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 #include "content/browser/service_worker/service_worker_process_manager.h" | 5 #include "content/browser/service_worker/service_worker_process_manager.h" |
6 | 6 |
7 #include "content/browser/renderer_host/render_process_host_impl.h" | 7 #include "content/browser/renderer_host/render_process_host_impl.h" |
8 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/site_instance.h" | 10 #include "content/public/browser/site_instance.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(int process_id) | 30 ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(int process_id) |
31 : process_id(process_id) { | 31 : process_id(process_id) { |
32 } | 32 } |
33 | 33 |
34 ServiceWorkerProcessManager::ProcessInfo::~ProcessInfo() { | 34 ServiceWorkerProcessManager::ProcessInfo::~ProcessInfo() { |
35 } | 35 } |
36 | 36 |
37 ServiceWorkerProcessManager::ServiceWorkerProcessManager( | 37 ServiceWorkerProcessManager::ServiceWorkerProcessManager( |
38 ServiceWorkerContextWrapper* context_wrapper) | 38 BrowserContext* browser_context) |
39 : context_wrapper_(context_wrapper), | 39 : browser_context_(browser_context), |
40 process_id_for_test_(-1), | 40 process_id_for_test_(-1), |
41 weak_this_factory_(this), | 41 weak_this_factory_(this), |
42 weak_this_(weak_this_factory_.GetWeakPtr()) { | 42 weak_this_(weak_this_factory_.GetWeakPtr()) { |
43 } | 43 } |
44 | 44 |
45 ServiceWorkerProcessManager::~ServiceWorkerProcessManager() { | 45 ServiceWorkerProcessManager::~ServiceWorkerProcessManager() { |
46 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 47 DCHECK(browser_context_ == NULL) |
| 48 << "Call Shutdown() before destroying |this|, so that racing method " |
| 49 << "invocations don't use a destroyed BrowserContext."; |
| 50 } |
| 51 |
| 52 void ServiceWorkerProcessManager::Shutdown() { |
| 53 browser_context_ = NULL; |
47 } | 54 } |
48 | 55 |
49 void ServiceWorkerProcessManager::AllocateWorkerProcess( | 56 void ServiceWorkerProcessManager::AllocateWorkerProcess( |
50 int embedded_worker_id, | 57 int embedded_worker_id, |
51 const std::vector<int>& process_ids, | 58 const std::vector<int>& process_ids, |
52 const GURL& script_url, | 59 const GURL& script_url, |
53 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>& | 60 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>& |
54 callback) { | 61 callback) { |
55 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 62 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
56 BrowserThread::PostTask( | 63 BrowserThread::PostTask( |
(...skipping 27 matching lines...) Expand all Loading... |
84 if (IncrementWorkerRefCountByPid(*it)) { | 91 if (IncrementWorkerRefCountByPid(*it)) { |
85 instance_info_.insert( | 92 instance_info_.insert( |
86 std::make_pair(embedded_worker_id, ProcessInfo(*it))); | 93 std::make_pair(embedded_worker_id, ProcessInfo(*it))); |
87 BrowserThread::PostTask(BrowserThread::IO, | 94 BrowserThread::PostTask(BrowserThread::IO, |
88 FROM_HERE, | 95 FROM_HERE, |
89 base::Bind(callback, SERVICE_WORKER_OK, *it)); | 96 base::Bind(callback, SERVICE_WORKER_OK, *it)); |
90 return; | 97 return; |
91 } | 98 } |
92 } | 99 } |
93 | 100 |
94 if (!context_wrapper_->browser_context_) { | 101 if (!browser_context_) { |
95 // Shutdown has started. | 102 // Shutdown has started. |
96 BrowserThread::PostTask( | 103 BrowserThread::PostTask( |
97 BrowserThread::IO, | 104 BrowserThread::IO, |
98 FROM_HERE, | 105 FROM_HERE, |
99 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); | 106 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); |
100 return; | 107 return; |
101 } | 108 } |
102 // No existing processes available; start a new one. | 109 // No existing processes available; start a new one. |
103 scoped_refptr<SiteInstance> site_instance = SiteInstance::CreateForURL( | 110 scoped_refptr<SiteInstance> site_instance = |
104 context_wrapper_->browser_context_, script_url); | 111 SiteInstance::CreateForURL(browser_context_, script_url); |
105 RenderProcessHost* rph = site_instance->GetProcess(); | 112 RenderProcessHost* rph = site_instance->GetProcess(); |
106 // This Init() call posts a task to the IO thread that adds the RPH's | 113 // This Init() call posts a task to the IO thread that adds the RPH's |
107 // ServiceWorkerDispatcherHost to the | 114 // ServiceWorkerDispatcherHost to the |
108 // EmbeddedWorkerRegistry::process_sender_map_. | 115 // EmbeddedWorkerRegistry::process_sender_map_. |
109 if (!rph->Init()) { | 116 if (!rph->Init()) { |
110 LOG(ERROR) << "Couldn't start a new process!"; | 117 LOG(ERROR) << "Couldn't start a new process!"; |
111 BrowserThread::PostTask( | 118 BrowserThread::PostTask( |
112 BrowserThread::IO, | 119 BrowserThread::IO, |
113 FROM_HERE, | 120 FROM_HERE, |
114 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); | 121 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 namespace base { | 171 namespace base { |
165 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the | 172 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the |
166 // member WeakPtr to safely guard the object's lifetime when used on that | 173 // member WeakPtr to safely guard the object's lifetime when used on that |
167 // thread. | 174 // thread. |
168 void DefaultDeleter<content::ServiceWorkerProcessManager>::operator()( | 175 void DefaultDeleter<content::ServiceWorkerProcessManager>::operator()( |
169 content::ServiceWorkerProcessManager* ptr) const { | 176 content::ServiceWorkerProcessManager* ptr) const { |
170 content::BrowserThread::DeleteSoon( | 177 content::BrowserThread::DeleteSoon( |
171 content::BrowserThread::UI, FROM_HERE, ptr); | 178 content::BrowserThread::UI, FROM_HERE, ptr); |
172 } | 179 } |
173 } // namespace base | 180 } // namespace base |
OLD | NEW |