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