OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_
H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_
H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_
H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAGER_
H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/scoped_observer.h" |
12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
13 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 14 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
15 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
17 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/extension_registry_observer.h" |
18 | 19 |
19 class ExtensionAction; | 20 class ExtensionAction; |
20 class Profile; | 21 class Profile; |
21 class StatusTray; | 22 class StatusTray; |
22 | 23 |
23 FORWARD_DECLARE_TEST(SystemIndicatorApiTest, SystemIndicator); | 24 FORWARD_DECLARE_TEST(SystemIndicatorApiTest, SystemIndicator); |
24 | 25 |
25 namespace extensions { | 26 namespace extensions { |
26 | |
27 class ExtensionIndicatorIcon; | 27 class ExtensionIndicatorIcon; |
| 28 class ExtensionRegistry; |
28 | 29 |
29 // Keeps track of all the systemIndicator icons created for a given Profile | 30 // Keeps track of all the systemIndicator icons created for a given Profile |
30 // that are currently visible in the UI. Use SystemIndicatorManagerFactory to | 31 // that are currently visible in the UI. Use SystemIndicatorManagerFactory to |
31 // create a SystemIndicatorManager object. | 32 // create a SystemIndicatorManager object. |
32 class SystemIndicatorManager : public content::NotificationObserver, | 33 class SystemIndicatorManager : public content::NotificationObserver, |
| 34 public ExtensionRegistryObserver, |
33 public KeyedService { | 35 public KeyedService { |
34 public: | 36 public: |
35 SystemIndicatorManager(Profile* profile, StatusTray* status_tray); | 37 SystemIndicatorManager(Profile* profile, StatusTray* status_tray); |
36 virtual ~SystemIndicatorManager(); | 38 virtual ~SystemIndicatorManager(); |
37 | 39 |
38 // KeyedService implementation. | 40 // KeyedService implementation. |
39 virtual void Shutdown() OVERRIDE; | 41 virtual void Shutdown() OVERRIDE; |
40 | 42 |
| 43 private: |
| 44 FRIEND_TEST_ALL_PREFIXES(::SystemIndicatorApiTest, SystemIndicator); |
| 45 |
41 // content::NotificationDelegate implementation. | 46 // content::NotificationDelegate implementation. |
42 virtual void Observe(int type, | 47 virtual void Observe(int type, |
43 const content::NotificationSource& source, | 48 const content::NotificationSource& source, |
44 const content::NotificationDetails& details) OVERRIDE; | 49 const content::NotificationDetails& details) OVERRIDE; |
45 | 50 |
46 private: | 51 // ExtensionRegistryObserver implementation. |
47 FRIEND_TEST_ALL_PREFIXES(::SystemIndicatorApiTest, SystemIndicator); | 52 virtual void OnExtensionUnloaded( |
| 53 content::BrowserContext* browser_context, |
| 54 const Extension* extension, |
| 55 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
48 | 56 |
49 // Determines whether the indicator should be hidden or shown and calls the | 57 // Determines whether the indicator should be hidden or shown and calls the |
50 // appropriate function. | 58 // appropriate function. |
51 void OnSystemIndicatorChanged(const ExtensionAction* extension_action); | 59 void OnSystemIndicatorChanged(const ExtensionAction* extension_action); |
52 | 60 |
53 // Causes a call to OnStatusIconClicked for the specified extension_id. | 61 // Causes a call to OnStatusIconClicked for the specified extension_id. |
54 // Returns false if no ExtensionIndicatorIcon is found for the extension. | 62 // Returns false if no ExtensionIndicatorIcon is found for the extension. |
55 bool SendClickEventToExtensionForTest(const std::string extension_id); | 63 bool SendClickEventToExtensionForTest(const std::string extension_id); |
56 | 64 |
57 // Causes an indicator to be shown for the given extension_action. Creates | 65 // Causes an indicator to be shown for the given extension_action. Creates |
58 // the indicator if necessary. | 66 // the indicator if necessary. |
59 void CreateOrUpdateIndicator( | 67 void CreateOrUpdateIndicator( |
60 const Extension* extension, | 68 const Extension* extension, |
61 const ExtensionAction* extension_action); | 69 const ExtensionAction* extension_action); |
62 | 70 |
63 // Causes the indicator for the given extension to be hidden. | 71 // Causes the indicator for the given extension to be hidden. |
64 void RemoveIndicator(const std::string &extension_id); | 72 void RemoveIndicator(const std::string &extension_id); |
65 | 73 |
66 typedef std::map<const std::string, linked_ptr<ExtensionIndicatorIcon> > | 74 typedef std::map<const std::string, linked_ptr<ExtensionIndicatorIcon> > |
67 SystemIndicatorMap; | 75 SystemIndicatorMap; |
68 | 76 |
69 Profile* profile_; | 77 Profile* profile_; |
70 StatusTray* status_tray_; | 78 StatusTray* status_tray_; |
71 SystemIndicatorMap system_indicators_; | 79 SystemIndicatorMap system_indicators_; |
72 content::NotificationRegistrar registrar_; | 80 content::NotificationRegistrar registrar_; |
73 base::ThreadChecker thread_checker_; | 81 base::ThreadChecker thread_checker_; |
74 | 82 |
| 83 // Listen to extension unloaded notifications. |
| 84 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 85 extension_registry_observer_; |
| 86 |
75 DISALLOW_COPY_AND_ASSIGN(SystemIndicatorManager); | 87 DISALLOW_COPY_AND_ASSIGN(SystemIndicatorManager); |
76 }; | 88 }; |
77 | 89 |
78 } // namespace extensions | 90 } // namespace extensions |
79 | 91 |
80 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAG
ER_H_ | 92 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INDICATOR_SYSTEM_INDICATOR_MANAG
ER_H_ |
OLD | NEW |