| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 186 } |
| 187 | 187 |
| 188 if (IsShutdown()) { | 188 if (IsShutdown()) { |
| 189 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 189 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 190 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT, | 190 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT, |
| 191 ChildProcessHost::kInvalidUniqueID, | 191 ChildProcessHost::kInvalidUniqueID, |
| 192 false /* is_new_process */, settings)); | 192 false /* is_new_process */, settings)); |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 | 195 |
| 196 // TODO(falken): Revert to DCHECK. Temporary check for debugging | 196 DCHECK(!base::ContainsKey(instance_info_, embedded_worker_id)) |
| 197 // crbug.com/639193 | |
| 198 CHECK(!base::ContainsKey(instance_info_, embedded_worker_id)) | |
| 199 << embedded_worker_id << " already has a process allocated"; | 197 << embedded_worker_id << " already has a process allocated"; |
| 200 | 198 |
| 201 if (can_use_existing_process) { | 199 if (can_use_existing_process) { |
| 202 int process_id = FindAvailableProcess(pattern); | 200 int process_id = FindAvailableProcess(pattern); |
| 203 if (process_id != ChildProcessHost::kInvalidUniqueID) { | 201 if (process_id != ChildProcessHost::kInvalidUniqueID) { |
| 204 RenderProcessHost::FromID(process_id)->IncrementServiceWorkerRefCount(); | 202 RenderProcessHost::FromID(process_id)->IncrementServiceWorkerRefCount(); |
| 205 instance_info_.insert( | 203 instance_info_.insert( |
| 206 std::make_pair(embedded_worker_id, ProcessInfo(process_id))); | 204 std::make_pair(embedded_worker_id, ProcessInfo(process_id))); |
| 207 BrowserThread::PostTask( | 205 BrowserThread::PostTask( |
| 208 BrowserThread::IO, FROM_HERE, | 206 BrowserThread::IO, FROM_HERE, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 249 } |
| 252 | 250 |
| 253 if (process_id_for_test_ != ChildProcessHost::kInvalidUniqueID) { | 251 if (process_id_for_test_ != ChildProcessHost::kInvalidUniqueID) { |
| 254 // Unittests don't increment or decrement the worker refcount of a | 252 // Unittests don't increment or decrement the worker refcount of a |
| 255 // RenderProcessHost. | 253 // RenderProcessHost. |
| 256 return; | 254 return; |
| 257 } | 255 } |
| 258 | 256 |
| 259 if (IsShutdown()) { | 257 if (IsShutdown()) { |
| 260 // Shutdown already released all instances. | 258 // Shutdown already released all instances. |
| 261 // TODO(falken): Revert to DCHECK. Temporary check for debugging | 259 DCHECK(instance_info_.empty()); |
| 262 // crbug.com/639193 | |
| 263 CHECK(instance_info_.empty()); | |
| 264 return; | 260 return; |
| 265 } | 261 } |
| 266 | 262 |
| 267 std::map<int, ProcessInfo>::iterator info = | 263 std::map<int, ProcessInfo>::iterator info = |
| 268 instance_info_.find(embedded_worker_id); | 264 instance_info_.find(embedded_worker_id); |
| 269 // ReleaseWorkerProcess could be called for a nonexistent worker id, for | 265 // ReleaseWorkerProcess could be called for a nonexistent worker id, for |
| 270 // example, when request to start a worker is aborted on the IO thread during | 266 // example, when request to start a worker is aborted on the IO thread during |
| 271 // process allocation that is failed on the UI thread. | 267 // process allocation that is failed on the UI thread. |
| 272 if (info == instance_info_.end()) | 268 if (info == instance_info_.end()) |
| 273 return; | 269 return; |
| 274 | 270 |
| 275 RenderProcessHost* rph = NULL; | 271 RenderProcessHost* rph = NULL; |
| 276 if (info->second.site_instance.get()) { | 272 if (info->second.site_instance.get()) { |
| 277 rph = info->second.site_instance->GetProcess(); | 273 rph = info->second.site_instance->GetProcess(); |
| 278 // TODO(falken): Revert to DCHECK. Temporary check for debugging | 274 DCHECK_EQ(info->second.process_id, rph->GetID()) |
| 279 // crbug.com/639193 | |
| 280 CHECK_EQ(info->second.process_id, rph->GetID()) | |
| 281 << "A SiteInstance's process shouldn't get destroyed while we're " | 275 << "A SiteInstance's process shouldn't get destroyed while we're " |
| 282 "holding a reference to it. Was the reference actually held?"; | 276 "holding a reference to it. Was the reference actually held?"; |
| 283 } else { | 277 } else { |
| 284 // TODO(falken): Revert to DCHECK. Temporary check for debugging | |
| 285 // crbug.com/639193 | |
| 286 rph = RenderProcessHost::FromID(info->second.process_id); | 278 rph = RenderProcessHost::FromID(info->second.process_id); |
| 287 CHECK(rph) | 279 DCHECK(rph) |
| 288 << "Process " << info->second.process_id | 280 << "Process " << info->second.process_id |
| 289 << " was destroyed unexpectedly. Did we actually hold a reference?"; | 281 << " was destroyed unexpectedly. Did we actually hold a reference?"; |
| 290 } | 282 } |
| 291 rph->DecrementServiceWorkerRefCount(); | 283 rph->DecrementServiceWorkerRefCount(); |
| 292 instance_info_.erase(info); | 284 instance_info_.erase(info); |
| 293 } | 285 } |
| 294 | 286 |
| 295 std::vector<int> ServiceWorkerProcessManager::SortProcessesForPattern( | 287 std::vector<int> ServiceWorkerProcessManager::SortProcessesForPattern( |
| 296 const GURL& pattern) const { | 288 const GURL& pattern) const { |
| 297 PatternProcessRefMap::const_iterator it = pattern_processes_.find(pattern); | 289 PatternProcessRefMap::const_iterator it = pattern_processes_.find(pattern); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 namespace std { | 334 namespace std { |
| 343 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the | 335 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the |
| 344 // member WeakPtr to safely guard the object's lifetime when used on that | 336 // member WeakPtr to safely guard the object's lifetime when used on that |
| 345 // thread. | 337 // thread. |
| 346 void default_delete<content::ServiceWorkerProcessManager>::operator()( | 338 void default_delete<content::ServiceWorkerProcessManager>::operator()( |
| 347 content::ServiceWorkerProcessManager* ptr) const { | 339 content::ServiceWorkerProcessManager* ptr) const { |
| 348 content::BrowserThread::DeleteSoon( | 340 content::BrowserThread::DeleteSoon( |
| 349 content::BrowserThread::UI, FROM_HERE, ptr); | 341 content::BrowserThread::UI, FROM_HERE, ptr); |
| 350 } | 342 } |
| 351 } // namespace std | 343 } // namespace std |
| OLD | NEW |