OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 15 matching lines...) Expand all Loading... |
26 class DevToolsAgentHost; | 26 class DevToolsAgentHost; |
27 class RenderViewHost; | 27 class RenderViewHost; |
28 class RenderFrameHost; | 28 class RenderFrameHost; |
29 class SiteInstance; | 29 class SiteInstance; |
30 }; | 30 }; |
31 | 31 |
32 namespace extensions { | 32 namespace extensions { |
33 | 33 |
34 class Extension; | 34 class Extension; |
35 class ExtensionHost; | 35 class ExtensionHost; |
| 36 class ProcessManagerDelegate; |
36 class ProcessManagerObserver; | 37 class ProcessManagerObserver; |
37 | 38 |
38 // Manages dynamic state of running Chromium extensions. There is one instance | 39 // Manages dynamic state of running Chromium extensions. There is one instance |
39 // of this class per Profile. OTR Profiles have a separate instance that keeps | 40 // of this class per Profile. OTR Profiles have a separate instance that keeps |
40 // track of split-mode extensions only. | 41 // track of split-mode extensions only. |
41 class ProcessManager : public content::NotificationObserver { | 42 class ProcessManager : public content::NotificationObserver { |
42 public: | 43 public: |
43 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; | 44 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; |
44 typedef ExtensionHostSet::const_iterator const_iterator; | 45 typedef ExtensionHostSet::const_iterator const_iterator; |
45 | 46 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 116 |
116 // Tracks network requests for a given RenderFrameHost, used to know | 117 // Tracks network requests for a given RenderFrameHost, used to know |
117 // when network activity is idle for lazy background pages. | 118 // when network activity is idle for lazy background pages. |
118 void OnNetworkRequestStarted(content::RenderFrameHost* render_frame_host); | 119 void OnNetworkRequestStarted(content::RenderFrameHost* render_frame_host); |
119 void OnNetworkRequestDone(content::RenderFrameHost* render_frame_host); | 120 void OnNetworkRequestDone(content::RenderFrameHost* render_frame_host); |
120 | 121 |
121 // Prevents |extension|'s background page from being closed and sends the | 122 // Prevents |extension|'s background page from being closed and sends the |
122 // onSuspendCanceled() event to it. | 123 // onSuspendCanceled() event to it. |
123 void CancelSuspend(const Extension* extension); | 124 void CancelSuspend(const Extension* extension); |
124 | 125 |
125 // Ensures background hosts are loaded for a new browser window. | 126 // Creates background hosts if the embedder is ready and they are not already |
126 void OnBrowserWindowReady(); | 127 // loaded. |
| 128 void MaybeCreateStartupBackgroundHosts(); |
127 | 129 |
128 // Gets the BrowserContext associated with site_instance_ and all other | 130 // Gets the BrowserContext associated with site_instance_ and all other |
129 // related SiteInstances. | 131 // related SiteInstances. |
130 content::BrowserContext* GetBrowserContext() const; | 132 content::BrowserContext* GetBrowserContext() const; |
131 | 133 |
132 // Sets callbacks for testing keepalive impulse behavior. | 134 // Sets callbacks for testing keepalive impulse behavior. |
133 typedef base::Callback<void(const std::string& extension_id)> | 135 typedef base::Callback<void(const std::string& extension_id)> |
134 ImpulseCallbackForTesting; | 136 ImpulseCallbackForTesting; |
135 void SetKeepaliveImpulseCallbackForTesting( | 137 void SetKeepaliveImpulseCallbackForTesting( |
136 const ImpulseCallbackForTesting& callback); | 138 const ImpulseCallbackForTesting& callback); |
137 void SetKeepaliveImpulseDecrementCallbackForTesting( | 139 void SetKeepaliveImpulseDecrementCallbackForTesting( |
138 const ImpulseCallbackForTesting& callback); | 140 const ImpulseCallbackForTesting& callback); |
139 | 141 |
140 // Creates an incognito-context instance for tests. Tests for non-incognito | 142 // Creates an incognito-context instance for tests. Tests for non-incognito |
141 // contexts can just use Create() above. | 143 // contexts can just use Create() above. |
142 static ProcessManager* CreateIncognitoForTesting( | 144 static ProcessManager* CreateIncognitoForTesting( |
143 content::BrowserContext* incognito_context, | 145 content::BrowserContext* incognito_context, |
144 content::BrowserContext* original_context, | 146 content::BrowserContext* original_context, |
145 ProcessManager* original_manager); | 147 ProcessManager* original_manager); |
146 | 148 |
| 149 bool startup_background_hosts_created_for_test() const { |
| 150 return startup_background_hosts_created_; |
| 151 } |
| 152 |
147 protected: | 153 protected: |
148 // If |context| is incognito pass the master context as |original_context|. | 154 // If |context| is incognito pass the master context as |original_context|. |
149 // Otherwise pass the same context for both. | 155 // Otherwise pass the same context for both. |
150 ProcessManager(content::BrowserContext* context, | 156 ProcessManager(content::BrowserContext* context, |
151 content::BrowserContext* original_context); | 157 content::BrowserContext* original_context); |
152 | 158 |
153 // Called on browser shutdown to close our extension hosts. | 159 // Called on browser shutdown to close our extension hosts. |
154 void CloseBackgroundHosts(); | 160 void CloseBackgroundHosts(); |
155 | 161 |
156 // content::NotificationObserver: | 162 // content::NotificationObserver: |
157 virtual void Observe(int type, | 163 virtual void Observe(int type, |
158 const content::NotificationSource& source, | 164 const content::NotificationSource& source, |
159 const content::NotificationDetails& details) OVERRIDE; | 165 const content::NotificationDetails& details) OVERRIDE; |
160 | 166 |
161 // Load all background pages once the profile data is ready and the pages | |
162 // should be loaded. | |
163 void CreateBackgroundHostsForProfileStartup(); | |
164 | |
165 content::NotificationRegistrar registrar_; | 167 content::NotificationRegistrar registrar_; |
166 | 168 |
167 // The set of ExtensionHosts running viewless background extensions. | 169 // The set of ExtensionHosts running viewless background extensions. |
168 ExtensionHostSet background_hosts_; | 170 ExtensionHostSet background_hosts_; |
169 | 171 |
170 // A SiteInstance related to the SiteInstance for all extensions in | 172 // A SiteInstance related to the SiteInstance for all extensions in |
171 // this profile. We create it in such a way that a new | 173 // this profile. We create it in such a way that a new |
172 // browsing instance is created. This controls process grouping. | 174 // browsing instance is created. This controls process grouping. |
173 scoped_refptr<content::SiteInstance> site_instance_; | 175 scoped_refptr<content::SiteInstance> site_instance_; |
174 | 176 |
175 private: | 177 private: |
176 friend class ProcessManagerTest; | 178 friend class ProcessManagerTest; |
177 | 179 |
178 // Extra information we keep for each extension's background page. | 180 // Extra information we keep for each extension's background page. |
179 struct BackgroundPageData; | 181 struct BackgroundPageData; |
180 typedef std::string ExtensionId; | 182 typedef std::string ExtensionId; |
181 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; | 183 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; |
182 typedef std::map<content::RenderViewHost*, | 184 typedef std::map<content::RenderViewHost*, |
183 extensions::ViewType> ExtensionRenderViews; | 185 extensions::ViewType> ExtensionRenderViews; |
184 | 186 |
| 187 // Load all background pages once the profile data is ready and the pages |
| 188 // should be loaded. |
| 189 void CreateStartupBackgroundHosts(); |
| 190 |
185 // Called just after |host| is created so it can be registered in our lists. | 191 // Called just after |host| is created so it can be registered in our lists. |
186 void OnBackgroundHostCreated(ExtensionHost* host); | 192 void OnBackgroundHostCreated(ExtensionHost* host); |
187 | 193 |
188 // Close the given |host| iff it's a background page. | 194 // Close the given |host| iff it's a background page. |
189 void CloseBackgroundHost(ExtensionHost* host); | 195 void CloseBackgroundHost(ExtensionHost* host); |
190 | 196 |
191 // Internal implementation of DecrementLazyKeepaliveCount with an | 197 // Internal implementation of DecrementLazyKeepaliveCount with an |
192 // |extension_id| known to have a lazy background page. | 198 // |extension_id| known to have a lazy background page. |
193 void DecrementLazyKeepaliveCount(const std::string& extension_id); | 199 void DecrementLazyKeepaliveCount(const std::string& extension_id); |
194 | 200 |
(...skipping 14 matching lines...) Expand all Loading... |
209 // with an extension). | 215 // with an extension). |
210 bool RegisterRenderViewHost(content::RenderViewHost* render_view_host); | 216 bool RegisterRenderViewHost(content::RenderViewHost* render_view_host); |
211 | 217 |
212 // Unregister RenderViewHosts and clear background page data for an extension | 218 // Unregister RenderViewHosts and clear background page data for an extension |
213 // which has been unloaded. | 219 // which has been unloaded. |
214 void UnregisterExtension(const std::string& extension_id); | 220 void UnregisterExtension(const std::string& extension_id); |
215 | 221 |
216 // Clears background page data for this extension. | 222 // Clears background page data for this extension. |
217 void ClearBackgroundPageData(const std::string& extension_id); | 223 void ClearBackgroundPageData(const std::string& extension_id); |
218 | 224 |
219 // Returns true if loading background pages should be deferred. | |
220 bool DeferLoadingBackgroundHosts() const; | |
221 | |
222 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); | 225 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); |
223 | 226 |
224 // Contains all active extension-related RenderViewHost instances for all | 227 // Contains all active extension-related RenderViewHost instances for all |
225 // extensions. We also keep a cache of the host's view type, because that | 228 // extensions. We also keep a cache of the host's view type, because that |
226 // information is not accessible at registration/deregistration time. | 229 // information is not accessible at registration/deregistration time. |
227 ExtensionRenderViews all_extension_views_; | 230 ExtensionRenderViews all_extension_views_; |
228 | 231 |
229 BackgroundPageDataMap background_page_data_; | 232 BackgroundPageDataMap background_page_data_; |
230 | 233 |
231 // The time to delay between an extension becoming idle and | 234 // The time to delay between an extension becoming idle and |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 266 |
264 // Must be last member, see doc on WeakPtrFactory. | 267 // Must be last member, see doc on WeakPtrFactory. |
265 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; | 268 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; |
266 | 269 |
267 DISALLOW_COPY_AND_ASSIGN(ProcessManager); | 270 DISALLOW_COPY_AND_ASSIGN(ProcessManager); |
268 }; | 271 }; |
269 | 272 |
270 } // namespace extensions | 273 } // namespace extensions |
271 | 274 |
272 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 275 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
OLD | NEW |