Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 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 ProcessManagerObserver; | 36 class ProcessManagerObserver; |
| 37 | 37 |
| 38 // Customization of ProcessManager from the extension system embedder. | |
| 39 class ProcessManagerDelegate { | |
|
Yoyo Zhou
2014/07/15 02:13:22
Probably it's best to put this in a separate heade
James Cook
2014/07/15 17:02:52
Done.
| |
| 40 public: | |
| 41 virtual ~ProcessManagerDelegate() {} | |
| 42 | |
| 43 // Returns true if the embedder allows background pages for the given | |
| 44 // |context|. | |
| 45 virtual bool IsBackgroundPageAllowed( | |
| 46 content::BrowserContext* context) const = 0; | |
| 47 | |
| 48 // Returns true if the embedder wishes to defer starting up the renderers for | |
| 49 // extension background pages. If the embedder returns true it must call | |
| 50 // ProcessManager::MaybeCreateStartupBackgroundHosts() when it is ready. See | |
| 51 // ChromeProcessManagerDelegate for examples of how this is useful. | |
| 52 virtual bool DeferCreatingStartupBackgroundHosts( | |
| 53 content::BrowserContext* context) const = 0; | |
| 54 }; | |
| 55 | |
| 38 // Manages dynamic state of running Chromium extensions. There is one instance | 56 // 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 | 57 // of this class per Profile. OTR Profiles have a separate instance that keeps |
| 40 // track of split-mode extensions only. | 58 // track of split-mode extensions only. |
| 41 class ProcessManager : public content::NotificationObserver { | 59 class ProcessManager : public content::NotificationObserver { |
| 42 public: | 60 public: |
| 43 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; | 61 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; |
| 44 typedef ExtensionHostSet::const_iterator const_iterator; | 62 typedef ExtensionHostSet::const_iterator const_iterator; |
| 45 | 63 |
| 46 static ProcessManager* Create(content::BrowserContext* context); | 64 static ProcessManager* Create(content::BrowserContext* context); |
| 47 virtual ~ProcessManager(); | 65 virtual ~ProcessManager(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 133 |
| 116 // Tracks network requests for a given RenderFrameHost, used to know | 134 // Tracks network requests for a given RenderFrameHost, used to know |
| 117 // when network activity is idle for lazy background pages. | 135 // when network activity is idle for lazy background pages. |
| 118 void OnNetworkRequestStarted(content::RenderFrameHost* render_frame_host); | 136 void OnNetworkRequestStarted(content::RenderFrameHost* render_frame_host); |
| 119 void OnNetworkRequestDone(content::RenderFrameHost* render_frame_host); | 137 void OnNetworkRequestDone(content::RenderFrameHost* render_frame_host); |
| 120 | 138 |
| 121 // Prevents |extension|'s background page from being closed and sends the | 139 // Prevents |extension|'s background page from being closed and sends the |
| 122 // onSuspendCanceled() event to it. | 140 // onSuspendCanceled() event to it. |
| 123 void CancelSuspend(const Extension* extension); | 141 void CancelSuspend(const Extension* extension); |
| 124 | 142 |
| 125 // Ensures background hosts are loaded for a new browser window. | 143 // Creates background hosts if the embedder is ready and they are not already |
| 126 void OnBrowserWindowReady(); | 144 // loaded. |
| 145 void MaybeCreateStartupBackgroundHosts(); | |
| 127 | 146 |
| 128 // Gets the BrowserContext associated with site_instance_ and all other | 147 // Gets the BrowserContext associated with site_instance_ and all other |
| 129 // related SiteInstances. | 148 // related SiteInstances. |
| 130 content::BrowserContext* GetBrowserContext() const; | 149 content::BrowserContext* GetBrowserContext() const; |
| 131 | 150 |
| 132 // Sets callbacks for testing keepalive impulse behavior. | 151 // Sets callbacks for testing keepalive impulse behavior. |
| 133 typedef base::Callback<void(const std::string& extension_id)> | 152 typedef base::Callback<void(const std::string& extension_id)> |
| 134 ImpulseCallbackForTesting; | 153 ImpulseCallbackForTesting; |
| 135 void SetKeepaliveImpulseCallbackForTesting( | 154 void SetKeepaliveImpulseCallbackForTesting( |
| 136 const ImpulseCallbackForTesting& callback); | 155 const ImpulseCallbackForTesting& callback); |
| 137 void SetKeepaliveImpulseDecrementCallbackForTesting( | 156 void SetKeepaliveImpulseDecrementCallbackForTesting( |
| 138 const ImpulseCallbackForTesting& callback); | 157 const ImpulseCallbackForTesting& callback); |
| 139 | 158 |
| 140 // Creates an incognito-context instance for tests. Tests for non-incognito | 159 // Creates an incognito-context instance for tests. Tests for non-incognito |
| 141 // contexts can just use Create() above. | 160 // contexts can just use Create() above. |
| 142 static ProcessManager* CreateIncognitoForTesting( | 161 static ProcessManager* CreateIncognitoForTesting( |
| 143 content::BrowserContext* incognito_context, | 162 content::BrowserContext* incognito_context, |
| 144 content::BrowserContext* original_context, | 163 content::BrowserContext* original_context, |
| 145 ProcessManager* original_manager); | 164 ProcessManager* original_manager); |
| 146 | 165 |
| 166 bool startup_background_hosts_created_for_test() const { | |
| 167 return startup_background_hosts_created_; | |
| 168 } | |
| 169 | |
| 147 protected: | 170 protected: |
| 148 // If |context| is incognito pass the master context as |original_context|. | 171 // If |context| is incognito pass the master context as |original_context|. |
| 149 // Otherwise pass the same context for both. | 172 // Otherwise pass the same context for both. |
| 150 ProcessManager(content::BrowserContext* context, | 173 ProcessManager(content::BrowserContext* context, |
| 151 content::BrowserContext* original_context); | 174 content::BrowserContext* original_context); |
| 152 | 175 |
| 153 // Called on browser shutdown to close our extension hosts. | 176 // Called on browser shutdown to close our extension hosts. |
| 154 void CloseBackgroundHosts(); | 177 void CloseBackgroundHosts(); |
| 155 | 178 |
| 156 // content::NotificationObserver: | 179 // content::NotificationObserver: |
| 157 virtual void Observe(int type, | 180 virtual void Observe(int type, |
| 158 const content::NotificationSource& source, | 181 const content::NotificationSource& source, |
| 159 const content::NotificationDetails& details) OVERRIDE; | 182 const content::NotificationDetails& details) OVERRIDE; |
| 160 | 183 |
| 161 // Load all background pages once the profile data is ready and the pages | 184 // Load all background pages once the profile data is ready and the pages |
| 162 // should be loaded. | 185 // should be loaded. |
| 163 void CreateBackgroundHostsForProfileStartup(); | 186 void CreateStartupBackgroundHosts(); |
|
Yoyo Zhou
2014/07/15 02:13:22
nit: does this need to be protected? can it be in
James Cook
2014/07/15 17:02:52
Good catch! Moved to private.
| |
| 164 | 187 |
| 165 content::NotificationRegistrar registrar_; | 188 content::NotificationRegistrar registrar_; |
| 166 | 189 |
| 167 // The set of ExtensionHosts running viewless background extensions. | 190 // The set of ExtensionHosts running viewless background extensions. |
| 168 ExtensionHostSet background_hosts_; | 191 ExtensionHostSet background_hosts_; |
| 169 | 192 |
| 170 // A SiteInstance related to the SiteInstance for all extensions in | 193 // A SiteInstance related to the SiteInstance for all extensions in |
| 171 // this profile. We create it in such a way that a new | 194 // this profile. We create it in such a way that a new |
| 172 // browsing instance is created. This controls process grouping. | 195 // browsing instance is created. This controls process grouping. |
| 173 scoped_refptr<content::SiteInstance> site_instance_; | 196 scoped_refptr<content::SiteInstance> site_instance_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 // with an extension). | 232 // with an extension). |
| 210 bool RegisterRenderViewHost(content::RenderViewHost* render_view_host); | 233 bool RegisterRenderViewHost(content::RenderViewHost* render_view_host); |
| 211 | 234 |
| 212 // Unregister RenderViewHosts and clear background page data for an extension | 235 // Unregister RenderViewHosts and clear background page data for an extension |
| 213 // which has been unloaded. | 236 // which has been unloaded. |
| 214 void UnregisterExtension(const std::string& extension_id); | 237 void UnregisterExtension(const std::string& extension_id); |
| 215 | 238 |
| 216 // Clears background page data for this extension. | 239 // Clears background page data for this extension. |
| 217 void ClearBackgroundPageData(const std::string& extension_id); | 240 void ClearBackgroundPageData(const std::string& extension_id); |
| 218 | 241 |
| 219 // Returns true if loading background pages should be deferred. | |
| 220 bool DeferLoadingBackgroundHosts() const; | |
| 221 | |
| 222 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); | 242 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); |
| 223 | 243 |
| 224 // Contains all active extension-related RenderViewHost instances for all | 244 // Contains all active extension-related RenderViewHost instances for all |
| 225 // extensions. We also keep a cache of the host's view type, because that | 245 // extensions. We also keep a cache of the host's view type, because that |
| 226 // information is not accessible at registration/deregistration time. | 246 // information is not accessible at registration/deregistration time. |
| 227 ExtensionRenderViews all_extension_views_; | 247 ExtensionRenderViews all_extension_views_; |
| 228 | 248 |
| 229 BackgroundPageDataMap background_page_data_; | 249 BackgroundPageDataMap background_page_data_; |
| 230 | 250 |
| 231 // The time to delay between an extension becoming idle and | 251 // The time to delay between an extension becoming idle and |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 247 ObserverList<ProcessManagerObserver> observer_list_; | 267 ObserverList<ProcessManagerObserver> observer_list_; |
| 248 | 268 |
| 249 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; | 269 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; |
| 250 | 270 |
| 251 DISALLOW_COPY_AND_ASSIGN(ProcessManager); | 271 DISALLOW_COPY_AND_ASSIGN(ProcessManager); |
| 252 }; | 272 }; |
| 253 | 273 |
| 254 } // namespace extensions | 274 } // namespace extensions |
| 255 | 275 |
| 256 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 276 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
| OLD | NEW |