Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 14 #include "content/browser/site_instance_impl.h" | |
| 14 #include "content/common/service_worker/embedded_worker_settings.h" | 15 #include "content/common/service_worker/embedded_worker_settings.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 17 #include "content/public/browser/site_instance.h" | 18 #include "content/public/browser/site_instance.h" |
| 18 #include "content/public/common/child_process_host.h" | 19 #include "content/public/common/child_process_host.h" |
| 19 #include "content/public/common/content_client.h" | 20 #include "content/public/common/content_client.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 195 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 195 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT, | 196 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT, |
| 196 ChildProcessHost::kInvalidUniqueID, | 197 ChildProcessHost::kInvalidUniqueID, |
| 197 false /* is_new_process */, settings)); | 198 false /* is_new_process */, settings)); |
| 198 return; | 199 return; |
| 199 } | 200 } |
| 200 | 201 |
| 201 DCHECK(!base::ContainsKey(instance_info_, embedded_worker_id)) | 202 DCHECK(!base::ContainsKey(instance_info_, embedded_worker_id)) |
| 202 << embedded_worker_id << " already has a process allocated"; | 203 << embedded_worker_id << " already has a process allocated"; |
| 203 | 204 |
| 204 if (can_use_existing_process) { | 205 if (can_use_existing_process) { |
|
Charlie Reis
2017/05/24 04:50:54
Sanity check: I'm assuming we'll come back and rem
clamy
2017/05/24 14:44:27
Added a TODO.
| |
| 205 int process_id = FindAvailableProcess(pattern); | 206 int process_id = FindAvailableProcess(pattern); |
| 206 if (process_id != ChildProcessHost::kInvalidUniqueID) { | 207 if (process_id != ChildProcessHost::kInvalidUniqueID) { |
| 207 RenderProcessHost::FromID(process_id)->IncrementServiceWorkerRefCount(); | 208 RenderProcessHost::FromID(process_id)->IncrementServiceWorkerRefCount(); |
| 208 instance_info_.insert( | 209 instance_info_.insert( |
| 209 std::make_pair(embedded_worker_id, ProcessInfo(process_id))); | 210 std::make_pair(embedded_worker_id, ProcessInfo(process_id))); |
| 210 BrowserThread::PostTask( | 211 BrowserThread::PostTask( |
| 211 BrowserThread::IO, FROM_HERE, | 212 BrowserThread::IO, FROM_HERE, |
| 212 base::Bind(callback, SERVICE_WORKER_OK, process_id, | 213 base::Bind(callback, SERVICE_WORKER_OK, process_id, |
| 213 false /* is_new_process */, settings)); | 214 false /* is_new_process */, settings)); |
| 214 return; | 215 return; |
| 215 } | 216 } |
| 216 } | 217 } |
| 217 | 218 |
| 218 // No existing processes available; start a new one. | 219 // No existing processes available; start a new one. |
| 219 scoped_refptr<SiteInstance> site_instance = | 220 scoped_refptr<SiteInstanceImpl> site_instance = |
| 220 SiteInstance::CreateForURL(browser_context_, script_url); | 221 SiteInstanceImpl::CreateForURL(browser_context_, script_url); |
| 222 site_instance->set_process_reuse_policy( | |
| 223 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); | |
| 221 RenderProcessHost* rph = site_instance->GetProcess(); | 224 RenderProcessHost* rph = site_instance->GetProcess(); |
| 222 | 225 |
| 223 // This Init() call posts a task to the IO thread that adds the RPH's | 226 // This Init() call posts a task to the IO thread that adds the RPH's |
| 224 // ServiceWorkerDispatcherHost to the | 227 // ServiceWorkerDispatcherHost to the |
| 225 // EmbeddedWorkerRegistry::process_sender_map_. | 228 // EmbeddedWorkerRegistry::process_sender_map_. |
| 226 if (!rph->Init()) { | 229 if (!rph->Init()) { |
| 227 LOG(ERROR) << "Couldn't start a new process!"; | 230 LOG(ERROR) << "Couldn't start a new process!"; |
| 228 BrowserThread::PostTask( | 231 BrowserThread::PostTask( |
| 229 BrowserThread::IO, FROM_HERE, | 232 BrowserThread::IO, FROM_HERE, |
| 230 base::Bind(callback, SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND, | 233 base::Bind(callback, SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 namespace std { | 342 namespace std { |
| 340 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the | 343 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the |
| 341 // member WeakPtr to safely guard the object's lifetime when used on that | 344 // member WeakPtr to safely guard the object's lifetime when used on that |
| 342 // thread. | 345 // thread. |
| 343 void default_delete<content::ServiceWorkerProcessManager>::operator()( | 346 void default_delete<content::ServiceWorkerProcessManager>::operator()( |
| 344 content::ServiceWorkerProcessManager* ptr) const { | 347 content::ServiceWorkerProcessManager* ptr) const { |
| 345 content::BrowserThread::DeleteSoon( | 348 content::BrowserThread::DeleteSoon( |
| 346 content::BrowserThread::UI, FROM_HERE, ptr); | 349 content::BrowserThread::UI, FROM_HERE, ptr); |
| 347 } | 350 } |
| 348 } // namespace std | 351 } // namespace std |
| OLD | NEW |