| 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 class RenderViewHost; | |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 26 class RenderViewHost; |
| 27 class SiteInstance; | 27 class SiteInstance; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 // Manages dynamic state of running Chromium extensions. There is one instance | 30 // 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 | 31 // of this class per Profile. OTR Profiles have a separate instance that keeps |
| 32 // track of split-mode extensions only. | 32 // track of split-mode extensions only. |
| 33 class ExtensionProcessManager : public content::NotificationObserver { | 33 class ExtensionProcessManager : public content::NotificationObserver { |
| 34 public: | 34 public: |
| 35 static ExtensionProcessManager* Create(Profile* profile); | 35 static ExtensionProcessManager* Create(Profile* profile); |
| 36 virtual ~ExtensionProcessManager(); | 36 virtual ~ExtensionProcessManager(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // Gets the ExtensionHost for the background page for an extension, or NULL if | 68 // Gets the ExtensionHost for the background page for an extension, or NULL if |
| 69 // the extension isn't running or doesn't have a background page. | 69 // the extension isn't running or doesn't have a background page. |
| 70 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id); | 70 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id); |
| 71 | 71 |
| 72 // Returns the SiteInstance that the given URL belongs to. | 72 // Returns the SiteInstance that the given URL belongs to. |
| 73 // TODO(aa): This only returns correct results for extensions and packaged | 73 // TODO(aa): This only returns correct results for extensions and packaged |
| 74 // apps, not hosted apps. | 74 // apps, not hosted apps. |
| 75 virtual content::SiteInstance* GetSiteInstanceForURL(const GURL& url); | 75 virtual content::SiteInstance* GetSiteInstanceForURL(const GURL& url); |
| 76 | 76 |
| 77 // Registers a RenderViewHost as hosting a given extension. | 77 // Registers a RenderViewHost as hosting a given extension. |
| 78 void RegisterRenderViewHost(RenderViewHost* render_view_host, | 78 void RegisterRenderViewHost(content::RenderViewHost* render_view_host, |
| 79 const Extension* extension); | 79 const Extension* extension); |
| 80 | 80 |
| 81 // Unregisters a RenderViewHost as hosting any extension. | 81 // Unregisters a RenderViewHost as hosting any extension. |
| 82 void UnregisterRenderViewHost(RenderViewHost* render_view_host); | 82 void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); |
| 83 | 83 |
| 84 // Returns all RenderViewHosts that are registered for the specified | 84 // Returns all RenderViewHosts that are registered for the specified |
| 85 // extension. | 85 // extension. |
| 86 std::set<RenderViewHost*> GetRenderViewHostsForExtension( | 86 std::set<content::RenderViewHost*> GetRenderViewHostsForExtension( |
| 87 const std::string& extension_id); | 87 const std::string& extension_id); |
| 88 | 88 |
| 89 // Returns true if |host| is managed by this process manager. | 89 // Returns true if |host| is managed by this process manager. |
| 90 bool HasExtensionHost(ExtensionHost* host) const; | 90 bool HasExtensionHost(ExtensionHost* host) const; |
| 91 | 91 |
| 92 // Getter and setter for the lazy background page's keepalive count. This is | 92 // Getter and setter for the lazy background page's keepalive count. This is |
| 93 // the count of how many outstanding "things" are keeping the page alive. | 93 // the count of how many outstanding "things" are keeping the page alive. |
| 94 // When this reaches 0, we will begin the process of shutting down the page. | 94 // When this reaches 0, we will begin the process of shutting down the page. |
| 95 // "Things" include pending events, resource loads, and API calls. | 95 // "Things" include pending events, resource loads, and API calls. |
| 96 int GetLazyKeepaliveCount(const Extension* extension); | 96 int GetLazyKeepaliveCount(const Extension* extension); |
| 97 int IncrementLazyKeepaliveCount(const Extension* extension); | 97 int IncrementLazyKeepaliveCount(const Extension* extension); |
| 98 int DecrementLazyKeepaliveCount(const Extension* extension); | 98 int DecrementLazyKeepaliveCount(const Extension* extension); |
| 99 | 99 |
| 100 // Handles a response to the ShouldClose message, used for lazy background | 100 // Handles a response to the ShouldClose message, used for lazy background |
| 101 // pages. | 101 // pages. |
| 102 void OnShouldCloseAck(const std::string& extension_id, int sequence_id); | 102 void OnShouldCloseAck(const std::string& extension_id, int sequence_id); |
| 103 | 103 |
| 104 // Tracks network requests for a given RenderViewHost, used to know | 104 // Tracks network requests for a given RenderViewHost, used to know |
| 105 // when network activity is idle for lazy background pages. | 105 // when network activity is idle for lazy background pages. |
| 106 void OnNetworkRequestStarted(RenderViewHost* render_view_host); | 106 void OnNetworkRequestStarted(content::RenderViewHost* render_view_host); |
| 107 void OnNetworkRequestDone(RenderViewHost* render_view_host); | 107 void OnNetworkRequestDone(content::RenderViewHost* render_view_host); |
| 108 | 108 |
| 109 typedef std::set<ExtensionHost*> ExtensionHostSet; | 109 typedef std::set<ExtensionHost*> ExtensionHostSet; |
| 110 typedef ExtensionHostSet::const_iterator const_iterator; | 110 typedef ExtensionHostSet::const_iterator const_iterator; |
| 111 const_iterator begin() const { return all_hosts_.begin(); } | 111 const_iterator begin() const { return all_hosts_.begin(); } |
| 112 const_iterator end() const { return all_hosts_.end(); } | 112 const_iterator end() const { return all_hosts_.end(); } |
| 113 | 113 |
| 114 protected: | 114 protected: |
| 115 explicit ExtensionProcessManager(Profile* profile); | 115 explicit ExtensionProcessManager(Profile* profile); |
| 116 | 116 |
| 117 // Called just after |host| is created so it can be registered in our lists. | 117 // Called just after |host| is created so it can be registered in our lists. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 139 | 139 |
| 140 // A SiteInstance related to the SiteInstance for all extensions in | 140 // A SiteInstance related to the SiteInstance for all extensions in |
| 141 // this profile. We create it in such a way that a new | 141 // this profile. We create it in such a way that a new |
| 142 // browsing instance is created. This controls process grouping. | 142 // browsing instance is created. This controls process grouping. |
| 143 scoped_refptr<content::SiteInstance> site_instance_; | 143 scoped_refptr<content::SiteInstance> site_instance_; |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 // Contains all extension-related RenderViewHost instances for all extensions. | 146 // Contains all extension-related RenderViewHost instances for all extensions. |
| 147 // We also keep a cache of the host's view type, because that information | 147 // We also keep a cache of the host's view type, because that information |
| 148 // is not accessible at registration/deregistration time. | 148 // is not accessible at registration/deregistration time. |
| 149 typedef std::map<RenderViewHost*, content::ViewType> ExtensionRenderViews; | 149 typedef std::map<content::RenderViewHost*, |
| 150 content::ViewType> ExtensionRenderViews; |
| 150 ExtensionRenderViews all_extension_views_; | 151 ExtensionRenderViews all_extension_views_; |
| 151 | 152 |
| 152 // Close the given |host| iff it's a background page. | 153 // Close the given |host| iff it's a background page. |
| 153 void CloseBackgroundHost(ExtensionHost* host); | 154 void CloseBackgroundHost(ExtensionHost* host); |
| 154 | 155 |
| 155 // These are called when the extension transitions between idle and active. | 156 // These are called when the extension transitions between idle and active. |
| 156 // They control the process of closing the background page when idle. | 157 // They control the process of closing the background page when idle. |
| 157 void OnLazyBackgroundPageIdle(const std::string& extension_id); | 158 void OnLazyBackgroundPageIdle(const std::string& extension_id); |
| 158 void OnLazyBackgroundPageActive(const std::string& extension_id); | 159 void OnLazyBackgroundPageActive(const std::string& extension_id); |
| 159 | 160 |
| 160 // Updates a potentially-registered RenderViewHost once it has been | 161 // Updates a potentially-registered RenderViewHost once it has been |
| 161 // associated with a WebContents. This allows us to gather information that | 162 // associated with a WebContents. This allows us to gather information that |
| 162 // was not available when the host was first registered. | 163 // was not available when the host was first registered. |
| 163 void UpdateRegisteredRenderView(RenderViewHost* render_view_host); | 164 void UpdateRegisteredRenderView(content::RenderViewHost* render_view_host); |
| 164 | 165 |
| 165 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); | 166 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); |
| 166 }; | 167 }; |
| 167 | 168 |
| 168 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 169 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| OLD | NEW |