Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(781)

Side by Side Diff: chrome/browser/extensions/extension_system.h

Issue 147923005: Split ExtensionSystem interface from ExtensionSystemImpl implementation, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re^3base Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_SYSTEM_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
13 #include "extensions/common/extension.h"
14 #include "extensions/common/one_shot_event.h"
15
16 class ExtensionService;
17 class Profile;
18
19 #if defined(OS_CHROMEOS)
20 namespace chromeos {
21 class DeviceLocalAccountManagementPolicyProvider;
22 }
23 #endif // defined(OS_CHROMEOS)
24
25 namespace content {
26 class BrowserContext;
27 }
28
29 namespace extensions {
30 class Blacklist;
31 class ErrorConsole;
32 class EventRouter;
33 class Extension;
34 class ExtensionSystemSharedFactory;
35 class ExtensionWarningBadgeService;
36 class ExtensionWarningService;
37 class InfoMap;
38 class InstallVerifier;
39 class LazyBackgroundTaskQueue;
40 class ManagementPolicy;
41 class NavigationObserver;
42 class ProcessManager;
43 class RuntimeData;
44 class StandardManagementPolicyProvider;
45 class StateStore;
46 class UserScriptMaster;
47
48 // The ExtensionSystem manages the creation and destruction of services
49 // related to extensions. Most objects are shared between normal
50 // and incognito Profiles, except as called out in comments.
51 // This interface supports using TestExtensionSystem for TestingProfiles
52 // that don't want all of the extensions baggage in their tests.
53 class ExtensionSystem : public BrowserContextKeyedService {
54 public:
55 ExtensionSystem();
56 virtual ~ExtensionSystem();
57
58 // Returns the instance for the given profile, or NULL if none. This is
59 // a convenience wrapper around ExtensionSystemFactory::GetForProfile.
60 static ExtensionSystem* Get(Profile* profile);
61
62 // Returns the same instance as Get() above.
63 static ExtensionSystem* GetForBrowserContext(
64 content::BrowserContext* profile);
65
66 // BrowserContextKeyedService implementation.
67 virtual void Shutdown() OVERRIDE {}
68
69 // Initializes extensions machinery.
70 // Component extensions are always enabled, external and user extensions are
71 // controlled by |extensions_enabled|.
72 virtual void InitForRegularProfile(bool extensions_enabled) = 0;
73
74 // The ExtensionService is created at startup.
75 virtual ExtensionService* extension_service() = 0;
76
77 // Per-extension data that can change during the life of the process but
78 // does not persist across restarts. Lives on UI thread. Created at startup.
79 virtual RuntimeData* runtime_data() = 0;
80
81 // The class controlling whether users are permitted to perform certain
82 // actions on extensions (install, uninstall, disable, etc.).
83 // The ManagementPolicy is created at startup.
84 virtual ManagementPolicy* management_policy() = 0;
85
86 // The UserScriptMaster is created at startup.
87 virtual UserScriptMaster* user_script_master() = 0;
88
89 // The ProcessManager is created at startup.
90 virtual ProcessManager* process_manager() = 0;
91
92 // The StateStore is created at startup.
93 virtual StateStore* state_store() = 0;
94
95 // The rules store is created at startup.
96 virtual StateStore* rules_store() = 0;
97
98 // Returns the IO-thread-accessible extension data.
99 virtual InfoMap* info_map() = 0;
100
101 // The LazyBackgroundTaskQueue is created at startup.
102 virtual LazyBackgroundTaskQueue* lazy_background_task_queue() = 0;
103
104 // The EventRouter is created at startup.
105 virtual EventRouter* event_router() = 0;
106
107 // The ExtensionWarningService is created at startup.
108 virtual ExtensionWarningService* warning_service() = 0;
109
110 // The blacklist is created at startup.
111 virtual Blacklist* blacklist() = 0;
112
113 // The ErrorConsole is created at startup.
114 virtual ErrorConsole* error_console() = 0;
115
116 // The InstallVerifier is created at startup.
117 virtual InstallVerifier* install_verifier() = 0;
118
119 // Called by the ExtensionService that lives in this system. Gives the
120 // info map a chance to react to the load event before the EXTENSION_LOADED
121 // notification has fired. The purpose for handling this event first is to
122 // avoid race conditions by making sure URLRequestContexts learn about new
123 // extensions before anything else needs them to know.
124 virtual void RegisterExtensionWithRequestContexts(
125 const Extension* extension) {}
126
127 // Called by the ExtensionService that lives in this system. Lets the
128 // info map clean up its RequestContexts once all the listeners to the
129 // EXTENSION_UNLOADED notification have finished running.
130 virtual void UnregisterExtensionWithRequestContexts(
131 const std::string& extension_id,
132 const UnloadedExtensionInfo::Reason reason) {}
133
134 // Signaled when the extension system has completed its startup tasks.
135 virtual const OneShotEvent& ready() const = 0;
136 };
137
138 // The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl.
139 // Implementation details: non-shared services are owned by
140 // ExtensionSystemImpl, a BrowserContextKeyedService with separate incognito
141 // instances. A private Shared class (also a BrowserContextKeyedService,
142 // but with a shared instance for incognito) keeps the common services.
143 class ExtensionSystemImpl : public ExtensionSystem {
144 public:
145 explicit ExtensionSystemImpl(Profile* profile);
146 virtual ~ExtensionSystemImpl();
147
148 // BrowserContextKeyedService implementation.
149 virtual void Shutdown() OVERRIDE;
150
151 virtual void InitForRegularProfile(bool extensions_enabled) OVERRIDE;
152
153 virtual ExtensionService* extension_service() OVERRIDE; // shared
154 virtual RuntimeData* runtime_data() OVERRIDE; // shared
155 virtual ManagementPolicy* management_policy() OVERRIDE; // shared
156 virtual UserScriptMaster* user_script_master() OVERRIDE; // shared
157 virtual ProcessManager* process_manager() OVERRIDE;
158 virtual StateStore* state_store() OVERRIDE; // shared
159 virtual StateStore* rules_store() OVERRIDE; // shared
160 virtual LazyBackgroundTaskQueue* lazy_background_task_queue()
161 OVERRIDE; // shared
162 virtual InfoMap* info_map() OVERRIDE; // shared
163 virtual EventRouter* event_router() OVERRIDE; // shared
164 virtual ExtensionWarningService* warning_service() OVERRIDE;
165 virtual Blacklist* blacklist() OVERRIDE; // shared
166 virtual ErrorConsole* error_console() OVERRIDE;
167 virtual InstallVerifier* install_verifier() OVERRIDE;
168
169 virtual void RegisterExtensionWithRequestContexts(
170 const Extension* extension) OVERRIDE;
171
172 virtual void UnregisterExtensionWithRequestContexts(
173 const std::string& extension_id,
174 const UnloadedExtensionInfo::Reason reason) OVERRIDE;
175
176 virtual const OneShotEvent& ready() const OVERRIDE;
177
178 private:
179 friend class ExtensionSystemSharedFactory;
180
181 // Owns the Extension-related systems that have a single instance
182 // shared between normal and incognito profiles.
183 class Shared : public BrowserContextKeyedService {
184 public:
185 explicit Shared(Profile* profile);
186 virtual ~Shared();
187
188 // Initialization takes place in phases.
189 virtual void InitPrefs();
190 // This must not be called until all the providers have been created.
191 void RegisterManagementPolicyProviders();
192 void Init(bool extensions_enabled);
193
194 // BrowserContextKeyedService implementation.
195 virtual void Shutdown() OVERRIDE;
196
197 StateStore* state_store();
198 StateStore* rules_store();
199 ExtensionService* extension_service();
200 RuntimeData* runtime_data();
201 ManagementPolicy* management_policy();
202 UserScriptMaster* user_script_master();
203 Blacklist* blacklist();
204 InfoMap* info_map();
205 LazyBackgroundTaskQueue* lazy_background_task_queue();
206 EventRouter* event_router();
207 ExtensionWarningService* warning_service();
208 ErrorConsole* error_console();
209 InstallVerifier* install_verifier();
210 const OneShotEvent& ready() const { return ready_; }
211
212 private:
213 Profile* profile_;
214
215 // The services that are shared between normal and incognito profiles.
216
217 scoped_ptr<StateStore> state_store_;
218 scoped_ptr<StateStore> rules_store_;
219 // LazyBackgroundTaskQueue is a dependency of
220 // MessageService and EventRouter.
221 scoped_ptr<LazyBackgroundTaskQueue> lazy_background_task_queue_;
222 scoped_ptr<EventRouter> event_router_;
223 scoped_ptr<NavigationObserver> navigation_observer_;
224 scoped_refptr<UserScriptMaster> user_script_master_;
225 scoped_ptr<Blacklist> blacklist_;
226 // StandardManagementPolicyProvider depends on Blacklist.
227 scoped_ptr<StandardManagementPolicyProvider>
228 standard_management_policy_provider_;
229 scoped_ptr<RuntimeData> runtime_data_;
230 // ExtensionService depends on StateStore, Blacklist and RuntimeData.
231 scoped_ptr<ExtensionService> extension_service_;
232 scoped_ptr<ManagementPolicy> management_policy_;
233 // extension_info_map_ needs to outlive process_manager_.
234 scoped_refptr<InfoMap> extension_info_map_;
235 scoped_ptr<ExtensionWarningService> extension_warning_service_;
236 scoped_ptr<ExtensionWarningBadgeService> extension_warning_badge_service_;
237 scoped_ptr<ErrorConsole> error_console_;
238 scoped_ptr<InstallVerifier> install_verifier_;
239
240 #if defined(OS_CHROMEOS)
241 scoped_ptr<chromeos::DeviceLocalAccountManagementPolicyProvider>
242 device_local_account_management_policy_provider_;
243 #endif
244
245 OneShotEvent ready_;
246 };
247
248 Profile* profile_;
249
250 Shared* shared_;
251
252 // |process_manager_| must be destroyed before the Profile's |io_data_|. While
253 // |process_manager_| still lives, we handle incoming resource requests from
254 // extension processes and those require access to the ResourceContext owned
255 // by |io_data_|.
256 scoped_ptr<ProcessManager> process_manager_;
257
258 DISALLOW_COPY_AND_ASSIGN(ExtensionSystemImpl);
259 };
260
261 } // namespace extensions
262
263 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_sync_service_factory.cc ('k') | chrome/browser/extensions/extension_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698