| Index: trunk/src/content/browser/service_worker/service_worker_process_manager.h
|
| ===================================================================
|
| --- trunk/src/content/browser/service_worker/service_worker_process_manager.h (revision 272148)
|
| +++ trunk/src/content/browser/service_worker/service_worker_process_manager.h (working copy)
|
| @@ -5,7 +5,6 @@
|
| #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"
|
| @@ -19,7 +18,6 @@
|
|
|
| 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
|
| @@ -42,65 +40,37 @@
|
| // 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);
|
| + callback) const;
|
|
|
| - // 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);
|
| + // Drops a reference to a process that was running a Service Worker. This
|
| + // must match a call to AllocateWorkerProcess.
|
| + void ReleaseWorkerProcess(int process_id);
|
|
|
| - // 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;
|
| - }
|
| + // |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);
|
|
|
| private:
|
| - // Information about the process for an EmbeddedWorkerInstance.
|
| - struct ProcessInfo {
|
| - explicit ProcessInfo(const scoped_refptr<SiteInstance>& site_instance);
|
| - explicit ProcessInfo(int process_id);
|
| - ~ProcessInfo();
|
| + bool IncrementWorkerRefcountByPid(int process_id) const;
|
| + bool DecrementWorkerRefcountByPid(int process_id) const;
|
|
|
| - // 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_;
|
| - const base::WeakPtr<ServiceWorkerProcessManager> weak_this_;
|
| + base::WeakPtr<ServiceWorkerProcessManager> weak_this_;
|
| };
|
|
|
| } // namespace content
|
|
|