| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 void ServiceWorkerProcessManager::Shutdown() { | 73 void ServiceWorkerProcessManager::Shutdown() { |
| 74 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 74 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 75 { | 75 { |
| 76 base::AutoLock lock(browser_context_lock_); | 76 base::AutoLock lock(browser_context_lock_); |
| 77 browser_context_ = nullptr; | 77 browser_context_ = nullptr; |
| 78 } | 78 } |
| 79 | 79 |
| 80 for (std::map<int, ProcessInfo>::const_iterator it = instance_info_.begin(); | 80 for (std::map<int, ProcessInfo>::const_iterator it = instance_info_.begin(); |
| 81 it != instance_info_.end(); | 81 it != instance_info_.end(); |
| 82 ++it) { | 82 ++it) { |
| 83 RenderProcessHost::FromID(it->second.process_id)->DecrementWorkerRefCount(); | 83 RenderProcessHost::FromID(it->second.process_id) |
| 84 ->DecrementServiceWorkerRefCount(); |
| 84 } | 85 } |
| 85 instance_info_.clear(); | 86 instance_info_.clear(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool ServiceWorkerProcessManager::IsShutdown() { | 89 bool ServiceWorkerProcessManager::IsShutdown() { |
| 89 base::AutoLock lock(browser_context_lock_); | 90 base::AutoLock lock(browser_context_lock_); |
| 90 return !browser_context_; | 91 return !browser_context_; |
| 91 } | 92 } |
| 92 | 93 |
| 93 void ServiceWorkerProcessManager::AddProcessReferenceToPattern( | 94 void ServiceWorkerProcessManager::AddProcessReferenceToPattern( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 false /* is_new_process */, settings)); | 192 false /* is_new_process */, settings)); |
| 192 return; | 193 return; |
| 193 } | 194 } |
| 194 | 195 |
| 195 DCHECK(!base::ContainsKey(instance_info_, embedded_worker_id)) | 196 DCHECK(!base::ContainsKey(instance_info_, embedded_worker_id)) |
| 196 << embedded_worker_id << " already has a process allocated"; | 197 << embedded_worker_id << " already has a process allocated"; |
| 197 | 198 |
| 198 if (can_use_existing_process) { | 199 if (can_use_existing_process) { |
| 199 int process_id = FindAvailableProcess(pattern); | 200 int process_id = FindAvailableProcess(pattern); |
| 200 if (process_id != ChildProcessHost::kInvalidUniqueID) { | 201 if (process_id != ChildProcessHost::kInvalidUniqueID) { |
| 201 RenderProcessHost::FromID(process_id)->IncrementWorkerRefCount(); | 202 RenderProcessHost::FromID(process_id)->IncrementServiceWorkerRefCount(); |
| 202 instance_info_.insert( | 203 instance_info_.insert( |
| 203 std::make_pair(embedded_worker_id, ProcessInfo(process_id))); | 204 std::make_pair(embedded_worker_id, ProcessInfo(process_id))); |
| 204 BrowserThread::PostTask( | 205 BrowserThread::PostTask( |
| 205 BrowserThread::IO, FROM_HERE, | 206 BrowserThread::IO, FROM_HERE, |
| 206 base::Bind(callback, SERVICE_WORKER_OK, process_id, | 207 base::Bind(callback, SERVICE_WORKER_OK, process_id, |
| 207 false /* is_new_process */, settings)); | 208 false /* is_new_process */, settings)); |
| 208 return; | 209 return; |
| 209 } | 210 } |
| 210 } | 211 } |
| 211 | 212 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 223 BrowserThread::IO, FROM_HERE, | 224 BrowserThread::IO, FROM_HERE, |
| 224 base::Bind(callback, SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND, | 225 base::Bind(callback, SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND, |
| 225 ChildProcessHost::kInvalidUniqueID, | 226 ChildProcessHost::kInvalidUniqueID, |
| 226 false /* is_new_process */, settings)); | 227 false /* is_new_process */, settings)); |
| 227 return; | 228 return; |
| 228 } | 229 } |
| 229 | 230 |
| 230 instance_info_.insert( | 231 instance_info_.insert( |
| 231 std::make_pair(embedded_worker_id, ProcessInfo(site_instance))); | 232 std::make_pair(embedded_worker_id, ProcessInfo(site_instance))); |
| 232 | 233 |
| 233 rph->IncrementWorkerRefCount(); | 234 rph->IncrementServiceWorkerRefCount(); |
| 234 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 235 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 235 base::Bind(callback, SERVICE_WORKER_OK, rph->GetID(), | 236 base::Bind(callback, SERVICE_WORKER_OK, rph->GetID(), |
| 236 true /* is_new_process */, settings)); | 237 true /* is_new_process */, settings)); |
| 237 } | 238 } |
| 238 | 239 |
| 239 void ServiceWorkerProcessManager::ReleaseWorkerProcess(int embedded_worker_id) { | 240 void ServiceWorkerProcessManager::ReleaseWorkerProcess(int embedded_worker_id) { |
| 240 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 241 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 241 BrowserThread::PostTask( | 242 BrowserThread::PostTask( |
| 242 BrowserThread::UI, | 243 BrowserThread::UI, |
| 243 FROM_HERE, | 244 FROM_HERE, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 272 rph = info->second.site_instance->GetProcess(); | 273 rph = info->second.site_instance->GetProcess(); |
| 273 DCHECK_EQ(info->second.process_id, rph->GetID()) | 274 DCHECK_EQ(info->second.process_id, rph->GetID()) |
| 274 << "A SiteInstance's process shouldn't get destroyed while we're " | 275 << "A SiteInstance's process shouldn't get destroyed while we're " |
| 275 "holding a reference to it. Was the reference actually held?"; | 276 "holding a reference to it. Was the reference actually held?"; |
| 276 } else { | 277 } else { |
| 277 rph = RenderProcessHost::FromID(info->second.process_id); | 278 rph = RenderProcessHost::FromID(info->second.process_id); |
| 278 DCHECK(rph) | 279 DCHECK(rph) |
| 279 << "Process " << info->second.process_id | 280 << "Process " << info->second.process_id |
| 280 << " was destroyed unexpectedly. Did we actually hold a reference?"; | 281 << " was destroyed unexpectedly. Did we actually hold a reference?"; |
| 281 } | 282 } |
| 282 rph->DecrementWorkerRefCount(); | 283 rph->DecrementServiceWorkerRefCount(); |
| 283 instance_info_.erase(info); | 284 instance_info_.erase(info); |
| 284 } | 285 } |
| 285 | 286 |
| 286 std::vector<int> ServiceWorkerProcessManager::SortProcessesForPattern( | 287 std::vector<int> ServiceWorkerProcessManager::SortProcessesForPattern( |
| 287 const GURL& pattern) const { | 288 const GURL& pattern) const { |
| 288 PatternProcessRefMap::const_iterator it = pattern_processes_.find(pattern); | 289 PatternProcessRefMap::const_iterator it = pattern_processes_.find(pattern); |
| 289 if (it == pattern_processes_.end()) | 290 if (it == pattern_processes_.end()) |
| 290 return std::vector<int>(); | 291 return std::vector<int>(); |
| 291 | 292 |
| 292 // Prioritize higher refcount processes to choose the process which has more | 293 // Prioritize higher refcount processes to choose the process which has more |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 namespace std { | 334 namespace std { |
| 334 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the | 335 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the |
| 335 // 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 |
| 336 // thread. | 337 // thread. |
| 337 void default_delete<content::ServiceWorkerProcessManager>::operator()( | 338 void default_delete<content::ServiceWorkerProcessManager>::operator()( |
| 338 content::ServiceWorkerProcessManager* ptr) const { | 339 content::ServiceWorkerProcessManager* ptr) const { |
| 339 content::BrowserThread::DeleteSoon( | 340 content::BrowserThread::DeleteSoon( |
| 340 content::BrowserThread::UI, FROM_HERE, ptr); | 341 content::BrowserThread::UI, FROM_HERE, ptr); |
| 341 } | 342 } |
| 342 } // namespace std | 343 } // namespace std |
| OLD | NEW |