| Index: content/browser/service_worker/service_worker_process_manager.h
|
| diff --git a/content/browser/service_worker/service_worker_process_manager.h b/content/browser/service_worker/service_worker_process_manager.h
|
| index 51d8eefcd8703eb434899e1b30e779f17cbe17ad..ec6ba977441faa9a52014cb5cf738136e260334e 100644
|
| --- a/content/browser/service_worker/service_worker_process_manager.h
|
| +++ b/content/browser/service_worker/service_worker_process_manager.h
|
| @@ -5,6 +5,7 @@
|
| #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_
|
| #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_
|
|
|
| +#include <map>
|
| #include <vector>
|
|
|
| #include "base/callback.h"
|
| @@ -18,6 +19,7 @@ namespace content {
|
|
|
| class BrowserContext;
|
| class ServiceWorkerContextWrapper;
|
| +class SiteInstance;
|
|
|
| // Interacts with the UI thread to keep RenderProcessHosts alive while the
|
| // ServiceWorker system is using them. Each instance of
|
| @@ -40,37 +42,65 @@ class CONTENT_EXPORT ServiceWorkerProcessManager {
|
| // Allocation can fail with SERVICE_WORKER_ERROR_START_WORKER_FAILED if
|
| // RenderProcessHost::Init fails.
|
| void AllocateWorkerProcess(
|
| + int embedded_worker_id,
|
| const std::vector<int>& process_ids,
|
| const GURL& script_url,
|
| const base::Callback<void(ServiceWorkerStatusCode, int process_id)>&
|
| - callback) const;
|
| + callback);
|
|
|
| - // Drops a reference to a process that was running a Service Worker. This
|
| - // must match a call to AllocateWorkerProcess.
|
| - void ReleaseWorkerProcess(int process_id);
|
| + // Drops a reference to a process that was running a Service Worker, and its
|
| + // SiteInstance. This must match a call to AllocateWorkerProcess.
|
| + void ReleaseWorkerProcess(int embedded_worker_id);
|
|
|
| - // |increment_for_test| and |decrement_for_test| define how to look up a
|
| - // process by ID and increment or decrement its worker reference count. This
|
| - // must be called before any reference to this object escapes to another
|
| - // thread, and is considered part of construction.
|
| - void SetProcessRefcountOpsForTest(
|
| - const base::Callback<bool(int)>& increment_for_test,
|
| - const base::Callback<bool(int)>& decrement_for_test);
|
| + // Sets a single process ID that will be used for all embedded workers. This
|
| + // bypasses the work of creating a process and managing its worker refcount so
|
| + // that unittests can run without a BrowserContext. The test is in charge of
|
| + // making sure this is only called on the same thread as runs the UI message
|
| + // loop.
|
| + void SetProcessIdForTest(int process_id) {
|
| + process_id_for_test_ = process_id;
|
| + }
|
|
|
| private:
|
| - bool IncrementWorkerRefcountByPid(int process_id) const;
|
| - bool DecrementWorkerRefcountByPid(int process_id) const;
|
| + // Information about the process for an EmbeddedWorkerInstance.
|
| + struct ProcessInfo {
|
| + explicit ProcessInfo(const scoped_refptr<SiteInstance>& site_instance);
|
| + explicit ProcessInfo(int process_id);
|
| + ~ProcessInfo();
|
| +
|
| + // Stores the SiteInstance the Worker lives inside. This needs to outlive
|
| + // the instance's use of its RPH to uphold assumptions in the
|
| + // ContentBrowserClient interface.
|
| + scoped_refptr<SiteInstance> site_instance;
|
| +
|
| + // In case the process was allocated without using a SiteInstance, we need
|
| + // to store a process ID to decrement a worker reference on shutdown.
|
| + // TODO(jyasskin): Implement http://crbug.com/372045 or thread a frame_id in
|
| + // so all processes can be allocated with a SiteInstance.
|
| + int process_id;
|
| + };
|
|
|
| // These fields are only accessed on the UI thread after construction.
|
| // The reference cycle through context_wrapper_ is broken in
|
| // ServiceWorkerContextWrapper::Shutdown().
|
| scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
|
| - base::Callback<bool(int)> increment_for_test_;
|
| - base::Callback<bool(int)> decrement_for_test_;
|
| +
|
| + // Maps the ID of a running EmbeddedWorkerInstance to information about the
|
| + // process it's running inside. Since the Instances themselves live on the IO
|
| + // thread, this can be slightly out of date:
|
| + // * instance_info_ is populated while an Instance is STARTING and before
|
| + // it's RUNNING.
|
| + // * instance_info_ is depopulated in a message sent as the Instance becomes
|
| + // STOPPED.
|
| + std::map<int, ProcessInfo> instance_info_;
|
| +
|
| + // In unit tests, this will be returned as the process for all
|
| + // EmbeddedWorkerInstances.
|
| + int process_id_for_test_;
|
|
|
| // Used to double-check that we don't access *this after it's destroyed.
|
| base::WeakPtrFactory<ServiceWorkerProcessManager> weak_this_factory_;
|
| - base::WeakPtr<ServiceWorkerProcessManager> weak_this_;
|
| + const base::WeakPtr<ServiceWorkerProcessManager> weak_this_;
|
| };
|
|
|
| } // namespace content
|
|
|