1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/scoped_observer.h" 12 #include "components/keyed_service/core/keyed_service.h" 13 #include "extensions/browser/extension_registry_observer.h" 14 15 class ExtensionAction; 16 class Profile; 17 18 namespace extensions { 19 20 class Extension; 21 class ExtensionRegistry; 22 23 // Owns the ExtensionActions associated with each extension. These actions live 24 // while an extension is loaded and are destroyed on unload. 25 class ExtensionActionManager : public KeyedService, 26 public ExtensionRegistryObserver { 27 public: 28 explicit ExtensionActionManager(Profile* profile); 29 virtual ~ExtensionActionManager(); 30 31 // Returns this profile's ExtensionActionManager. One instance is 32 // shared between a profile and its incognito version. 33 static ExtensionActionManager* Get(Profile* profile); 34 35 // Retrieves the page action, or browser action for |extension|. 36 // If the result is not NULL, it remains valid until the extension is 37 // unloaded. 38 ExtensionAction* GetPageAction(const extensions::Extension& extension) const; 39 ExtensionAction* GetBrowserAction( 40 const extensions::Extension& extension) const; 41 ExtensionAction* GetSystemIndicator( 42 const extensions::Extension& extension) const; 43 44 private: 45 // Implement ExtensionRegistryObserver. 46 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, 47 const Extension* extension, 48 UnloadedExtensionInfo::Reason reason) 49 OVERRIDE; 50 51 Profile* profile_; 52 53 // Listen to extension unloaded notifications. 54 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 55 extension_registry_observer_; 56 57 // Keyed by Extension ID. These maps are populated lazily when their 58 // ExtensionAction is first requested, and the entries are removed when the 59 // extension is unloaded. Not every extension has a page action or browser 60 // action. 61 typedef std::map<std::string, linked_ptr<ExtensionAction> > ExtIdToActionMap; 62 mutable ExtIdToActionMap page_actions_; 63 mutable ExtIdToActionMap browser_actions_; 64 mutable ExtIdToActionMap system_indicators_; 65 }; 66 67 } // namespace extensions 68 69 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ 70