| 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 85fbcc1c050192f60a43f3b6b7c2ce738aef29b1..7e6a43db78b52c63e9434f74fa5d79d1842885b3 100644
|
| --- a/content/browser/service_worker/service_worker_process_manager.h
|
| +++ b/content/browser/service_worker/service_worker_process_manager.h
|
| @@ -9,10 +9,13 @@
|
| #include <vector>
|
|
|
| #include "base/callback.h"
|
| +#include "base/gtest_prod_util.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "content/common/service_worker/service_worker_status_code.h"
|
|
|
| +#include "content/public/browser/render_process_host_observer.h"
|
| +
|
| class GURL;
|
|
|
| namespace content {
|
| @@ -21,33 +24,32 @@ class BrowserContext;
|
| class SiteInstance;
|
|
|
| // Interacts with the UI thread to keep RenderProcessHosts alive while the
|
| -// ServiceWorker system is using them. Each instance of
|
| -// ServiceWorkerProcessManager is destroyed on the UI thread shortly after its
|
| -// ServiceWorkerContextWrapper is destroyed.
|
| -class CONTENT_EXPORT ServiceWorkerProcessManager {
|
| +// ServiceWorker system is using them. It also tracks candidate processes
|
| +// for each scope. Each instance of ServiceWorkerProcessManager is destroyed
|
| +// on the UI thread shortly after its ServiceWorkerContextWrapper is destroyed.
|
| +class CONTENT_EXPORT ServiceWorkerProcessManager
|
| + : public RenderProcessHostObserver {
|
| public:
|
| // |*this| must be owned by a ServiceWorkerContextWrapper in a
|
| // StoragePartition within |browser_context|.
|
| explicit ServiceWorkerProcessManager(BrowserContext* browser_context);
|
|
|
| // Shutdown must be called before the ProcessManager is destroyed.
|
| - ~ServiceWorkerProcessManager();
|
| + virtual ~ServiceWorkerProcessManager();
|
|
|
| // Synchronously prevents new processes from being allocated.
|
| // TODO(jyasskin): Drop references to RenderProcessHosts too.
|
| void Shutdown();
|
|
|
| // Returns a reference to a running process suitable for starting the Service
|
| - // Worker at |script_url|. Processes in |process_ids| will be checked in order
|
| - // for existence, and if none exist, then a new process will be created. Posts
|
| - // |callback| to the IO thread to indicate whether creation succeeded and the
|
| - // process ID that has a new reference.
|
| + // Worker at |script_url|. Posts |callback| to the IO thread to indicate
|
| + // whether creation succeeded and the process ID that has a new reference.
|
| //
|
| // 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& scope,
|
| const GURL& script_url,
|
| const base::Callback<void(ServiceWorkerStatusCode, int process_id)>&
|
| callback);
|
| @@ -65,7 +67,23 @@ class CONTENT_EXPORT ServiceWorkerProcessManager {
|
| process_id_for_test_ = process_id;
|
| }
|
|
|
| + // Adds/removes process reference for the |scope|, the process with highest
|
| + // score will be chosen to start worker. The pending processes will be added
|
| + // with lowest priority(0).
|
| + void AddScopePendingProcesses(const GURL& scope,
|
| + const std::vector<int>& pending_processes);
|
| + void AddScopeProcessReference(const GURL& scope, int process_id);
|
| + void RemoveScopeProcessReference(const GURL& scope, int process_id);
|
| +
|
| + // Returns true if the |scope| has at least one process to run.
|
| + bool ScopeHasProcessToRun(const GURL& scope) const;
|
| +
|
| + // RenderProcessHostObserver overrides:
|
| + virtual void RenderProcessHostDestroyed(RenderProcessHost* host) OVERRIDE;
|
| +
|
| private:
|
| + FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest, SortProcess);
|
| +
|
| // Information about the process for an EmbeddedWorkerInstance.
|
| struct ProcessInfo {
|
| explicit ProcessInfo(const scoped_refptr<SiteInstance>& site_instance);
|
| @@ -84,6 +102,12 @@ class CONTENT_EXPORT ServiceWorkerProcessManager {
|
| int process_id;
|
| };
|
|
|
| + typedef std::map<int, int> ProcessRefMap;
|
| + typedef std::map<const GURL, ProcessRefMap> ScopeProcessRefMap;
|
| +
|
| + // Returns a process vector sorted by the reference count for the |scope|.
|
| + std::vector<int> SortProcessesForScope(const GURL& scope) const;
|
| +
|
| // These fields are only accessed on the UI thread.
|
| BrowserContext* browser_context_;
|
|
|
| @@ -100,6 +124,9 @@ class CONTENT_EXPORT ServiceWorkerProcessManager {
|
| // EmbeddedWorkerInstances.
|
| int process_id_for_test_;
|
|
|
| + ScopeProcessRefMap scope_processes_;
|
| + void DumpProcessReferences();
|
| +
|
| // 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_;
|
|
|