Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_action_manager.h
blob415d8633b8053134344c8e34b3c647f95a8fa58e
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, browser action, or script badge 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* GetScriptBadge(const extensions::Extension& extension) const;
42 ExtensionAction* GetSystemIndicator(
43 const extensions::Extension& extension) const;
45 private:
46 // Implement content::NotificationObserver.
47 virtual void Observe(int type,
48 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE;
51 content::NotificationRegistrar registrar_;
52 Profile* profile_;
54 // Keyed by Extension ID. These maps are populated lazily when their
55 // ExtensionAction is first requested, and the entries are removed when the
56 // extension is unloaded. Not every extension has a page action or browser
57 // action, but all have a script badge.
58 typedef std::map<std::string, linked_ptr<ExtensionAction> > ExtIdToActionMap;
59 mutable ExtIdToActionMap page_actions_;
60 mutable ExtIdToActionMap browser_actions_;
61 mutable ExtIdToActionMap script_badges_;
62 mutable ExtIdToActionMap system_indicators_;
65 } // namespace extensions
67 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_