[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
| 6 | #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 7 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 8 | #include <map> |
[email protected] | 8a17bd5 | 2009-06-06 08:19:49 | [diff] [blame] | 9 | #include <set> |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 10 | #include <string> |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 11 | |
[email protected] | a23f62e | 2013-04-26 13:13:02 | [diff] [blame] | 12 | #include "base/callback.h" |
[email protected] | 1790275 | 2011-08-31 22:52:54 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
[email protected] | 99c49b5 | 2012-05-02 01:50:20 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | 08d469b2 | 2014-03-31 00:51:24 | [diff] [blame] | 16 | #include "base/observer_list.h" |
[email protected] | 41a17c5 | 2013-06-28 00:27:53 | [diff] [blame] | 17 | #include "base/time/time.h" |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 18 | #include "components/keyed_service/core/keyed_service.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 19 | #include "content/public/browser/notification_observer.h" |
| 20 | #include "content/public/browser/notification_registrar.h" |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 21 | #include "extensions/common/view_type.h" |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 22 | |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 23 | class GURL; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 24 | |
| 25 | namespace content { |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 26 | class BrowserContext; |
[email protected] | a23f62e | 2013-04-26 13:13:02 | [diff] [blame] | 27 | class DevToolsAgentHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 28 | class RenderViewHost; |
[email protected] | 9dfed87 | 2013-12-30 23:08:56 | [diff] [blame] | 29 | class RenderFrameHost; |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 30 | class SiteInstance; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 31 | }; |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 32 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 33 | namespace extensions { |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 34 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 35 | class Extension; |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 36 | class ExtensionHost; |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 37 | class ExtensionRegistry; |
| 38 | class ProcessManagerDelegate; |
[email protected] | 08d469b2 | 2014-03-31 00:51:24 | [diff] [blame] | 39 | class ProcessManagerObserver; |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 40 | |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 41 | // Manages dynamic state of running Chromium extensions. There is one instance |
| 42 | // of this class per Profile. OTR Profiles have a separate instance that keeps |
| 43 | // track of split-mode extensions only. |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 44 | class ProcessManager : public KeyedService, |
| 45 | public content::NotificationObserver { |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 46 | public: |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 47 | typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 48 | typedef ExtensionHostSet::const_iterator const_iterator; |
| 49 | |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 50 | static ProcessManager* Get(content::BrowserContext* context); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 51 | ~ProcessManager() override; |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 52 | |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 53 | const ExtensionHostSet& background_hosts() const { |
| 54 | return background_hosts_; |
| 55 | } |
| 56 | |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 57 | typedef std::set<content::RenderViewHost*> ViewSet; |
| 58 | const ViewSet GetAllViews() const; |
| 59 | |
[email protected] | 08d469b2 | 2014-03-31 00:51:24 | [diff] [blame] | 60 | // The typical observer interface. |
| 61 | void AddObserver(ProcessManagerObserver* observer); |
| 62 | void RemoveObserver(ProcessManagerObserver* observer); |
| 63 | |
[email protected] | 029ad37 | 2011-05-20 17:12:56 | [diff] [blame] | 64 | // Creates a new UI-less extension instance. Like CreateViewHost, but not |
[email protected] | 6ad9cdf7 | 2014-02-27 13:12:41 | [diff] [blame] | 65 | // displayed anywhere. Returns false if no background host can be created, |
| 66 | // for example for hosted apps and extensions that aren't enabled in |
| 67 | // Incognito. |
| 68 | virtual bool CreateBackgroundHost(const Extension* extension, |
| 69 | const GURL& url); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 70 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 71 | // Gets the ExtensionHost for the background page for an extension, or NULL if |
| 72 | // the extension isn't running or doesn't have a background page. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 73 | ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 74 | |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 75 | // Returns the SiteInstance that the given URL belongs to. |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 76 | // TODO(aa): This only returns correct results for extensions and packaged |
| 77 | // apps, not hosted apps. |
rdevlin.cronin | 3d426152 | 2015-02-10 00:48:15 | [diff] [blame] | 78 | virtual scoped_refptr<content::SiteInstance> GetSiteInstanceForURL( |
| 79 | const GURL& url); |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 80 | |
hashimoto | 5bca227 | 2014-11-04 07:35:18 | [diff] [blame] | 81 | // If the view isn't keeping the lazy background page alive, increments the |
| 82 | // keepalive count to do so. |
| 83 | void AcquireLazyKeepaliveCountForView( |
| 84 | content::RenderViewHost* render_view_host); |
| 85 | |
| 86 | // If the view is keeping the lazy background page alive, decrements the |
| 87 | // keepalive count to stop doing it. |
| 88 | void ReleaseLazyKeepaliveCountForView( |
| 89 | content::RenderViewHost* render_view_host); |
| 90 | |
[email protected] | 3e19499 | 2011-10-20 05:39:10 | [diff] [blame] | 91 | // Unregisters a RenderViewHost as hosting any extension. |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 92 | void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); |
[email protected] | 3e19499 | 2011-10-20 05:39:10 | [diff] [blame] | 93 | |
| 94 | // Returns all RenderViewHosts that are registered for the specified |
| 95 | // extension. |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 96 | std::set<content::RenderViewHost*> GetRenderViewHostsForExtension( |
[email protected] | 3e19499 | 2011-10-20 05:39:10 | [diff] [blame] | 97 | const std::string& extension_id); |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 98 | |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 99 | // Returns the extension associated with the specified RenderViewHost, or |
| 100 | // NULL. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 101 | const Extension* GetExtensionForRenderViewHost( |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 102 | content::RenderViewHost* render_view_host); |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 103 | |
[email protected] | 7042b68 | 2012-04-19 22:57:51 | [diff] [blame] | 104 | // Returns true if the (lazy) background host for the given extension has |
| 105 | // already been sent the unload event and is shutting down. |
| 106 | bool IsBackgroundHostClosing(const std::string& extension_id); |
| 107 | |
[email protected] | 720ad131 | 2012-02-27 23:07:36 | [diff] [blame] | 108 | // Getter and setter for the lazy background page's keepalive count. This is |
| 109 | // the count of how many outstanding "things" are keeping the page alive. |
| 110 | // When this reaches 0, we will begin the process of shutting down the page. |
| 111 | // "Things" include pending events, resource loads, and API calls. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 112 | int GetLazyKeepaliveCount(const Extension* extension); |
[email protected] | 38877015 | 2013-12-03 01:25:32 | [diff] [blame] | 113 | void IncrementLazyKeepaliveCount(const Extension* extension); |
| 114 | void DecrementLazyKeepaliveCount(const Extension* extension); |
[email protected] | 720ad131 | 2012-02-27 23:07:36 | [diff] [blame] | 115 | |
[email protected] | 38877015 | 2013-12-03 01:25:32 | [diff] [blame] | 116 | // Keeps a background page alive. Unlike IncrementLazyKeepaliveCount, these |
| 117 | // impulses will only keep the page alive for a limited amount of time unless |
| 118 | // called regularly. |
| 119 | void KeepaliveImpulse(const Extension* extension); |
| 120 | |
[email protected] | e0ff1aa | 2014-08-16 01:38:11 | [diff] [blame] | 121 | // Triggers a keepalive impulse for a plug-in (e.g NaCl). |
| 122 | static void OnKeepaliveFromPlugin(int render_process_id, |
| 123 | int render_frame_id, |
| 124 | const std::string& extension_id); |
| 125 | |
[email protected] | 584e657 | 2013-02-16 07:02:33 | [diff] [blame] | 126 | // Handles a response to the ShouldSuspend message, used for lazy background |
[email protected] | 720ad131 | 2012-02-27 23:07:36 | [diff] [blame] | 127 | // pages. |
[email protected] | 77a538f | 2014-07-14 22:25:37 | [diff] [blame] | 128 | void OnShouldSuspendAck(const std::string& extension_id, uint64 sequence_id); |
[email protected] | 103f19f | 2012-04-02 19:30:12 | [diff] [blame] | 129 | |
[email protected] | 584e657 | 2013-02-16 07:02:33 | [diff] [blame] | 130 | // Same as above, for the Suspend message. |
| 131 | void OnSuspendAck(const std::string& extension_id); |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 132 | |
[email protected] | 9dfed87 | 2013-12-30 23:08:56 | [diff] [blame] | 133 | // Tracks network requests for a given RenderFrameHost, used to know |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 134 | // when network activity is idle for lazy background pages. |
chirantan | 79788f6 | 2015-02-02 23:57:25 | [diff] [blame] | 135 | void OnNetworkRequestStarted(content::RenderFrameHost* render_frame_host, |
| 136 | uint64 request_id); |
| 137 | void OnNetworkRequestDone(content::RenderFrameHost* render_frame_host, |
| 138 | uint64 request_id); |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 139 | |
[email protected] | 0d475e07 | 2012-07-26 02:30:42 | [diff] [blame] | 140 | // Prevents |extension|'s background page from being closed and sends the |
| 141 | // onSuspendCanceled() event to it. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 142 | void CancelSuspend(const Extension* extension); |
[email protected] | 0d475e07 | 2012-07-26 02:30:42 | [diff] [blame] | 143 | |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 144 | // Creates background hosts if the embedder is ready and they are not already |
| 145 | // loaded. |
| 146 | void MaybeCreateStartupBackgroundHosts(); |
[email protected] | aa3dd49 | 2013-11-05 17:09:09 | [diff] [blame] | 147 | |
[email protected] | 9602db4 | 2014-07-25 05:24:37 | [diff] [blame] | 148 | // Called on shutdown to close our extension hosts. |
| 149 | void CloseBackgroundHosts(); |
| 150 | |
[email protected] | aa3dd49 | 2013-11-05 17:09:09 | [diff] [blame] | 151 | // Gets the BrowserContext associated with site_instance_ and all other |
| 152 | // related SiteInstances. |
| 153 | content::BrowserContext* GetBrowserContext() const; |
| 154 | |
[email protected] | b6cd720 | 2014-01-07 17:46:55 | [diff] [blame] | 155 | // Sets callbacks for testing keepalive impulse behavior. |
| 156 | typedef base::Callback<void(const std::string& extension_id)> |
| 157 | ImpulseCallbackForTesting; |
| 158 | void SetKeepaliveImpulseCallbackForTesting( |
| 159 | const ImpulseCallbackForTesting& callback); |
| 160 | void SetKeepaliveImpulseDecrementCallbackForTesting( |
| 161 | const ImpulseCallbackForTesting& callback); |
| 162 | |
yoz | a9bf560 | 2014-09-19 02:03:31 | [diff] [blame] | 163 | // Sets the time in milliseconds that an extension event page can |
| 164 | // be idle before it is shut down; must be > 0. |
| 165 | static void SetEventPageIdleTimeForTesting(unsigned idle_time_msec); |
| 166 | |
| 167 | // Sets the time in milliseconds that an extension event page has |
| 168 | // between being notified of its impending unload and that unload |
| 169 | // happening. |
| 170 | static void SetEventPageSuspendingTimeForTesting( |
| 171 | unsigned suspending_time_msec); |
| 172 | |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 173 | // Creates a non-incognito instance for tests. |registry| allows unit tests |
| 174 | // to inject an ExtensionRegistry that is not managed by the usual |
| 175 | // BrowserContextKeyedServiceFactory system. |
| 176 | static ProcessManager* CreateForTesting(content::BrowserContext* context, |
| 177 | ExtensionRegistry* registry); |
| 178 | |
| 179 | // Creates an incognito-context instance for tests. |
[email protected] | b9f6ba3 | 2014-03-10 18:34:08 | [diff] [blame] | 180 | static ProcessManager* CreateIncognitoForTesting( |
| 181 | content::BrowserContext* incognito_context, |
| 182 | content::BrowserContext* original_context, |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 183 | ExtensionRegistry* registry); |
| 184 | |
| 185 | bool startup_background_hosts_created_for_test() const { |
| 186 | return startup_background_hosts_created_; |
| 187 | } |
[email protected] | b9f6ba3 | 2014-03-10 18:34:08 | [diff] [blame] | 188 | |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 189 | protected: |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 190 | static ProcessManager* Create(content::BrowserContext* context); |
| 191 | |
| 192 | // |context| is incognito pass the master context as |original_context|. |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 193 | // Otherwise pass the same context for both. Pass the ExtensionRegistry for |
| 194 | // |context| as |registry|, or override it for testing. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 195 | ProcessManager(content::BrowserContext* context, |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 196 | content::BrowserContext* original_context, |
| 197 | ExtensionRegistry* registry); |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 198 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 199 | // content::NotificationObserver: |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 200 | void Observe(int type, |
| 201 | const content::NotificationSource& source, |
| 202 | const content::NotificationDetails& details) override; |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 203 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 204 | content::NotificationRegistrar registrar_; |
[email protected] | fc36895 | 2009-05-21 21:37:06 | [diff] [blame] | 205 | |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 206 | // The set of ExtensionHosts running viewless background extensions. |
[email protected] | 8a17bd5 | 2009-06-06 08:19:49 | [diff] [blame] | 207 | ExtensionHostSet background_hosts_; |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 208 | |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 209 | // A SiteInstance related to the SiteInstance for all extensions in |
| 210 | // this profile. We create it in such a way that a new |
| 211 | // browsing instance is created. This controls process grouping. |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 212 | scoped_refptr<content::SiteInstance> site_instance_; |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 213 | |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 214 | // Not owned. Also used by IncognitoProcessManager. |
| 215 | ExtensionRegistry* extension_registry_; |
| 216 | |
[email protected] | 3e19499 | 2011-10-20 05:39:10 | [diff] [blame] | 217 | private: |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 218 | friend class ProcessManagerFactory; |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 219 | friend class ProcessManagerTest; |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 220 | |
[email protected] | 103f19f | 2012-04-02 19:30:12 | [diff] [blame] | 221 | // Extra information we keep for each extension's background page. |
| 222 | struct BackgroundPageData; |
hashimoto | 5bca227 | 2014-11-04 07:35:18 | [diff] [blame] | 223 | struct ExtensionRenderViewData; |
[email protected] | 103f19f | 2012-04-02 19:30:12 | [diff] [blame] | 224 | typedef std::string ExtensionId; |
| 225 | typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; |
hashimoto | 5bca227 | 2014-11-04 07:35:18 | [diff] [blame] | 226 | typedef std::map<content::RenderViewHost*, ExtensionRenderViewData> |
| 227 | ExtensionRenderViews; |
[email protected] | 3e19499 | 2011-10-20 05:39:10 | [diff] [blame] | 228 | |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 229 | // Load all background pages once the profile data is ready and the pages |
| 230 | // should be loaded. |
| 231 | void CreateStartupBackgroundHosts(); |
| 232 | |
[email protected] | 94de8cb | 2013-11-07 06:29:21 | [diff] [blame] | 233 | // Called just after |host| is created so it can be registered in our lists. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 234 | void OnBackgroundHostCreated(ExtensionHost* host); |
[email protected] | 94de8cb | 2013-11-07 06:29:21 | [diff] [blame] | 235 | |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 236 | // Close the given |host| iff it's a background page. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 237 | void CloseBackgroundHost(ExtensionHost* host); |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 238 | |
[email protected] | 38877015 | 2013-12-03 01:25:32 | [diff] [blame] | 239 | // Internal implementation of DecrementLazyKeepaliveCount with an |
| 240 | // |extension_id| known to have a lazy background page. |
| 241 | void DecrementLazyKeepaliveCount(const std::string& extension_id); |
| 242 | |
| 243 | // Checks if keepalive impulses have occured, and adjusts keep alive count. |
| 244 | void OnKeepaliveImpulseCheck(); |
| 245 | |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 246 | // These are called when the extension transitions between idle and active. |
| 247 | // They control the process of closing the background page when idle. |
[email protected] | 99c49b5 | 2012-05-02 01:50:20 | [diff] [blame] | 248 | void OnLazyBackgroundPageIdle(const std::string& extension_id, |
[email protected] | 77a538f | 2014-07-14 22:25:37 | [diff] [blame] | 249 | uint64 sequence_id); |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 250 | void OnLazyBackgroundPageActive(const std::string& extension_id); |
[email protected] | 0d475e07 | 2012-07-26 02:30:42 | [diff] [blame] | 251 | void CloseLazyBackgroundPageNow(const std::string& extension_id, |
[email protected] | 77a538f | 2014-07-14 22:25:37 | [diff] [blame] | 252 | uint64 sequence_id); |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 253 | |
[email protected] | 35e0e079 | 2012-11-30 02:35:48 | [diff] [blame] | 254 | // Potentially registers a RenderViewHost, if it is associated with an |
| 255 | // extension. Does nothing if this is not an extension renderer. |
[email protected] | 96cac5e | 2014-02-18 16:22:15 | [diff] [blame] | 256 | // Returns true, if render_view_host was registered (it is associated |
| 257 | // with an extension). |
| 258 | bool RegisterRenderViewHost(content::RenderViewHost* render_view_host); |
[email protected] | 06024c6 | 2011-10-20 20:57:12 | [diff] [blame] | 259 | |
[email protected] | 5b3ee85 | 2013-09-26 06:33:10 | [diff] [blame] | 260 | // Unregister RenderViewHosts and clear background page data for an extension |
| 261 | // which has been unloaded. |
| 262 | void UnregisterExtension(const std::string& extension_id); |
| 263 | |
[email protected] | caffe70 | 2012-05-03 05:30:17 | [diff] [blame] | 264 | // Clears background page data for this extension. |
| 265 | void ClearBackgroundPageData(const std::string& extension_id); |
| 266 | |
[email protected] | a23f62e | 2013-04-26 13:13:02 | [diff] [blame] | 267 | void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); |
| 268 | |
[email protected] | 35e0e079 | 2012-11-30 02:35:48 | [diff] [blame] | 269 | // Contains all active extension-related RenderViewHost instances for all |
| 270 | // extensions. We also keep a cache of the host's view type, because that |
| 271 | // information is not accessible at registration/deregistration time. |
| 272 | ExtensionRenderViews all_extension_views_; |
| 273 | |
[email protected] | 103f19f | 2012-04-02 19:30:12 | [diff] [blame] | 274 | BackgroundPageDataMap background_page_data_; |
| 275 | |
[email protected] | aa3dd49 | 2013-11-05 17:09:09 | [diff] [blame] | 276 | // True if we have created the startup set of background hosts. |
| 277 | bool startup_background_hosts_created_; |
| 278 | |
[email protected] | 75e7bac | 2013-11-01 23:33:42 | [diff] [blame] | 279 | base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; |
| 280 | |
[email protected] | b6cd720 | 2014-01-07 17:46:55 | [diff] [blame] | 281 | ImpulseCallbackForTesting keepalive_impulse_callback_for_testing_; |
| 282 | ImpulseCallbackForTesting keepalive_impulse_decrement_callback_for_testing_; |
| 283 | |
[email protected] | 08d469b2 | 2014-03-31 00:51:24 | [diff] [blame] | 284 | ObserverList<ProcessManagerObserver> observer_list_; |
| 285 | |
[email protected] | 77a538f | 2014-07-14 22:25:37 | [diff] [blame] | 286 | // ID Counter used to set ProcessManager::BackgroundPageData close_sequence_id |
| 287 | // members. These IDs are tracked per extension in background_page_data_ and |
| 288 | // are used to verify that nothing has interrupted the process of closing a |
| 289 | // lazy background process. |
| 290 | // |
| 291 | // Any interruption obtains a new ID by incrementing |
| 292 | // last_background_close_sequence_id_ and storing it in background_page_data_ |
| 293 | // for a particular extension. Callbacks and round-trip IPC messages store the |
| 294 | // value of the extension's close_sequence_id at the beginning of the process. |
| 295 | // Thus comparisons can be done to halt when IDs no longer match. |
| 296 | // |
| 297 | // This counter provides unique IDs even when BackgroundPageData objects are |
| 298 | // reset. |
| 299 | uint64 last_background_close_sequence_id_; |
| 300 | |
| 301 | // Must be last member, see doc on WeakPtrFactory. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 302 | base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 303 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 304 | DISALLOW_COPY_AND_ASSIGN(ProcessManager); |
[email protected] | 481e1a4 | 2009-05-06 20:56:05 | [diff] [blame] | 305 | }; |
| 306 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 307 | } // namespace extensions |
| 308 | |
| 309 | #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ |