| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 20 #include "extensions/common/view_type.h" | 21 #include "extensions/common/view_type.h" |
| 21 | 22 |
| 22 class GURL; | 23 class GURL; |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 class BrowserContext; | 26 class BrowserContext; |
| 26 class DevToolsAgentHost; | 27 class DevToolsAgentHost; |
| 27 class RenderViewHost; | 28 class RenderViewHost; |
| 28 class RenderFrameHost; | 29 class RenderFrameHost; |
| 29 class SiteInstance; | 30 class SiteInstance; |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 namespace extensions { | 33 namespace extensions { |
| 33 | 34 |
| 34 class Extension; | 35 class Extension; |
| 35 class ExtensionHost; | 36 class ExtensionHost; |
| 36 class ExtensionRegistry; | 37 class ExtensionRegistry; |
| 37 class ProcessManagerDelegate; | 38 class ProcessManagerDelegate; |
| 38 class ProcessManagerObserver; | 39 class ProcessManagerObserver; |
| 39 | 40 |
| 40 // Manages dynamic state of running Chromium extensions. There is one instance | 41 // Manages dynamic state of running Chromium extensions. There is one instance |
| 41 // of this class per Profile. OTR Profiles have a separate instance that keeps | 42 // of this class per Profile. OTR Profiles have a separate instance that keeps |
| 42 // track of split-mode extensions only. | 43 // track of split-mode extensions only. |
| 43 class ProcessManager : public content::NotificationObserver { | 44 class ProcessManager : public KeyedService, |
| 45 public content::NotificationObserver { |
| 44 public: | 46 public: |
| 45 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; | 47 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; |
| 46 typedef ExtensionHostSet::const_iterator const_iterator; | 48 typedef ExtensionHostSet::const_iterator const_iterator; |
| 47 | 49 |
| 48 static ProcessManager* Create(content::BrowserContext* context); | 50 static ProcessManager* Get(content::BrowserContext* context); |
| 49 ~ProcessManager() override; | 51 ~ProcessManager() override; |
| 50 | 52 |
| 51 const ExtensionHostSet& background_hosts() const { | 53 const ExtensionHostSet& background_hosts() const { |
| 52 return background_hosts_; | 54 return background_hosts_; |
| 53 } | 55 } |
| 54 | 56 |
| 55 typedef std::set<content::RenderViewHost*> ViewSet; | 57 typedef std::set<content::RenderViewHost*> ViewSet; |
| 56 const ViewSet GetAllViews() const; | 58 const ViewSet GetAllViews() const; |
| 57 | 59 |
| 58 // The typical observer interface. | 60 // The typical observer interface. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // Creates a non-incognito instance for tests. |registry| allows unit tests | 163 // Creates a non-incognito instance for tests. |registry| allows unit tests |
| 162 // to inject an ExtensionRegistry that is not managed by the usual | 164 // to inject an ExtensionRegistry that is not managed by the usual |
| 163 // BrowserContextKeyedServiceFactory system. | 165 // BrowserContextKeyedServiceFactory system. |
| 164 static ProcessManager* CreateForTesting(content::BrowserContext* context, | 166 static ProcessManager* CreateForTesting(content::BrowserContext* context, |
| 165 ExtensionRegistry* registry); | 167 ExtensionRegistry* registry); |
| 166 | 168 |
| 167 // Creates an incognito-context instance for tests. | 169 // Creates an incognito-context instance for tests. |
| 168 static ProcessManager* CreateIncognitoForTesting( | 170 static ProcessManager* CreateIncognitoForTesting( |
| 169 content::BrowserContext* incognito_context, | 171 content::BrowserContext* incognito_context, |
| 170 content::BrowserContext* original_context, | 172 content::BrowserContext* original_context, |
| 171 ProcessManager* original_manager, | |
| 172 ExtensionRegistry* registry); | 173 ExtensionRegistry* registry); |
| 173 | 174 |
| 174 bool startup_background_hosts_created_for_test() const { | 175 bool startup_background_hosts_created_for_test() const { |
| 175 return startup_background_hosts_created_; | 176 return startup_background_hosts_created_; |
| 176 } | 177 } |
| 177 | 178 |
| 178 protected: | 179 protected: |
| 179 // If |context| is incognito pass the master context as |original_context|. | 180 static ProcessManager* Create(content::BrowserContext* context); |
| 181 |
| 182 // |context| is incognito pass the master context as |original_context|. |
| 180 // Otherwise pass the same context for both. Pass the ExtensionRegistry for | 183 // Otherwise pass the same context for both. Pass the ExtensionRegistry for |
| 181 // |context| as |registry|, or override it for testing. | 184 // |context| as |registry|, or override it for testing. |
| 182 ProcessManager(content::BrowserContext* context, | 185 ProcessManager(content::BrowserContext* context, |
| 183 content::BrowserContext* original_context, | 186 content::BrowserContext* original_context, |
| 184 ExtensionRegistry* registry); | 187 ExtensionRegistry* registry); |
| 185 | 188 |
| 186 // content::NotificationObserver: | 189 // content::NotificationObserver: |
| 187 void Observe(int type, | 190 void Observe(int type, |
| 188 const content::NotificationSource& source, | 191 const content::NotificationSource& source, |
| 189 const content::NotificationDetails& details) override; | 192 const content::NotificationDetails& details) override; |
| 190 | 193 |
| 191 content::NotificationRegistrar registrar_; | 194 content::NotificationRegistrar registrar_; |
| 192 | 195 |
| 193 // The set of ExtensionHosts running viewless background extensions. | 196 // The set of ExtensionHosts running viewless background extensions. |
| 194 ExtensionHostSet background_hosts_; | 197 ExtensionHostSet background_hosts_; |
| 195 | 198 |
| 196 // A SiteInstance related to the SiteInstance for all extensions in | 199 // A SiteInstance related to the SiteInstance for all extensions in |
| 197 // this profile. We create it in such a way that a new | 200 // this profile. We create it in such a way that a new |
| 198 // browsing instance is created. This controls process grouping. | 201 // browsing instance is created. This controls process grouping. |
| 199 scoped_refptr<content::SiteInstance> site_instance_; | 202 scoped_refptr<content::SiteInstance> site_instance_; |
| 200 | 203 |
| 201 // Not owned. Also used by IncognitoProcessManager. | 204 // Not owned. Also used by IncognitoProcessManager. |
| 202 ExtensionRegistry* extension_registry_; | 205 ExtensionRegistry* extension_registry_; |
| 203 | 206 |
| 204 private: | 207 private: |
| 208 friend class ProcessManagerFactory; |
| 205 friend class ProcessManagerTest; | 209 friend class ProcessManagerTest; |
| 206 | 210 |
| 207 // Extra information we keep for each extension's background page. | 211 // Extra information we keep for each extension's background page. |
| 208 struct BackgroundPageData; | 212 struct BackgroundPageData; |
| 209 typedef std::string ExtensionId; | 213 typedef std::string ExtensionId; |
| 210 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; | 214 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; |
| 211 typedef std::map<content::RenderViewHost*, | 215 typedef std::map<content::RenderViewHost*, |
| 212 extensions::ViewType> ExtensionRenderViews; | 216 extensions::ViewType> ExtensionRenderViews; |
| 213 | 217 |
| 214 // Load all background pages once the profile data is ready and the pages | 218 // Load all background pages once the profile data is ready and the pages |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 289 |
| 286 // Must be last member, see doc on WeakPtrFactory. | 290 // Must be last member, see doc on WeakPtrFactory. |
| 287 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; | 291 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; |
| 288 | 292 |
| 289 DISALLOW_COPY_AND_ASSIGN(ProcessManager); | 293 DISALLOW_COPY_AND_ASSIGN(ProcessManager); |
| 290 }; | 294 }; |
| 291 | 295 |
| 292 } // namespace extensions | 296 } // namespace extensions |
| 293 | 297 |
| 294 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ | 298 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
| OLD | NEW |