OLD | NEW |
---|---|
(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 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "chrome/browser/profiles/profile_keyed_service.h" | |
14 #include "chrome/common/extensions/extension_constants.h" | |
15 | |
16 class Extension; | |
17 class ExtensionDevToolsManager; | |
18 class ExtensionEventRouter; | |
19 class ExtensionInfoMap; | |
20 class ExtensionMessageService; | |
21 class ExtensionNavigationObserver; | |
22 class ExtensionPrefs; | |
23 class ExtensionPrefValueMap; | |
24 class ExtensionProcessManager; | |
25 class ExtensionService; | |
26 class Profile; | |
27 class UserScriptMaster; | |
28 | |
29 // The ExtensionSystem manages the creation and destruction of services | |
30 // related to extensions. Most objects are shared between normal | |
31 // and incognito Profiles, except for the process manager. | |
Aaron Boodman
2012/02/28 00:21:21
Nit: just say "except for where called out in comm
Yoyo Zhou
2012/02/28 22:58:26
Done.
| |
32 // This interface is analogous to ExtensionServiceInterface; it supports | |
Aaron Boodman
2012/02/28 00:21:21
Again, no need to mention specific class names whi
Yoyo Zhou
2012/02/28 22:58:26
Done.
| |
33 // using TestExtensionSystem for TestingProfiles that don't want all of the | |
34 // extensions baggage in their tests. | |
35 class ExtensionSystem : public ProfileKeyedService { | |
36 public: | |
37 ExtensionSystem(); | |
38 virtual ~ExtensionSystem(); | |
39 | |
40 // ProfileKeyedService implementation. | |
41 virtual void Shutdown() OVERRIDE {} | |
42 | |
43 // Initializes extensions machinery. | |
44 // Component extensions are always enabled, external and user extensions | |
45 // are controlled by |extensions_enabled|. | |
46 virtual void Init(bool extensions_enabled) = 0; | |
47 | |
48 // The ExtensionService is created at startup. | |
49 virtual ExtensionService* extension_service() = 0; | |
50 | |
51 // The ExtensionDevToolsManager is created at startup. | |
52 virtual ExtensionDevToolsManager* devtools_manager() = 0; | |
53 | |
54 // The UserScriptMaster is created at startup. | |
55 virtual UserScriptMaster* user_script_master() = 0; | |
56 | |
57 // The ExtensionProcessManager is created at startup. | |
58 virtual ExtensionProcessManager* process_manager() = 0; | |
59 | |
60 // Returns the IO-thread-accessible extension data. | |
61 virtual ExtensionInfoMap* info_map() = 0; | |
62 | |
63 // The ExtensionMessageService is created at startup. | |
64 virtual ExtensionMessageService* message_service() = 0; | |
65 | |
66 // The ExtensionEventRouter is created at startup. | |
67 virtual ExtensionEventRouter* event_router() = 0; | |
68 | |
69 // Called by the ExtensionService that lives in this system. Gives the | |
70 // info map a chance to react to the load event before the EXTENSION_LOADED | |
71 // notification has fired. The purpose for handling this event first is to | |
72 // avoid race conditions by making sure URLRequestContexts learn about new | |
73 // extensions before anything else needs them to know. | |
74 virtual void RegisterExtensionWithRequestContexts( | |
75 const Extension* extension) {} | |
76 | |
77 // Called by the ExtensionService that lives in this system. Lets the | |
78 // info map clean up its RequestContexts once all the listeners to the | |
79 // EXTENSION_UNLOADED notification have finished running. | |
80 virtual void UnregisterExtensionWithRequestContexts( | |
81 const std::string& extension_id, | |
82 const extension_misc::UnloadedExtensionReason reason) {} | |
83 }; | |
84 | |
85 // The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl. | |
86 // Implementation details: non-shared services are owned by | |
87 // ExtensionSystemImpl, a ProfileKeyedService with separate incognito | |
88 // instances. A private Delegate class (also a ProfileKeyedService, | |
89 // but with a shared instance for incognito) keeps the common services. | |
90 class ExtensionSystemImpl : public ExtensionSystem { | |
91 public: | |
92 explicit ExtensionSystemImpl(Profile* profile); | |
93 virtual ~ExtensionSystemImpl(); | |
94 | |
95 // ProfileKeyedService implementation. | |
96 virtual void Shutdown() OVERRIDE; | |
97 | |
98 virtual void Init(bool extensions_enabled) OVERRIDE; | |
99 | |
100 virtual ExtensionService* extension_service() OVERRIDE; // delegated | |
101 virtual UserScriptMaster* user_script_master() OVERRIDE; // delegated | |
102 virtual ExtensionDevToolsManager* devtools_manager() OVERRIDE; | |
103 virtual ExtensionProcessManager* process_manager() OVERRIDE; | |
104 virtual ExtensionInfoMap* info_map() OVERRIDE; // delegated | |
105 virtual ExtensionMessageService* message_service() OVERRIDE; // delegated | |
106 virtual ExtensionEventRouter* event_router() OVERRIDE; // delegated | |
107 | |
108 virtual void RegisterExtensionWithRequestContexts( | |
109 const Extension* extension) OVERRIDE; | |
110 | |
111 virtual void UnregisterExtensionWithRequestContexts( | |
112 const std::string& extension_id, | |
113 const extension_misc::UnloadedExtensionReason reason) OVERRIDE; | |
114 | |
115 private: | |
116 friend class ExtensionSystemDelegateFactory; | |
117 | |
118 // Owns the Extension-related systems that have a single instance | |
119 // shared between normal and incognito profiles. | |
120 class Delegate : public ProfileKeyedService { | |
Aaron Boodman
2012/02/28 00:21:21
Delegate is a kinda funky name for this class, sin
Yoyo Zhou
2012/02/28 22:58:26
Done.
| |
121 public: | |
122 explicit Delegate(Profile* profile); | |
123 virtual ~Delegate(); | |
124 | |
125 // ProfileKeyedService implementation. | |
126 virtual void Shutdown() OVERRIDE; | |
127 | |
128 // Initialization takes place in phases. | |
129 virtual void InitPrefs(); | |
130 void InitInfoMap(); | |
131 void Init(bool extensions_enabled); | |
132 | |
133 ExtensionService* extension_service(); | |
134 UserScriptMaster* user_script_master(); | |
135 ExtensionInfoMap* info_map(); | |
136 ExtensionMessageService* message_service(); | |
137 ExtensionEventRouter* event_router(); | |
138 | |
139 private: | |
140 Profile* profile_; | |
141 | |
142 // The services that are shared between normal and incognito profiles. | |
143 | |
144 // Keep extension_prefs_ on top of extension_service_ because the latter | |
145 // maintains a pointer to the first and shall be destructed first. | |
146 scoped_ptr<ExtensionPrefs> extension_prefs_; | |
147 scoped_ptr<ExtensionService> extension_service_; | |
148 scoped_refptr<UserScriptMaster> user_script_master_; | |
149 // extension_info_map_ needs to outlive extension_process_manager_. | |
150 scoped_refptr<ExtensionInfoMap> extension_info_map_; | |
151 scoped_refptr<ExtensionMessageService> extension_message_service_; | |
152 scoped_ptr<ExtensionEventRouter> extension_event_router_; | |
153 scoped_ptr<ExtensionNavigationObserver> extension_navigation_observer_; | |
154 }; | |
155 | |
156 Profile* profile_; | |
157 | |
158 Delegate* delegate_; | |
159 | |
160 // The services that have their own instances in incognito. | |
161 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; | |
162 // |extension_process_manager_| must be destroyed before the Profile's | |
163 // |io_data_|. While |extension_process_manager_| still lives, we handle | |
164 // incoming resource requests from extension processes and those require | |
165 // access to the ResourceContext owned by |io_data_|. | |
166 scoped_ptr<ExtensionProcessManager> extension_process_manager_; | |
167 }; | |
168 | |
169 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_H_ | |
OLD | NEW |