NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / extension_action_manager.h
blob2316205e9fe26722568151c9828aea800d6c4775
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/linked_ptr.h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
16 class ExtensionAction;
17 class Profile;
19 namespace extensions {
21 class Extension;
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 BrowserContextKeyedService,
26 public content::NotificationObserver {
27 public:
28 explicit ExtensionActionManager(Profile* profile);
29 virtual ~ExtensionActionManager();
31 // Returns this profile's ExtensionActionManager. One instance is
32 // shared between a profile and its incognito version.
33 static ExtensionActionManager* Get(Profile* profile);
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;
44 private:
45 // Implement content::NotificationObserver.
46 virtual void Observe(int type,
47 const content::NotificationSource& source,
48 const content::NotificationDetails& details) OVERRIDE;
50 content::NotificationRegistrar registrar_;
51 Profile* profile_;
53 // Keyed by Extension ID. These maps are populated lazily when their
54 // ExtensionAction is first requested, and the entries are removed when the
55 // extension is unloaded. Not every extension has a page action or browser
56 // action.
57 typedef std::map<std::string, linked_ptr<ExtensionAction> > ExtIdToActionMap;
58 mutable ExtIdToActionMap page_actions_;
59 mutable ExtIdToActionMap browser_actions_;
60 mutable ExtIdToActionMap system_indicators_;
63 } // namespace extensions
65 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_