Chromium Code Reviews| 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..e65b906ac8ae3afd35251c2c496594c3c7685df5 100644 |
| --- a/content/browser/service_worker/service_worker_process_manager.h |
| +++ b/content/browser/service_worker/service_worker_process_manager.h |
| @@ -9,9 +9,11 @@ |
| #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; |
| @@ -21,33 +23,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 +66,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 |
|
Jeffrey Yasskin
2014/08/19 23:42:24
It's not clear what a "score" or "priority" is her
xiang
2014/08/29 07:49:40
Done.
|
| + // with lowest priority(0). |
| + void AddScopePendingProcesses(const GURL& scope, |
| + const std::vector<int>& pending_processes); |
|
kinuko
2014/08/12 15:27:07
This method and where we call it feels a bit sketc
Jeffrey Yasskin
2014/08/19 23:42:24
+1 to removing "pending" processes, if possible.
xiang
2014/08/29 07:49:40
Done.
|
| + 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 +101,12 @@ class CONTENT_EXPORT ServiceWorkerProcessManager { |
| int process_id; |
| }; |
| + typedef std::map<int, int> ProcessRefMap; |
|
Jeffrey Yasskin
2014/08/19 23:42:24
Always document what an "int" means.
xiang
2014/08/29 07:49:39
Done.
|
| + 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 +123,9 @@ class CONTENT_EXPORT ServiceWorkerProcessManager { |
| // EmbeddedWorkerInstances. |
| int process_id_for_test_; |
| + // Candidate process info for each scope, should be accessed on the UI thread. |
| + ScopeProcessRefMap scope_processes_; |
| + |
| // 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_; |