| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 ServiceWorkerProcessManager::~ServiceWorkerProcessManager() { | 62 ServiceWorkerProcessManager::~ServiceWorkerProcessManager() { |
| 63 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 63 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 64 DCHECK(IsShutdown()) | 64 DCHECK(IsShutdown()) |
| 65 << "Call Shutdown() before destroying |this|, so that racing method " | 65 << "Call Shutdown() before destroying |this|, so that racing method " |
| 66 << "invocations don't use a destroyed BrowserContext."; | 66 << "invocations don't use a destroyed BrowserContext."; |
| 67 DCHECK(instance_info_.empty()); | 67 DCHECK(instance_info_.empty()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ServiceWorkerProcessManager::Shutdown() { | 70 void ServiceWorkerProcessManager::Shutdown() { |
| 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 72 browser_context_ = NULL; | 72 { |
| 73 base::AutoLock lock(browser_context_lock_); |
| 74 browser_context_ = nullptr; |
| 75 } |
| 76 |
| 73 for (std::map<int, ProcessInfo>::const_iterator it = instance_info_.begin(); | 77 for (std::map<int, ProcessInfo>::const_iterator it = instance_info_.begin(); |
| 74 it != instance_info_.end(); | 78 it != instance_info_.end(); |
| 75 ++it) { | 79 ++it) { |
| 76 RenderProcessHost::FromID(it->second.process_id)->DecrementWorkerRefCount(); | 80 RenderProcessHost::FromID(it->second.process_id)->DecrementWorkerRefCount(); |
| 77 } | 81 } |
| 78 instance_info_.clear(); | 82 instance_info_.clear(); |
| 79 } | 83 } |
| 80 | 84 |
| 85 bool ServiceWorkerProcessManager::IsShutdown() { |
| 86 base::AutoLock lock(browser_context_lock_); |
| 87 return !browser_context_; |
| 88 } |
| 89 |
| 81 void ServiceWorkerProcessManager::AddProcessReferenceToPattern( | 90 void ServiceWorkerProcessManager::AddProcessReferenceToPattern( |
| 82 const GURL& pattern, int process_id) { | 91 const GURL& pattern, int process_id) { |
| 83 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 92 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 84 BrowserThread::PostTask( | 93 BrowserThread::PostTask( |
| 85 BrowserThread::UI, | 94 BrowserThread::UI, |
| 86 FROM_HERE, | 95 FROM_HERE, |
| 87 base::Bind(&ServiceWorkerProcessManager::AddProcessReferenceToPattern, | 96 base::Bind(&ServiceWorkerProcessManager::AddProcessReferenceToPattern, |
| 88 weak_this_, | 97 weak_this_, |
| 89 pattern, | 98 pattern, |
| 90 process_id)); | 99 process_id)); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 namespace std { | 332 namespace std { |
| 324 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the | 333 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the |
| 325 // member WeakPtr to safely guard the object's lifetime when used on that | 334 // member WeakPtr to safely guard the object's lifetime when used on that |
| 326 // thread. | 335 // thread. |
| 327 void default_delete<content::ServiceWorkerProcessManager>::operator()( | 336 void default_delete<content::ServiceWorkerProcessManager>::operator()( |
| 328 content::ServiceWorkerProcessManager* ptr) const { | 337 content::ServiceWorkerProcessManager* ptr) const { |
| 329 content::BrowserThread::DeleteSoon( | 338 content::BrowserThread::DeleteSoon( |
| 330 content::BrowserThread::UI, FROM_HERE, ptr); | 339 content::BrowserThread::UI, FROM_HERE, ptr); |
| 331 } | 340 } |
| 332 } // namespace std | 341 } // namespace std |
| OLD | NEW |