Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/common/service_worker/service_worker_status_code.h" | 14 #include "content/common/service_worker/service_worker_status_code.h" |
| 15 | 15 |
| 16 class GURL; | 16 class GURL; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 class BrowserContext; | 20 class BrowserContext; |
| 21 class ServiceWorkerContextWrapper; | |
| 22 class SiteInstance; | 21 class SiteInstance; |
| 23 | 22 |
| 24 // Interacts with the UI thread to keep RenderProcessHosts alive while the | 23 // Interacts with the UI thread to keep RenderProcessHosts alive while the |
| 25 // ServiceWorker system is using them. Each instance of | 24 // ServiceWorker system is using them. Each instance of |
| 26 // ServiceWorkerProcessManager is destroyed on the UI thread shortly after its | 25 // ServiceWorkerProcessManager is destroyed on the UI thread shortly after its |
|
michaeln
2014/05/22 01:43:42
stale comment, 'shortly after' s/b 'when the'
Jeffrey Yasskin
2014/05/22 02:47:54
Unfortunately, it's not stale. The SWContextWrappe
| |
| 27 // ServiceWorkerContextCore is destroyed on the IO thread. | 26 // ServiceWorkerContextWrapper is destroyed. |
| 28 class CONTENT_EXPORT ServiceWorkerProcessManager { | 27 class CONTENT_EXPORT ServiceWorkerProcessManager { |
| 29 public: | 28 public: |
| 30 // |*this| must be owned by |context_wrapper|->context(). | 29 // |*this| must be owned by a ServiceWorkerContextWrapper in a |
| 31 explicit ServiceWorkerProcessManager( | 30 // StoragePartition within |browser_context|. |
| 32 ServiceWorkerContextWrapper* context_wrapper); | 31 explicit ServiceWorkerProcessManager(BrowserContext* browser_context); |
| 33 | 32 |
| 33 // Shutdown must be called before the ProcessManager is destroyed. | |
| 34 ~ServiceWorkerProcessManager(); | 34 ~ServiceWorkerProcessManager(); |
| 35 | 35 |
| 36 // Synchronously prevents new processes from being allocated. | |
| 37 // TODO(jyasskin): Drop references to RenderProcessHosts too. | |
| 38 void Shutdown(); | |
| 39 | |
| 36 // Returns a reference to a running process suitable for starting the Service | 40 // Returns a reference to a running process suitable for starting the Service |
| 37 // Worker at |script_url|. Processes in |process_ids| will be checked in order | 41 // Worker at |script_url|. Processes in |process_ids| will be checked in order |
| 38 // for existence, and if none exist, then a new process will be created. Posts | 42 // for existence, and if none exist, then a new process will be created. Posts |
| 39 // |callback| to the IO thread to indicate whether creation succeeded and the | 43 // |callback| to the IO thread to indicate whether creation succeeded and the |
| 40 // process ID that has a new reference. | 44 // process ID that has a new reference. |
| 41 // | 45 // |
| 42 // Allocation can fail with SERVICE_WORKER_ERROR_START_WORKER_FAILED if | 46 // Allocation can fail with SERVICE_WORKER_ERROR_START_WORKER_FAILED if |
| 43 // RenderProcessHost::Init fails. | 47 // RenderProcessHost::Init fails. |
| 44 void AllocateWorkerProcess( | 48 void AllocateWorkerProcess( |
| 45 int embedded_worker_id, | 49 int embedded_worker_id, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 73 // ContentBrowserClient interface. | 77 // ContentBrowserClient interface. |
| 74 scoped_refptr<SiteInstance> site_instance; | 78 scoped_refptr<SiteInstance> site_instance; |
| 75 | 79 |
| 76 // In case the process was allocated without using a SiteInstance, we need | 80 // In case the process was allocated without using a SiteInstance, we need |
| 77 // to store a process ID to decrement a worker reference on shutdown. | 81 // to store a process ID to decrement a worker reference on shutdown. |
| 78 // TODO(jyasskin): Implement http://crbug.com/372045 or thread a frame_id in | 82 // TODO(jyasskin): Implement http://crbug.com/372045 or thread a frame_id in |
| 79 // so all processes can be allocated with a SiteInstance. | 83 // so all processes can be allocated with a SiteInstance. |
| 80 int process_id; | 84 int process_id; |
| 81 }; | 85 }; |
| 82 | 86 |
| 83 // These fields are only accessed on the UI thread after construction. | 87 // These fields are only accessed on the UI thread. |
| 84 // The reference cycle through context_wrapper_ is broken in | 88 BrowserContext* browser_context_; |
| 85 // ServiceWorkerContextWrapper::Shutdown(). | |
| 86 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_; | |
| 87 | 89 |
| 88 // Maps the ID of a running EmbeddedWorkerInstance to information about the | 90 // Maps the ID of a running EmbeddedWorkerInstance to information about the |
| 89 // process it's running inside. Since the Instances themselves live on the IO | 91 // process it's running inside. Since the Instances themselves live on the IO |
| 90 // thread, this can be slightly out of date: | 92 // thread, this can be slightly out of date: |
| 91 // * instance_info_ is populated while an Instance is STARTING and before | 93 // * instance_info_ is populated while an Instance is STARTING and before |
| 92 // it's RUNNING. | 94 // it's RUNNING. |
| 93 // * instance_info_ is depopulated in a message sent as the Instance becomes | 95 // * instance_info_ is depopulated in a message sent as the Instance becomes |
| 94 // STOPPED. | 96 // STOPPED. |
| 95 std::map<int, ProcessInfo> instance_info_; | 97 std::map<int, ProcessInfo> instance_info_; |
| 96 | 98 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 107 | 109 |
| 108 namespace base { | 110 namespace base { |
| 109 // Specialized to post the deletion to the UI thread. | 111 // Specialized to post the deletion to the UI thread. |
| 110 template <> | 112 template <> |
| 111 struct CONTENT_EXPORT DefaultDeleter<content::ServiceWorkerProcessManager> { | 113 struct CONTENT_EXPORT DefaultDeleter<content::ServiceWorkerProcessManager> { |
| 112 void operator()(content::ServiceWorkerProcessManager* ptr) const; | 114 void operator()(content::ServiceWorkerProcessManager* ptr) const; |
| 113 }; | 115 }; |
| 114 } // namespace base | 116 } // namespace base |
| 115 | 117 |
| 116 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ | 118 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ |
| OLD | NEW |