Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 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 "content/public/common/view_type.h" | 15 #include "content/public/common/view_type.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 | 18 |
| 19 class Browser; | 19 class Browser; |
| 20 class Extension; | 20 class Extension; |
| 21 class ExtensionHost; | 21 class ExtensionHost; |
| 22 class GURL; | 22 class GURL; |
| 23 class Profile; | 23 class Profile; |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 class RenderViewHost; | 26 class RenderViewHost; |
| 27 class SiteInstance; | 27 class SiteInstance; |
| 28 class WebContents; | |
|
Aaron Boodman
2012/04/20 06:34:56
You can remove this.
benwells
2012/04/23 05:00:26
Done.
| |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 // Manages dynamic state of running Chromium extensions. There is one instance | 31 // Manages dynamic state of running Chromium extensions. There is one instance |
| 31 // of this class per Profile. OTR Profiles have a separate instance that keeps | 32 // of this class per Profile. OTR Profiles have a separate instance that keeps |
| 32 // track of split-mode extensions only. | 33 // track of split-mode extensions only. |
| 33 class ExtensionProcessManager : public content::NotificationObserver { | 34 class ExtensionProcessManager : public content::NotificationObserver { |
| 34 public: | 35 public: |
| 36 typedef std::set<ExtensionHost*> ExtensionHostSet; | |
| 37 typedef ExtensionHostSet::const_iterator const_iterator; | |
| 38 | |
| 35 static ExtensionProcessManager* Create(Profile* profile); | 39 static ExtensionProcessManager* Create(Profile* profile); |
| 36 virtual ~ExtensionProcessManager(); | 40 virtual ~ExtensionProcessManager(); |
| 37 | 41 |
| 42 const ExtensionHostSet& background_hosts() const { | |
| 43 return background_hosts_; | |
| 44 } | |
| 45 | |
| 46 const ExtensionHostSet& platform_app_hosts() const { | |
|
Aaron Boodman
2012/04/20 06:34:56
It seems like this is only needed for one test. Ca
benwells
2012/04/23 05:00:26
They can removed for all platform app tests, excep
Aaron Boodman
2012/04/25 21:27:05
I see. Since you know the view type, perhaps you c
| |
| 47 return platform_app_hosts_; | |
| 48 } | |
| 49 | |
| 50 typedef std::set<content::RenderViewHost*> ViewSet; | |
| 51 const ViewSet GetAllViews() const; | |
| 52 | |
| 38 // Creates a new ExtensionHost with its associated view, grouping it in the | 53 // Creates a new ExtensionHost with its associated view, grouping it in the |
| 39 // appropriate SiteInstance (and therefore process) based on the URL and | 54 // appropriate SiteInstance (and therefore process) based on the URL and |
| 40 // profile. | 55 // profile. |
| 41 virtual ExtensionHost* CreateViewHost(const Extension* extension, | 56 virtual ExtensionHost* CreateViewHost(const Extension* extension, |
| 42 const GURL& url, | 57 const GURL& url, |
| 43 Browser* browser, | 58 Browser* browser, |
| 44 content::ViewType view_type); | 59 content::ViewType view_type); |
| 45 ExtensionHost* CreateViewHost(const GURL& url, | 60 ExtensionHost* CreateViewHost(const GURL& url, |
| 46 Browser* browser, | 61 Browser* browser, |
| 47 content::ViewType view_type); | 62 content::ViewType view_type); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 const Extension* extension); | 94 const Extension* extension); |
| 80 | 95 |
| 81 // Unregisters a RenderViewHost as hosting any extension. | 96 // Unregisters a RenderViewHost as hosting any extension. |
| 82 void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); | 97 void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); |
| 83 | 98 |
| 84 // Returns all RenderViewHosts that are registered for the specified | 99 // Returns all RenderViewHosts that are registered for the specified |
| 85 // extension. | 100 // extension. |
| 86 std::set<content::RenderViewHost*> GetRenderViewHostsForExtension( | 101 std::set<content::RenderViewHost*> GetRenderViewHostsForExtension( |
| 87 const std::string& extension_id); | 102 const std::string& extension_id); |
| 88 | 103 |
| 89 // Returns true if |host| is managed by this process manager. | 104 // Returns the extension associated with the specified RenderViewHost, or |
| 90 bool HasExtensionHost(ExtensionHost* host) const; | 105 // NULL. |
| 106 const Extension* GetExtensionForRenderViewHost( | |
| 107 content::RenderViewHost* render_view_host); | |
| 91 | 108 |
| 92 // Returns true if the (lazy) background host for the given extension has | 109 // Returns true if the (lazy) background host for the given extension has |
| 93 // already been sent the unload event and is shutting down. | 110 // already been sent the unload event and is shutting down. |
| 94 bool IsBackgroundHostClosing(const std::string& extension_id); | 111 bool IsBackgroundHostClosing(const std::string& extension_id); |
| 95 | 112 |
| 96 // Getter and setter for the lazy background page's keepalive count. This is | 113 // Getter and setter for the lazy background page's keepalive count. This is |
| 97 // the count of how many outstanding "things" are keeping the page alive. | 114 // the count of how many outstanding "things" are keeping the page alive. |
| 98 // When this reaches 0, we will begin the process of shutting down the page. | 115 // When this reaches 0, we will begin the process of shutting down the page. |
| 99 // "Things" include pending events, resource loads, and API calls. | 116 // "Things" include pending events, resource loads, and API calls. |
| 100 int GetLazyKeepaliveCount(const Extension* extension); | 117 int GetLazyKeepaliveCount(const Extension* extension); |
| 101 int IncrementLazyKeepaliveCount(const Extension* extension); | 118 int IncrementLazyKeepaliveCount(const Extension* extension); |
| 102 int DecrementLazyKeepaliveCount(const Extension* extension); | 119 int DecrementLazyKeepaliveCount(const Extension* extension); |
| 103 | 120 |
| 104 // Handles a response to the ShouldUnload message, used for lazy background | 121 // Handles a response to the ShouldUnload message, used for lazy background |
| 105 // pages. | 122 // pages. |
| 106 void OnShouldUnloadAck(const std::string& extension_id, int sequence_id); | 123 void OnShouldUnloadAck(const std::string& extension_id, int sequence_id); |
| 107 | 124 |
| 108 // Same as above, for the Unload message. | 125 // Same as above, for the Unload message. |
| 109 void OnUnloadAck(const std::string& extension_id); | 126 void OnUnloadAck(const std::string& extension_id); |
| 110 | 127 |
| 111 // Tracks network requests for a given RenderViewHost, used to know | 128 // Tracks network requests for a given RenderViewHost, used to know |
| 112 // when network activity is idle for lazy background pages. | 129 // when network activity is idle for lazy background pages. |
| 113 void OnNetworkRequestStarted(content::RenderViewHost* render_view_host); | 130 void OnNetworkRequestStarted(content::RenderViewHost* render_view_host); |
| 114 void OnNetworkRequestDone(content::RenderViewHost* render_view_host); | 131 void OnNetworkRequestDone(content::RenderViewHost* render_view_host); |
| 115 | 132 |
| 116 typedef std::set<ExtensionHost*> ExtensionHostSet; | |
| 117 typedef ExtensionHostSet::const_iterator const_iterator; | |
| 118 const_iterator begin() const { return all_hosts_.begin(); } | |
| 119 const_iterator end() const { return all_hosts_.end(); } | |
| 120 | |
| 121 protected: | 133 protected: |
| 122 explicit ExtensionProcessManager(Profile* profile); | 134 explicit ExtensionProcessManager(Profile* profile); |
| 123 | 135 |
| 124 // Called just after |host| is created so it can be registered in our lists. | 136 // Called just after |host| is created so it can be registered in our lists. |
| 125 void OnExtensionHostCreated(ExtensionHost* host, bool is_background); | 137 void OnExtensionHostCreated(ExtensionHost* host, bool is_background); |
| 126 | 138 |
| 127 // Called on browser shutdown to close our extension hosts. | 139 // Called on browser shutdown to close our extension hosts. |
| 128 void CloseBackgroundHosts(); | 140 void CloseBackgroundHosts(); |
| 129 | 141 |
| 130 // content::NotificationObserver: | 142 // content::NotificationObserver: |
| 131 virtual void Observe(int type, | 143 virtual void Observe(int type, |
| 132 const content::NotificationSource& source, | 144 const content::NotificationSource& source, |
| 133 const content::NotificationDetails& details) OVERRIDE; | 145 const content::NotificationDetails& details) OVERRIDE; |
| 134 | 146 |
| 135 // Gets the profile associated with site_instance_ and all other | 147 // Gets the profile associated with site_instance_ and all other |
| 136 // related SiteInstances. | 148 // related SiteInstances. |
| 137 Profile* GetProfile() const; | 149 Profile* GetProfile() const; |
| 138 | 150 |
| 139 content::NotificationRegistrar registrar_; | 151 content::NotificationRegistrar registrar_; |
| 140 | 152 |
| 141 // The set of all ExtensionHosts managed by this process manager. | 153 // The set of ExtensionHosts running viewless background extensions. |
| 142 ExtensionHostSet all_hosts_; | 154 ExtensionHostSet background_hosts_; |
| 143 | 155 |
| 144 // The set of running viewless background extensions. | 156 // The set of ExtensionHosts running platform apps. |
| 145 ExtensionHostSet background_hosts_; | 157 ExtensionHostSet platform_app_hosts_; |
| 146 | 158 |
| 147 // A SiteInstance related to the SiteInstance for all extensions in | 159 // A SiteInstance related to the SiteInstance for all extensions in |
| 148 // this profile. We create it in such a way that a new | 160 // this profile. We create it in such a way that a new |
| 149 // browsing instance is created. This controls process grouping. | 161 // browsing instance is created. This controls process grouping. |
| 150 scoped_refptr<content::SiteInstance> site_instance_; | 162 scoped_refptr<content::SiteInstance> site_instance_; |
| 151 | 163 |
| 152 private: | 164 private: |
| 153 // Extra information we keep for each extension's background page. | 165 // Extra information we keep for each extension's background page. |
| 154 struct BackgroundPageData; | 166 struct BackgroundPageData; |
| 155 typedef std::string ExtensionId; | 167 typedef std::string ExtensionId; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 178 // associated with a WebContents. This allows us to gather information that | 190 // associated with a WebContents. This allows us to gather information that |
| 179 // was not available when the host was first registered. | 191 // was not available when the host was first registered. |
| 180 void UpdateRegisteredRenderView(content::RenderViewHost* render_view_host); | 192 void UpdateRegisteredRenderView(content::RenderViewHost* render_view_host); |
| 181 | 193 |
| 182 BackgroundPageDataMap background_page_data_; | 194 BackgroundPageDataMap background_page_data_; |
| 183 | 195 |
| 184 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); | 196 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); |
| 185 }; | 197 }; |
| 186 | 198 |
| 187 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 199 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| OLD | NEW |