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_EXTENSION_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/profiles/profile_keyed_service.h" | 13 #include "chrome/browser/profiles/profile_keyed_service.h" |
14 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
15 | 15 |
16 class ExtensionDevToolsManager; | 16 class ExtensionDevToolsManager; |
17 class ExtensionEventRouter; | 17 class ExtensionEventRouter; |
18 class ExtensionInfoMap; | 18 class ExtensionInfoMap; |
19 class ExtensionMessageService; | 19 class ExtensionMessageService; |
20 class ExtensionNavigationObserver; | 20 class ExtensionNavigationObserver; |
21 class ExtensionProcessManager; | 21 class ExtensionProcessManager; |
22 class ExtensionService; | 22 class ExtensionService; |
23 class Profile; | 23 class Profile; |
24 class UserScriptMaster; | 24 class UserScriptMaster; |
25 | 25 |
26 namespace extensions { | 26 namespace extensions { |
27 class AlarmManager; | 27 class AlarmManager; |
28 class Extension; | 28 class Extension; |
29 class ExtensionPrefs; | 29 class ExtensionPrefs; |
| 30 class ExtensionSystemSharedFactory; |
30 class LazyBackgroundTaskQueue; | 31 class LazyBackgroundTaskQueue; |
31 class ManagementPolicy; | 32 class ManagementPolicy; |
32 class RulesRegistryService; | 33 class RulesRegistryService; |
33 class StateStore; | 34 class StateStore; |
34 } | |
35 | 35 |
36 // The ExtensionSystem manages the creation and destruction of services | 36 // The ExtensionSystem manages the creation and destruction of services |
37 // related to extensions. Most objects are shared between normal | 37 // related to extensions. Most objects are shared between normal |
38 // and incognito Profiles, except as called out in comments. | 38 // and incognito Profiles, except as called out in comments. |
39 // This interface supports using TestExtensionSystem for TestingProfiles | 39 // This interface supports using TestExtensionSystem for TestingProfiles |
40 // that don't want all of the extensions baggage in their tests. | 40 // that don't want all of the extensions baggage in their tests. |
41 class ExtensionSystem : public ProfileKeyedService { | 41 class ExtensionSystem : public ProfileKeyedService { |
42 public: | 42 public: |
43 ExtensionSystem(); | 43 ExtensionSystem(); |
44 virtual ~ExtensionSystem(); | 44 virtual ~ExtensionSystem(); |
45 | 45 |
46 // Returns the instance for the given profile, or NULL if none. This is | 46 // Returns the instance for the given profile, or NULL if none. This is |
47 // a convenience wrapper around ExtensionSystemFactory::GetForProfile. | 47 // a convenience wrapper around ExtensionSystemFactory::GetForProfile. |
48 static ExtensionSystem* Get(Profile* profile); | 48 static ExtensionSystem* Get(Profile* profile); |
49 | 49 |
50 // ProfileKeyedService implementation. | 50 // ProfileKeyedService implementation. |
51 virtual void Shutdown() OVERRIDE {} | 51 virtual void Shutdown() OVERRIDE {} |
52 | 52 |
53 // Initializes extensions machinery. | 53 // Initializes extensions machinery. |
54 // Component extensions are always enabled, external and user extensions | 54 // Component extensions are always enabled, external and user extensions |
55 // are controlled by |extensions_enabled|. | 55 // are controlled by |extensions_enabled|. |
56 virtual void Init(bool extensions_enabled) = 0; | 56 virtual void Init(bool extensions_enabled) = 0; |
57 | 57 |
58 // The ExtensionService is created at startup. | 58 // The ExtensionService is created at startup. |
59 virtual ExtensionService* extension_service() = 0; | 59 virtual ExtensionService* extension_service() = 0; |
60 | 60 |
61 // The class controlling whether users are permitted to perform certain | 61 // The class controlling whether users are permitted to perform certain |
62 // actions on extensions (install, uninstall, disable, etc.). | 62 // actions on extensions (install, uninstall, disable, etc.). |
63 // The ManagementPolicy is created at startup. | 63 // The ManagementPolicy is created at startup. |
64 virtual extensions::ManagementPolicy* management_policy() = 0; | 64 virtual ManagementPolicy* management_policy() = 0; |
65 | 65 |
66 // The ExtensionDevToolsManager is created at startup. | 66 // The ExtensionDevToolsManager is created at startup. |
67 virtual ExtensionDevToolsManager* devtools_manager() = 0; | 67 virtual ExtensionDevToolsManager* devtools_manager() = 0; |
68 | 68 |
69 // The UserScriptMaster is created at startup. | 69 // The UserScriptMaster is created at startup. |
70 virtual UserScriptMaster* user_script_master() = 0; | 70 virtual UserScriptMaster* user_script_master() = 0; |
71 | 71 |
72 // The ExtensionProcessManager is created at startup. | 72 // The ExtensionProcessManager is created at startup. |
73 virtual ExtensionProcessManager* process_manager() = 0; | 73 virtual ExtensionProcessManager* process_manager() = 0; |
74 | 74 |
75 // The AlarmManager is created at startup. | 75 // The AlarmManager is created at startup. |
76 virtual extensions::AlarmManager* alarm_manager() = 0; | 76 virtual AlarmManager* alarm_manager() = 0; |
77 | 77 |
78 // The StateStore is created at startup. | 78 // The StateStore is created at startup. |
79 virtual extensions::StateStore* state_store() = 0; | 79 virtual StateStore* state_store() = 0; |
80 | 80 |
81 // Returns the IO-thread-accessible extension data. | 81 // Returns the IO-thread-accessible extension data. |
82 virtual ExtensionInfoMap* info_map() = 0; | 82 virtual ExtensionInfoMap* info_map() = 0; |
83 | 83 |
84 // The LazyBackgroundTaskQueue is created at startup. | 84 // The LazyBackgroundTaskQueue is created at startup. |
85 virtual extensions::LazyBackgroundTaskQueue* lazy_background_task_queue() = 0; | 85 virtual LazyBackgroundTaskQueue* lazy_background_task_queue() = 0; |
86 | 86 |
87 // The ExtensionMessageService is created at startup. | 87 // The ExtensionMessageService is created at startup. |
88 virtual ExtensionMessageService* message_service() = 0; | 88 virtual ExtensionMessageService* message_service() = 0; |
89 | 89 |
90 // The ExtensionEventRouter is created at startup. | 90 // The ExtensionEventRouter is created at startup. |
91 virtual ExtensionEventRouter* event_router() = 0; | 91 virtual ExtensionEventRouter* event_router() = 0; |
92 | 92 |
93 // The RulesRegistryService is created at startup. | 93 // The RulesRegistryService is created at startup. |
94 virtual extensions::RulesRegistryService* rules_registry_service() = 0; | 94 virtual RulesRegistryService* rules_registry_service() = 0; |
95 | 95 |
96 // Called by the ExtensionService that lives in this system. Gives the | 96 // Called by the ExtensionService that lives in this system. Gives the |
97 // info map a chance to react to the load event before the EXTENSION_LOADED | 97 // info map a chance to react to the load event before the EXTENSION_LOADED |
98 // notification has fired. The purpose for handling this event first is to | 98 // notification has fired. The purpose for handling this event first is to |
99 // avoid race conditions by making sure URLRequestContexts learn about new | 99 // avoid race conditions by making sure URLRequestContexts learn about new |
100 // extensions before anything else needs them to know. | 100 // extensions before anything else needs them to know. |
101 virtual void RegisterExtensionWithRequestContexts( | 101 virtual void RegisterExtensionWithRequestContexts( |
102 const extensions::Extension* extension) {} | 102 const Extension* extension) {} |
103 | 103 |
104 // Called by the ExtensionService that lives in this system. Lets the | 104 // Called by the ExtensionService that lives in this system. Lets the |
105 // info map clean up its RequestContexts once all the listeners to the | 105 // info map clean up its RequestContexts once all the listeners to the |
106 // EXTENSION_UNLOADED notification have finished running. | 106 // EXTENSION_UNLOADED notification have finished running. |
107 virtual void UnregisterExtensionWithRequestContexts( | 107 virtual void UnregisterExtensionWithRequestContexts( |
108 const std::string& extension_id, | 108 const std::string& extension_id, |
109 const extension_misc::UnloadedExtensionReason reason) {} | 109 const extension_misc::UnloadedExtensionReason reason) {} |
110 }; | 110 }; |
111 | 111 |
112 // The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl. | 112 // The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl. |
113 // Implementation details: non-shared services are owned by | 113 // Implementation details: non-shared services are owned by |
114 // ExtensionSystemImpl, a ProfileKeyedService with separate incognito | 114 // ExtensionSystemImpl, a ProfileKeyedService with separate incognito |
115 // instances. A private Shared class (also a ProfileKeyedService, | 115 // instances. A private Shared class (also a ProfileKeyedService, |
116 // but with a shared instance for incognito) keeps the common services. | 116 // but with a shared instance for incognito) keeps the common services. |
117 class ExtensionSystemImpl : public ExtensionSystem { | 117 class ExtensionSystemImpl : public ExtensionSystem { |
118 public: | 118 public: |
119 explicit ExtensionSystemImpl(Profile* profile); | 119 explicit ExtensionSystemImpl(Profile* profile); |
120 virtual ~ExtensionSystemImpl(); | 120 virtual ~ExtensionSystemImpl(); |
121 | 121 |
122 // ProfileKeyedService implementation. | 122 // ProfileKeyedService implementation. |
123 virtual void Shutdown() OVERRIDE; | 123 virtual void Shutdown() OVERRIDE; |
124 | 124 |
125 virtual void Init(bool extensions_enabled) OVERRIDE; | 125 virtual void Init(bool extensions_enabled) OVERRIDE; |
126 | 126 |
127 virtual ExtensionService* extension_service() OVERRIDE; // shared | 127 virtual ExtensionService* extension_service() OVERRIDE; // shared |
128 virtual extensions::ManagementPolicy* management_policy() OVERRIDE; // shared | 128 virtual ManagementPolicy* management_policy() OVERRIDE; // shared |
129 virtual UserScriptMaster* user_script_master() OVERRIDE; // shared | 129 virtual UserScriptMaster* user_script_master() OVERRIDE; // shared |
130 virtual ExtensionDevToolsManager* devtools_manager() OVERRIDE; | 130 virtual ExtensionDevToolsManager* devtools_manager() OVERRIDE; |
131 virtual ExtensionProcessManager* process_manager() OVERRIDE; | 131 virtual ExtensionProcessManager* process_manager() OVERRIDE; |
132 virtual extensions::AlarmManager* alarm_manager() OVERRIDE; | 132 virtual AlarmManager* alarm_manager() OVERRIDE; |
133 virtual extensions::StateStore* state_store() OVERRIDE; | 133 virtual StateStore* state_store() OVERRIDE; |
134 virtual extensions::LazyBackgroundTaskQueue* lazy_background_task_queue() | 134 virtual LazyBackgroundTaskQueue* lazy_background_task_queue() |
135 OVERRIDE; // shared | 135 OVERRIDE; // shared |
136 virtual ExtensionInfoMap* info_map() OVERRIDE; // shared | 136 virtual ExtensionInfoMap* info_map() OVERRIDE; // shared |
137 virtual ExtensionMessageService* message_service() OVERRIDE; // shared | 137 virtual ExtensionMessageService* message_service() OVERRIDE; // shared |
138 virtual ExtensionEventRouter* event_router() OVERRIDE; // shared | 138 virtual ExtensionEventRouter* event_router() OVERRIDE; // shared |
139 // The RulesRegistryService is created at startup. | 139 // The RulesRegistryService is created at startup. |
140 virtual extensions::RulesRegistryService* rules_registry_service() | 140 virtual RulesRegistryService* rules_registry_service() |
141 OVERRIDE; // shared | 141 OVERRIDE; // shared |
142 | 142 |
143 virtual void RegisterExtensionWithRequestContexts( | 143 virtual void RegisterExtensionWithRequestContexts( |
144 const extensions::Extension* extension) OVERRIDE; | 144 const Extension* extension) OVERRIDE; |
145 | 145 |
146 virtual void UnregisterExtensionWithRequestContexts( | 146 virtual void UnregisterExtensionWithRequestContexts( |
147 const std::string& extension_id, | 147 const std::string& extension_id, |
148 const extension_misc::UnloadedExtensionReason reason) OVERRIDE; | 148 const extension_misc::UnloadedExtensionReason reason) OVERRIDE; |
149 | 149 |
150 private: | 150 private: |
151 friend class ExtensionSystemSharedFactory; | 151 friend class ExtensionSystemSharedFactory; |
152 | 152 |
153 // Owns the Extension-related systems that have a single instance | 153 // Owns the Extension-related systems that have a single instance |
154 // shared between normal and incognito profiles. | 154 // shared between normal and incognito profiles. |
155 class Shared : public ProfileKeyedService { | 155 class Shared : public ProfileKeyedService { |
156 public: | 156 public: |
157 explicit Shared(Profile* profile); | 157 explicit Shared(Profile* profile); |
158 virtual ~Shared(); | 158 virtual ~Shared(); |
159 | 159 |
160 // Initialization takes place in phases. | 160 // Initialization takes place in phases. |
161 virtual void InitPrefs(); | 161 virtual void InitPrefs(); |
162 // This must not be called until all the providers have been created. | 162 // This must not be called until all the providers have been created. |
163 void RegisterManagementPolicyProviders(); | 163 void RegisterManagementPolicyProviders(); |
164 void InitInfoMap(); | 164 void InitInfoMap(); |
165 void Init(bool extensions_enabled); | 165 void Init(bool extensions_enabled); |
166 | 166 |
167 extensions::StateStore* state_store(); | 167 StateStore* state_store(); |
168 ExtensionService* extension_service(); | 168 ExtensionService* extension_service(); |
169 extensions::ManagementPolicy* management_policy(); | 169 ManagementPolicy* management_policy(); |
170 UserScriptMaster* user_script_master(); | 170 UserScriptMaster* user_script_master(); |
171 ExtensionInfoMap* info_map(); | 171 ExtensionInfoMap* info_map(); |
172 extensions::LazyBackgroundTaskQueue* lazy_background_task_queue(); | 172 LazyBackgroundTaskQueue* lazy_background_task_queue(); |
173 ExtensionMessageService* message_service(); | 173 ExtensionMessageService* message_service(); |
174 ExtensionEventRouter* event_router(); | 174 ExtensionEventRouter* event_router(); |
175 extensions::RulesRegistryService* rules_registry_service(); | 175 RulesRegistryService* rules_registry_service(); |
176 | 176 |
177 private: | 177 private: |
178 Profile* profile_; | 178 Profile* profile_; |
179 | 179 |
180 // The services that are shared between normal and incognito profiles. | 180 // The services that are shared between normal and incognito profiles. |
181 | 181 |
182 scoped_ptr<extensions::StateStore> state_store_; | 182 scoped_ptr<StateStore> state_store_; |
183 scoped_ptr<extensions::ExtensionPrefs> extension_prefs_; | 183 scoped_ptr<ExtensionPrefs> extension_prefs_; |
184 // ExtensionService depends on the 2 above. | 184 // ExtensionService depends on the 2 above. |
185 scoped_ptr<ExtensionService> extension_service_; | 185 scoped_ptr<ExtensionService> extension_service_; |
186 scoped_ptr<extensions::ManagementPolicy> management_policy_; | 186 scoped_ptr<ManagementPolicy> management_policy_; |
187 scoped_refptr<UserScriptMaster> user_script_master_; | 187 scoped_refptr<UserScriptMaster> user_script_master_; |
188 // extension_info_map_ needs to outlive extension_process_manager_. | 188 // extension_info_map_ needs to outlive extension_process_manager_. |
189 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 189 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
190 // This is a dependency of ExtensionMessageService and ExtensionEventRouter. | 190 // This is a dependency of ExtensionMessageService and ExtensionEventRouter. |
191 scoped_ptr<extensions::LazyBackgroundTaskQueue> lazy_background_task_queue_; | 191 scoped_ptr<LazyBackgroundTaskQueue> lazy_background_task_queue_; |
192 scoped_ptr<ExtensionMessageService> extension_message_service_; | 192 scoped_ptr<ExtensionMessageService> extension_message_service_; |
193 scoped_ptr<ExtensionEventRouter> extension_event_router_; | 193 scoped_ptr<ExtensionEventRouter> extension_event_router_; |
194 scoped_ptr<ExtensionNavigationObserver> extension_navigation_observer_; | 194 scoped_ptr<ExtensionNavigationObserver> extension_navigation_observer_; |
195 scoped_ptr<extensions::RulesRegistryService> rules_registry_service_; | 195 scoped_ptr<RulesRegistryService> rules_registry_service_; |
196 }; | 196 }; |
197 | 197 |
198 Profile* profile_; | 198 Profile* profile_; |
199 | 199 |
200 Shared* shared_; | 200 Shared* shared_; |
201 | 201 |
202 // The services that have their own instances in incognito. | 202 // The services that have their own instances in incognito. |
203 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; | 203 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; |
204 // |extension_process_manager_| must be destroyed before the Profile's | 204 // |extension_process_manager_| must be destroyed before the Profile's |
205 // |io_data_|. While |extension_process_manager_| still lives, we handle | 205 // |io_data_|. While |extension_process_manager_| still lives, we handle |
206 // incoming resource requests from extension processes and those require | 206 // incoming resource requests from extension processes and those require |
207 // access to the ResourceContext owned by |io_data_|. | 207 // access to the ResourceContext owned by |io_data_|. |
208 scoped_ptr<ExtensionProcessManager> extension_process_manager_; | 208 scoped_ptr<ExtensionProcessManager> extension_process_manager_; |
209 scoped_ptr<extensions::AlarmManager> alarm_manager_; | 209 scoped_ptr<AlarmManager> alarm_manager_; |
210 | 210 |
211 DISALLOW_COPY_AND_ASSIGN(ExtensionSystemImpl); | 211 DISALLOW_COPY_AND_ASSIGN(ExtensionSystemImpl); |
212 }; | 212 }; |
213 | 213 |
| 214 } // namespace extensions |
| 215 |
214 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ | 216 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ |
OLD | NEW |