blob: 7528a5b72c87d8f5f0a900f75d837fb92519aa06 [file] [log] [blame]
Avi Drissman60039d42022-09-13 21:49:051// Copyright 2013 The Chromium Authors
[email protected]481e1a42009-05-06 20:56:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]98b6d942013-11-10 00:34:075#ifndef EXTENSIONS_BROWSER_PROCESS_MANAGER_H_
6#define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_
[email protected]481e1a42009-05-06 20:56:057
avic9cec102015-12-23 00:39:268#include <stdint.h>
9
[email protected]45776222009-07-15 20:21:5810#include <map>
[email protected]8a17bd52009-06-06 08:19:4911#include <set>
[email protected]45776222009-07-15 20:21:5812#include <string>
David Bertoni3e1e9fa2018-08-29 20:39:3013#include <utility>
Istiaque Ahmedb744ecf2019-02-06 00:23:3214#include <vector>
[email protected]481e1a42009-05-06 20:56:0515
[email protected]a23f62e2013-04-26 13:13:0216#include "base/callback.h"
[email protected]17902752011-08-31 22:52:5417#include "base/compiler_specific.h"
Keishi Hattori0e45c022021-11-27 09:25:5218#include "base/memory/raw_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1519#include "base/memory/ref_counted.h"
[email protected]99c49b52012-05-02 01:50:2020#include "base/memory/weak_ptr.h"
[email protected]08d469b22014-03-31 00:51:2421#include "base/observer_list.h"
Sigurdur Asgeirsson834f0572021-03-24 13:24:5822#include "base/scoped_multi_source_observation.h"
reillyg0ea3fa902014-10-28 15:30:2323#include "components/keyed_service/core/keyed_service.h"
dgozman47679eb12016-10-17 17:30:1824#include "content/public/browser/devtools_agent_host_observer.h"
Evan Stade922f3f1f2019-09-04 21:05:1325#include "content/public/browser/render_process_host.h"
Istiaque Ahmedd4b67ee2019-03-02 10:53:2026#include "content/public/browser/render_process_host_observer.h"
Istiaque Ahmedfbeff9fb2022-02-09 22:15:3427#include "content/public/browser/service_worker_external_request_timeout_type.h"
David Bertoni3e1e9fa2018-08-29 20:39:3028#include "extensions/browser/activity.h"
kmarshall24b29b22015-04-29 01:41:4729#include "extensions/browser/event_page_tracker.h"
Vasiliy Telezhnikov9980b402021-02-18 20:41:5430#include "extensions/browser/extension_host_observer.h"
limasdfe0f061b2015-02-27 00:35:0631#include "extensions/browser/extension_registry_observer.h"
Istiaque Ahmedb744ecf2019-02-06 00:23:3232#include "extensions/browser/service_worker/worker_id.h"
33#include "extensions/browser/service_worker/worker_id_set.h"
rdevlin.cronin0670b562016-07-02 02:05:4334#include "extensions/common/extension_id.h"
[email protected]481e1a42009-05-06 20:56:0535
[email protected]481e1a42009-05-06 20:56:0536class GURL;
[email protected]b6583592012-01-25 19:52:3337
38namespace content {
[email protected]7f474212013-11-05 04:26:1639class BrowserContext;
[email protected]a23f62e2013-04-26 13:13:0240class DevToolsAgentHost;
[email protected]9dfed872013-12-30 23:08:5641class RenderFrameHost;
[email protected]481e1a42009-05-06 20:56:0542class SiteInstance;
rdevlin.cronin6ae04a012015-04-03 20:19:4043class WebContents;
Nico Weber210c0bc2019-02-11 22:01:0944} // namespace content
[email protected]481e1a42009-05-06 20:56:0545
[email protected]1c321ee2012-05-21 03:02:3446namespace extensions {
[email protected]98b6d942013-11-10 00:34:0747
[email protected]1c321ee2012-05-21 03:02:3448class Extension;
[email protected]3a1dc572012-07-31 22:25:1349class ExtensionHost;
[email protected]6b54fda2014-07-22 02:13:4750class ExtensionRegistry;
[email protected]08d469b22014-03-31 00:51:2451class ProcessManagerObserver;
[email protected]1c321ee2012-05-21 03:02:3452
[email protected]bc535ee52010-08-31 18:40:3253// Manages dynamic state of running Chromium extensions. There is one instance
54// of this class per Profile. OTR Profiles have a separate instance that keeps
55// track of split-mode extensions only.
reillyg0ea3fa902014-10-28 15:30:2356class ProcessManager : public KeyedService,
kmarshall24b29b22015-04-29 01:41:4757 public ExtensionRegistryObserver,
dgozman47679eb12016-10-17 17:30:1858 public EventPageTracker,
Istiaque Ahmedd4b67ee2019-03-02 10:53:2059 public content::DevToolsAgentHostObserver,
Vasiliy Telezhnikov9980b402021-02-18 20:41:5460 public content::RenderProcessHostObserver,
61 public ExtensionHostObserver {
[email protected]481e1a42009-05-06 20:56:0562 public:
rdevlin.cronin6ae04a012015-04-03 20:19:4063 using ExtensionHostSet = std::set<extensions::ExtensionHost*>;
[email protected]d1fe1352012-04-26 00:47:3264
reillyg0ea3fa902014-10-28 15:30:2365 static ProcessManager* Get(content::BrowserContext* context);
Peter Boström951cf77e2021-09-22 00:02:5966
67 ProcessManager(const ProcessManager&) = delete;
68 ProcessManager& operator=(const ProcessManager&) = delete;
69
dcheng9168b2f2014-10-21 12:38:2470 ~ProcessManager() override;
[email protected]481e1a42009-05-06 20:56:0571
sense383ce0f2017-03-24 04:06:4372 // KeyedService support:
73 void Shutdown() override;
74
rdevlin.cronin6ae04a012015-04-03 20:19:4075 void RegisterRenderFrameHost(content::WebContents* web_contents,
76 content::RenderFrameHost* render_frame_host,
77 const Extension* extension);
78 void UnregisterRenderFrameHost(content::RenderFrameHost* render_frame_host);
[email protected]d1fe1352012-04-26 00:47:3279
Istiaque Ahmedb744ecf2019-02-06 00:23:3280 // Registers or unregisters a running worker state to this process manager.
81 // Note: This does not create any Service Workers.
Istiaque Ahmedb744ecf2019-02-06 00:23:3282 void RegisterServiceWorker(const WorkerId& worker_id);
83 void UnregisterServiceWorker(const WorkerId& worker_id);
84
rdevlin.cronin6ae04a012015-04-03 20:19:4085 // Returns the SiteInstance that the given URL belongs to.
Karandeep Bhatia48d90fdf2021-07-09 01:20:5186 // NOTE: Usage of this method is potentially error-prone. An extension can
87 // correspond to multiple SiteInstances (e.g. consider a cross origin isolated
88 // extension with non-cross-origin-isolated contexts).
rdevlin.cronin6ae04a012015-04-03 20:19:4089 // TODO(aa): This only returns correct results for extensions and packaged
90 // apps, not hosted apps.
91 virtual scoped_refptr<content::SiteInstance> GetSiteInstanceForURL(
92 const GURL& url);
[email protected]d1fe1352012-04-26 00:47:3293
rdevlin.cronin6ae04a012015-04-03 20:19:4094 using FrameSet = std::set<content::RenderFrameHost*>;
95 const FrameSet GetAllFrames() const;
96
97 // Returns all RenderFrameHosts that are registered for the specified
98 // extension.
99 ProcessManager::FrameSet GetRenderFrameHostsForExtension(
100 const std::string& extension_id);
101
robcdcc4b82015-12-06 12:39:45102 bool IsRenderFrameHostRegistered(content::RenderFrameHost* render_frame_host);
103
[email protected]08d469b22014-03-31 00:51:24104 void AddObserver(ProcessManagerObserver* observer);
105 void RemoveObserver(ProcessManagerObserver* observer);
106
[email protected]029ad372011-05-20 17:12:56107 // Creates a new UI-less extension instance. Like CreateViewHost, but not
[email protected]6ad9cdf72014-02-27 13:12:41108 // displayed anywhere. Returns false if no background host can be created,
109 // for example for hosted apps and extensions that aren't enabled in
110 // Incognito.
111 virtual bool CreateBackgroundHost(const Extension* extension,
112 const GURL& url);
[email protected]bc535ee52010-08-31 18:40:32113
rdevlin.cronin6ae04a012015-04-03 20:19:40114 // Creates background hosts if the embedder is ready and they are not already
115 // loaded.
116 void MaybeCreateStartupBackgroundHosts();
117
118 // Gets the ExtensionHost for the background page for an extension, or null if
[email protected]4814b512009-11-07 00:12:29119 // the extension isn't running or doesn't have a background page.
[email protected]98b6d942013-11-10 00:34:07120 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id);
[email protected]4814b512009-11-07 00:12:29121
Devlin Croninccf3b9d2022-06-30 02:16:16122 // Returns the background page ExtensionHost for the given
123 // |render_frame_host|, if |render_frame_host| is within the extension's
124 // background. Note that this will return the background page host for
125 // iframes embedded in the background page, even if they are not extension
126 // frames.
127 // TODO(https://crbug.com/1340001): Make these "gotchas" less subtle.
rdevlin.croninb48a98e2015-05-01 00:00:28128 ExtensionHost* GetExtensionHostForRenderFrameHost(
129 content::RenderFrameHost* render_frame_host);
130
[email protected]7042b682012-04-19 22:57:51131 // Returns true if the (lazy) background host for the given extension has
132 // already been sent the unload event and is shutting down.
133 bool IsBackgroundHostClosing(const std::string& extension_id);
134
Devlin Cronin7a282e32017-08-10 01:54:10135 // Returns the extension associated with the specified RenderFrameHost,
136 // or null.
rdevlin.cronin6ae04a012015-04-03 20:19:40137 const Extension* GetExtensionForRenderFrameHost(
138 content::RenderFrameHost* render_frame_host);
Devlin Cronin7a282e32017-08-10 01:54:10139
140 // Returns the extension associated with the main frame of the given
141 // |web_contents|, or null if there isn't one.
rdevlin.cronin6ae04a012015-04-03 20:19:40142 const Extension* GetExtensionForWebContents(
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41143 content::WebContents* web_contents);
rdevlin.cronin6ae04a012015-04-03 20:19:40144
[email protected]720ad1312012-02-27 23:07:36145 // Getter and setter for the lazy background page's keepalive count. This is
146 // the count of how many outstanding "things" are keeping the page alive.
147 // When this reaches 0, we will begin the process of shutting down the page.
148 // "Things" include pending events, resource loads, and API calls.
wez714dde12017-02-14 22:26:03149 // Returns -1 if |extension| does not have a lazy background page.
David Bertoni3e1e9fa2018-08-29 20:39:30150 // The calls to increment and decrement the count also accept a category
151 // of activity and an extra string of data. These are kept so there is
152 // more information for the counts. See the Activity struct definition
153 // for more details regarding the extra data.
[email protected]98b6d942013-11-10 00:34:07154 int GetLazyKeepaliveCount(const Extension* extension);
David Bertoni3e1e9fa2018-08-29 20:39:30155 void IncrementLazyKeepaliveCount(const Extension* extension,
156 Activity::Type activity_type,
157 const std::string& extra_data);
158 void DecrementLazyKeepaliveCount(const Extension* extension,
159 Activity::Type activity_type,
160 const std::string& extra_data);
161
Vasiliy Telezhnikov78b98d02021-03-16 14:26:28162 // Sends out notification to observers when the extension process is gone.
163 void NotifyExtensionProcessTerminated(const Extension* extension);
164
Istiaque Ahmedb744ecf2019-02-06 00:23:32165 // Methods to increment or decrement the ref-count of a specified service
166 // worker with id |worker_id|.
167 // The increment method returns the guid that needs to be passed to the
168 // decrement method.
Istiaque Ahmedfbeff9fb2022-02-09 22:15:34169 // |timeout_type| is the SW's timeout behavior.
Istiaque Ahmedb744ecf2019-02-06 00:23:32170 std::string IncrementServiceWorkerKeepaliveCount(
171 const WorkerId& worker_id,
Istiaque Ahmedfbeff9fb2022-02-09 22:15:34172 content::ServiceWorkerExternalRequestTimeoutType timeout_type,
Istiaque Ahmedb744ecf2019-02-06 00:23:32173 Activity::Type activity_type,
174 const std::string& extra_data);
175 // Decrements the ref-count of the specified worker with |worker_id| that
176 // had its ref-count incremented with |request_uuid|.
177 void DecrementServiceWorkerKeepaliveCount(const WorkerId& worker_id,
178 const std::string& request_uuid,
179 Activity::Type activity_type,
180 const std::string& extra_data);
181
David Bertoni3e1e9fa2018-08-29 20:39:30182 using ActivitiesMultisetPair = std::pair<Activity::Type, std::string>;
183 using ActivitiesMultiset = std::multiset<ActivitiesMultisetPair>;
184
185 // Return the current set of keep-alive activities for the extension.
186 ActivitiesMultiset GetLazyKeepaliveActivities(const Extension* extension);
[email protected]720ad1312012-02-27 23:07:36187
[email protected]584e6572013-02-16 07:02:33188 // Handles a response to the ShouldSuspend message, used for lazy background
[email protected]720ad1312012-02-27 23:07:36189 // pages.
avic9cec102015-12-23 00:39:26190 void OnShouldSuspendAck(const std::string& extension_id,
191 uint64_t sequence_id);
[email protected]103f19f2012-04-02 19:30:12192
[email protected]9dfed872013-12-30 23:08:56193 // Tracks network requests for a given RenderFrameHost, used to know
[email protected]6baff0b52012-03-06 01:30:18194 // when network activity is idle for lazy background pages.
Vasiliy Telezhnikov9980b402021-02-18 20:41:54195 void NetworkRequestStarted(content::RenderFrameHost* render_frame_host,
196 uint64_t request_id);
197 void NetworkRequestDone(content::RenderFrameHost* render_frame_host,
198 uint64_t request_id);
[email protected]6baff0b52012-03-06 01:30:18199
[email protected]0d475e072012-07-26 02:30:42200 // Prevents |extension|'s background page from being closed and sends the
201 // onSuspendCanceled() event to it.
[email protected]98b6d942013-11-10 00:34:07202 void CancelSuspend(const Extension* extension);
[email protected]0d475e072012-07-26 02:30:42203
[email protected]9602db42014-07-25 05:24:37204 // Called on shutdown to close our extension hosts.
205 void CloseBackgroundHosts();
206
kmarshall24b29b22015-04-29 01:41:47207 // EventPageTracker implementation.
208 bool IsEventPageSuspended(const std::string& extension_id) override;
209 bool WakeEventPage(const std::string& extension_id,
Istiaque Ahmed28edfd22018-08-30 23:40:47210 base::OnceCallback<void(bool)> callback) override;
kmarshall24b29b22015-04-29 01:41:47211
yoza9bf5602014-09-19 02:03:31212 // Sets the time in milliseconds that an extension event page can
213 // be idle before it is shut down; must be > 0.
214 static void SetEventPageIdleTimeForTesting(unsigned idle_time_msec);
215
216 // Sets the time in milliseconds that an extension event page has
217 // between being notified of its impending unload and that unload
218 // happening.
219 static void SetEventPageSuspendingTimeForTesting(
220 unsigned suspending_time_msec);
221
[email protected]6b54fda2014-07-22 02:13:47222 // Creates a non-incognito instance for tests. |registry| allows unit tests
223 // to inject an ExtensionRegistry that is not managed by the usual
224 // BrowserContextKeyedServiceFactory system.
225 static ProcessManager* CreateForTesting(content::BrowserContext* context,
226 ExtensionRegistry* registry);
227
228 // Creates an incognito-context instance for tests.
[email protected]b9f6ba32014-03-10 18:34:08229 static ProcessManager* CreateIncognitoForTesting(
230 content::BrowserContext* incognito_context,
231 content::BrowserContext* original_context,
[email protected]6b54fda2014-07-22 02:13:47232 ExtensionRegistry* registry);
233
rdevlin.cronin6ae04a012015-04-03 20:19:40234 content::BrowserContext* browser_context() const { return browser_context_; }
235
236 const ExtensionHostSet& background_hosts() const {
237 return background_hosts_;
238 }
239
Istiaque Ahmedb744ecf2019-02-06 00:23:32240 // Returns true if this ProcessManager has registered any worker with id
241 // |worker_id|.
242 bool HasServiceWorker(const WorkerId& worker_id) const;
243
Ghazale Hosseinabadib11bca622020-09-22 21:15:50244 // Returns all the Service Worker infos that is active for the extension with
245 // |extension_id|.
246 std::vector<WorkerId> GetServiceWorkersForExtension(
247 const ExtensionId& extension_id) const;
248
[email protected]6b54fda2014-07-22 02:13:47249 bool startup_background_hosts_created_for_test() const {
250 return startup_background_hosts_created_;
251 }
[email protected]b9f6ba32014-03-10 18:34:08252
Istiaque Ahmedd4b67ee2019-03-02 10:53:20253 std::vector<WorkerId> GetAllWorkersIdsForTesting();
254
[email protected]bc535ee52010-08-31 18:40:32255 protected:
reillyg0ea3fa902014-10-28 15:30:23256 static ProcessManager* Create(content::BrowserContext* context);
257
Reilly Grant58ea3832020-06-24 17:47:55258 // |context| is incognito pass the original context as |original_context|.
[email protected]6b54fda2014-07-22 02:13:47259 // Otherwise pass the same context for both. Pass the ExtensionRegistry for
260 // |context| as |registry|, or override it for testing.
[email protected]98b6d942013-11-10 00:34:07261 ProcessManager(content::BrowserContext* context,
[email protected]6b54fda2014-07-22 02:13:47262 content::BrowserContext* original_context,
263 ExtensionRegistry* registry);
[email protected]bc535ee52010-08-31 18:40:32264
rdevlin.cronin6ae04a012015-04-03 20:19:40265 // Not owned. Also used by IncognitoProcessManager.
Keishi Hattori0e45c022021-11-27 09:25:52266 raw_ptr<ExtensionRegistry> extension_registry_;
rdevlin.cronin6ae04a012015-04-03 20:19:40267
268 private:
269 friend class ProcessManagerFactory;
270 friend class ProcessManagerTest;
271
limasdfe0f061b2015-02-27 00:35:06272 // ExtensionRegistryObserver:
273 void OnExtensionLoaded(content::BrowserContext* browser_context,
274 const Extension* extension) override;
275 void OnExtensionUnloaded(content::BrowserContext* browser_context,
276 const Extension* extension,
limasdf0deef2042017-05-03 19:17:17277 UnloadedExtensionReason reason) override;
limasdfe0f061b2015-02-27 00:35:06278
Istiaque Ahmedd4b67ee2019-03-02 10:53:20279 // content::RenderProcessHostObserver:
280 void RenderProcessExited(
281 content::RenderProcessHost* host,
282 const content::ChildProcessTerminationInfo& info) override;
283
Vasiliy Telezhnikov9980b402021-02-18 20:41:54284 // ExtensionHostObserver:
285 void OnExtensionHostDestroyed(ExtensionHost* host) override;
Vasiliy Telezhnikov9980b402021-02-18 20:41:54286
[email protected]103f19f2012-04-02 19:30:12287 // Extra information we keep for each extension's background page.
288 struct BackgroundPageData;
rdevlin.cronin6ae04a012015-04-03 20:19:40289 struct ExtensionRenderFrameData;
290 using BackgroundPageDataMap = std::map<ExtensionId, BackgroundPageData>;
291 using ExtensionRenderFrames =
292 std::map<content::RenderFrameHost*, ExtensionRenderFrameData>;
[email protected]3e194992011-10-20 05:39:10293
[email protected]6b54fda2014-07-22 02:13:47294 // Load all background pages once the profile data is ready and the pages
295 // should be loaded.
296 void CreateStartupBackgroundHosts();
297
[email protected]94de8cb2013-11-07 06:29:21298 // Called just after |host| is created so it can be registered in our lists.
[email protected]98b6d942013-11-10 00:34:07299 void OnBackgroundHostCreated(ExtensionHost* host);
[email protected]94de8cb2013-11-07 06:29:21300
Devlin Cronin36eecdae02022-07-07 18:15:08301 // Handles a request from a created extension host to close the contents.
302 // This happens in cases such as the contents calling `window.close()`.
303 void HandleCloseExtensionHost(ExtensionHost* host);
304
[email protected]06024c62011-10-20 20:57:12305 // Close the given |host| iff it's a background page.
[email protected]98b6d942013-11-10 00:34:07306 void CloseBackgroundHost(ExtensionHost* host);
[email protected]06024c62011-10-20 20:57:12307
rdevlin.cronin6ae04a012015-04-03 20:19:40308 // If the frame isn't keeping the lazy background page alive, increments the
309 // keepalive count to do so.
310 void AcquireLazyKeepaliveCountForFrame(
311 content::RenderFrameHost* render_frame_host);
312
313 // If the frame is keeping the lazy background page alive, decrements the
314 // keepalive count to stop doing it.
315 void ReleaseLazyKeepaliveCountForFrame(
316 content::RenderFrameHost* render_frame_host);
317
[email protected]388770152013-12-03 01:25:32318 // Internal implementation of DecrementLazyKeepaliveCount with an
319 // |extension_id| known to have a lazy background page.
320 void DecrementLazyKeepaliveCount(const std::string& extension_id);
David Bertoni3e1e9fa2018-08-29 20:39:30321 void DecrementLazyKeepaliveCount(const std::string& extension_id,
322 Activity::Type activity_type,
323 const std::string& extra_data);
[email protected]388770152013-12-03 01:25:32324
[email protected]6baff0b52012-03-06 01:30:18325 // These are called when the extension transitions between idle and active.
326 // They control the process of closing the background page when idle.
[email protected]99c49b52012-05-02 01:50:20327 void OnLazyBackgroundPageIdle(const std::string& extension_id,
avic9cec102015-12-23 00:39:26328 uint64_t sequence_id);
[email protected]6baff0b52012-03-06 01:30:18329 void OnLazyBackgroundPageActive(const std::string& extension_id);
[email protected]0d475e072012-07-26 02:30:42330 void CloseLazyBackgroundPageNow(const std::string& extension_id,
avic9cec102015-12-23 00:39:26331 uint64_t sequence_id);
[email protected]6baff0b52012-03-06 01:30:18332
dgozman47679eb12016-10-17 17:30:18333 const Extension* GetExtensionForAgentHost(
334 content::DevToolsAgentHost* agent_host);
335
336 // content::DevToolsAgentHostObserver overrides.
337 void DevToolsAgentHostAttached(
338 content::DevToolsAgentHost* agent_host) override;
339 void DevToolsAgentHostDetached(
340 content::DevToolsAgentHost* agent_host) override;
[email protected]06024c62011-10-20 20:57:12341
rdevlin.cronin6ae04a012015-04-03 20:19:40342 // Unregister RenderFrameHosts and clear background page data for an extension
[email protected]5b3ee852013-09-26 06:33:10343 // which has been unloaded.
344 void UnregisterExtension(const std::string& extension_id);
345
[email protected]caffe702012-05-03 05:30:17346 // Clears background page data for this extension.
347 void ClearBackgroundPageData(const std::string& extension_id);
348
Gyuyoung Kimf271be42021-03-03 03:09:37349 // Handles a response to the SuspendExtension Mojo method, used for lazy
350 // background pages.
351 void OnSuspendAck(const std::string& extension_id);
352
rdevlin.cronin6ae04a012015-04-03 20:19:40353 // The set of ExtensionHosts running viewless background extensions.
354 ExtensionHostSet background_hosts_;
355
356 // A SiteInstance related to the SiteInstance for all extensions in
357 // this profile. We create it in such a way that a new
358 // browsing instance is created. This controls process grouping.
359 scoped_refptr<content::SiteInstance> site_instance_;
360
361 // The browser context associated with the |site_instance_|.
Keishi Hattori0e45c022021-11-27 09:25:52362 raw_ptr<content::BrowserContext> browser_context_;
rdevlin.cronin6ae04a012015-04-03 20:19:40363
364 // Contains all active extension-related RenderFrameHost instances for all
[email protected]35e0e0792012-11-30 02:35:48365 // extensions. We also keep a cache of the host's view type, because that
366 // information is not accessible at registration/deregistration time.
rdevlin.cronin6ae04a012015-04-03 20:19:40367 ExtensionRenderFrames all_extension_frames_;
[email protected]35e0e0792012-11-30 02:35:48368
Istiaque Ahmedb744ecf2019-02-06 00:23:32369 // TaskRunner for interacting with ServiceWorkerContexts.
Matt Falkenhagend55b9282019-09-10 23:53:35370 // TODO(crbug.com/824858): This is unused when ServiceWorkerOnUI is enabled.
Istiaque Ahmedb744ecf2019-02-06 00:23:32371 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
372
373 // Contains all active extension Service Worker information for all
374 // extensions.
375 WorkerIdSet all_extension_workers_;
376
[email protected]103f19f2012-04-02 19:30:12377 BackgroundPageDataMap background_page_data_;
378
[email protected]aa3dd492013-11-05 17:09:09379 // True if we have created the startup set of background hosts.
380 bool startup_background_hosts_created_;
381
Evan Stade22e3f9b2019-10-01 21:12:17382 base::ObserverList<ProcessManagerObserver> observer_list_;
[email protected]08d469b22014-03-31 00:51:24383
[email protected]77a538f2014-07-14 22:25:37384 // ID Counter used to set ProcessManager::BackgroundPageData close_sequence_id
385 // members. These IDs are tracked per extension in background_page_data_ and
386 // are used to verify that nothing has interrupted the process of closing a
387 // lazy background process.
388 //
389 // Any interruption obtains a new ID by incrementing
390 // last_background_close_sequence_id_ and storing it in background_page_data_
391 // for a particular extension. Callbacks and round-trip IPC messages store the
392 // value of the extension's close_sequence_id at the beginning of the process.
393 // Thus comparisons can be done to halt when IDs no longer match.
394 //
395 // This counter provides unique IDs even when BackgroundPageData objects are
396 // reset.
avic9cec102015-12-23 00:39:26397 uint64_t last_background_close_sequence_id_;
[email protected]77a538f2014-07-14 22:25:37398
rockote5703292015-09-28 23:23:09399 // Tracks pending network requests by opaque ID. This is used to ensure proper
400 // keepalive counting in response to request status updates; e.g., if an
401 // extension URLRequest is constructed and then destroyed without ever
402 // starting, we can receive a completion notification without a corresponding
403 // start notification. In that case we want to avoid decrementing keepalive.
naskod13fd292016-06-07 20:33:33404 std::map<int, ExtensionHost*> pending_network_requests_;
rockote5703292015-09-28 23:23:09405
Istiaque Ahmedd4b67ee2019-03-02 10:53:20406 // Observers of Service Worker RPH this ProcessManager manages.
Sigurdur Asgeirsson834f0572021-03-24 13:24:58407 base::ScopedMultiSourceObservation<content::RenderProcessHost,
408 content::RenderProcessHostObserver>
409 process_observations_{this};
Istiaque Ahmedd4b67ee2019-03-02 10:53:20410 // Maps render render_process_id -> extension_id for all Service Workers this
411 // ProcessManager manages.
412 std::map<int, std::set<ExtensionId>> worker_process_to_extension_ids_;
413
[email protected]77a538f2014-07-14 22:25:37414 // Must be last member, see doc on WeakPtrFactory.
Jeremy Roman9fc2de62019-07-12 14:15:03415 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_{this};
[email protected]481e1a42009-05-06 20:56:05416};
417
[email protected]98b6d942013-11-10 00:34:07418} // namespace extensions
419
420#endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_