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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) | 47 DCHECK(browser_context_ == NULL) |
48 << "Call Shutdown() before destroying |this|, so that racing method " | 48 << "Call Shutdown() before destroying |this|, so that racing method " |
49 << "invocations don't use a destroyed BrowserContext."; | 49 << "invocations don't use a destroyed BrowserContext."; |
50 } | 50 } |
51 | 51 |
52 void ServiceWorkerProcessManager::Shutdown() { | 52 void ServiceWorkerProcessManager::Shutdown() { |
53 browser_context_ = NULL; | 53 browser_context_ = NULL; |
| 54 for (std::map<int, ProcessInfo>::const_iterator it = instance_info_.begin(); |
| 55 it != instance_info_.end(); |
| 56 ++it) { |
| 57 RenderProcessHost* rph = RenderProcessHost::FromID(it->second.process_id); |
| 58 DCHECK(rph); |
| 59 static_cast<RenderProcessHostImpl*>(rph)->DecrementWorkerRefCount(); |
| 60 } |
| 61 instance_info_.clear(); |
54 } | 62 } |
55 | 63 |
56 void ServiceWorkerProcessManager::AllocateWorkerProcess( | 64 void ServiceWorkerProcessManager::AllocateWorkerProcess( |
57 int embedded_worker_id, | 65 int embedded_worker_id, |
58 const std::vector<int>& process_ids, | 66 const std::vector<int>& process_ids, |
59 const GURL& script_url, | 67 const GURL& script_url, |
60 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>& | 68 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>& |
61 callback) { | 69 callback) { |
62 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 70 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
63 BrowserThread::PostTask( | 71 BrowserThread::PostTask( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 base::Bind(&ServiceWorkerProcessManager::ReleaseWorkerProcess, | 148 base::Bind(&ServiceWorkerProcessManager::ReleaseWorkerProcess, |
141 weak_this_, | 149 weak_this_, |
142 embedded_worker_id)); | 150 embedded_worker_id)); |
143 return; | 151 return; |
144 } | 152 } |
145 if (process_id_for_test_ != -1) { | 153 if (process_id_for_test_ != -1) { |
146 // Unittests don't increment or decrement the worker refcount of a | 154 // Unittests don't increment or decrement the worker refcount of a |
147 // RenderProcessHost. | 155 // RenderProcessHost. |
148 return; | 156 return; |
149 } | 157 } |
| 158 if (browser_context_ == NULL) { |
| 159 // Shutdown already released all instances. |
| 160 DCHECK(instance_info_.empty()); |
| 161 return; |
| 162 } |
150 std::map<int, ProcessInfo>::iterator info = | 163 std::map<int, ProcessInfo>::iterator info = |
151 instance_info_.find(embedded_worker_id); | 164 instance_info_.find(embedded_worker_id); |
152 DCHECK(info != instance_info_.end()); | 165 DCHECK(info != instance_info_.end()); |
153 RenderProcessHost* rph = NULL; | 166 RenderProcessHost* rph = NULL; |
154 if (info->second.site_instance) { | 167 if (info->second.site_instance) { |
155 rph = info->second.site_instance->GetProcess(); | 168 rph = info->second.site_instance->GetProcess(); |
156 DCHECK_EQ(info->second.process_id, rph->GetID()) | 169 DCHECK_EQ(info->second.process_id, rph->GetID()) |
157 << "A SiteInstance's process shouldn't get destroyed while we're " | 170 << "A SiteInstance's process shouldn't get destroyed while we're " |
158 "holding a reference to it. Was the reference actually held?"; | 171 "holding a reference to it. Was the reference actually held?"; |
159 } else { | 172 } else { |
(...skipping 11 matching lines...) Expand all Loading... |
171 namespace base { | 184 namespace base { |
172 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the | 185 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the |
173 // member WeakPtr to safely guard the object's lifetime when used on that | 186 // member WeakPtr to safely guard the object's lifetime when used on that |
174 // thread. | 187 // thread. |
175 void DefaultDeleter<content::ServiceWorkerProcessManager>::operator()( | 188 void DefaultDeleter<content::ServiceWorkerProcessManager>::operator()( |
176 content::ServiceWorkerProcessManager* ptr) const { | 189 content::ServiceWorkerProcessManager* ptr) const { |
177 content::BrowserThread::DeleteSoon( | 190 content::BrowserThread::DeleteSoon( |
178 content::BrowserThread::UI, FROM_HERE, ptr); | 191 content::BrowserThread::UI, FROM_HERE, ptr); |
179 } | 192 } |
180 } // namespace base | 193 } // namespace base |
OLD | NEW |