Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: content/browser/service_worker/service_worker_process_manager.cc

Issue 292973003: Reparent SWProcessManager onto SWContextWrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 17 matching lines...) Expand all
28 } 28 }
29 29
30 ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(int process_id) 30 ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(int process_id)
31 : process_id(process_id) { 31 : process_id(process_id) {
32 } 32 }
33 33
34 ServiceWorkerProcessManager::ProcessInfo::~ProcessInfo() { 34 ServiceWorkerProcessManager::ProcessInfo::~ProcessInfo() {
35 } 35 }
36 36
37 ServiceWorkerProcessManager::ServiceWorkerProcessManager( 37 ServiceWorkerProcessManager::ServiceWorkerProcessManager(
38 ServiceWorkerContextWrapper* context_wrapper) 38 BrowserContext* browser_context)
39 : context_wrapper_(context_wrapper), 39 : browser_context_(browser_context),
40 process_id_for_test_(-1), 40 process_id_for_test_(-1),
41 weak_this_factory_(this), 41 weak_this_factory_(this),
42 weak_this_(weak_this_factory_.GetWeakPtr()) { 42 weak_this_(weak_this_factory_.GetWeakPtr()) {
43 } 43 }
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)
48 << "Call Shutdown() before destroying |this|, so that racing method "
49 << "invocations don't use a destroyed BrowserContext.";
50 }
falken 2014/05/22 02:43:19 nit: newline here?
Jeffrey Yasskin 2014/05/22 02:47:54 Done.
51 void ServiceWorkerProcessManager::Shutdown() {
52 browser_context_ = NULL;
47 } 53 }
48 54
49 void ServiceWorkerProcessManager::AllocateWorkerProcess( 55 void ServiceWorkerProcessManager::AllocateWorkerProcess(
50 int embedded_worker_id, 56 int embedded_worker_id,
51 const std::vector<int>& process_ids, 57 const std::vector<int>& process_ids,
52 const GURL& script_url, 58 const GURL& script_url,
53 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>& 59 const base::Callback<void(ServiceWorkerStatusCode, int process_id)>&
54 callback) { 60 callback) {
55 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 61 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
56 BrowserThread::PostTask( 62 BrowserThread::PostTask(
(...skipping 27 matching lines...) Expand all
84 if (IncrementWorkerRefCountByPid(*it)) { 90 if (IncrementWorkerRefCountByPid(*it)) {
85 instance_info_.insert( 91 instance_info_.insert(
86 std::make_pair(embedded_worker_id, ProcessInfo(*it))); 92 std::make_pair(embedded_worker_id, ProcessInfo(*it)));
87 BrowserThread::PostTask(BrowserThread::IO, 93 BrowserThread::PostTask(BrowserThread::IO,
88 FROM_HERE, 94 FROM_HERE,
89 base::Bind(callback, SERVICE_WORKER_OK, *it)); 95 base::Bind(callback, SERVICE_WORKER_OK, *it));
90 return; 96 return;
91 } 97 }
92 } 98 }
93 99
94 if (!context_wrapper_->browser_context_) { 100 if (!browser_context_) {
95 // Shutdown has started. 101 // Shutdown has started.
96 BrowserThread::PostTask( 102 BrowserThread::PostTask(
97 BrowserThread::IO, 103 BrowserThread::IO,
98 FROM_HERE, 104 FROM_HERE,
99 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); 105 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1));
100 return; 106 return;
101 } 107 }
102 // No existing processes available; start a new one. 108 // No existing processes available; start a new one.
103 scoped_refptr<SiteInstance> site_instance = SiteInstance::CreateForURL( 109 scoped_refptr<SiteInstance> site_instance =
104 context_wrapper_->browser_context_, script_url); 110 SiteInstance::CreateForURL(browser_context_, script_url);
105 RenderProcessHost* rph = site_instance->GetProcess(); 111 RenderProcessHost* rph = site_instance->GetProcess();
106 // This Init() call posts a task to the IO thread that adds the RPH's 112 // This Init() call posts a task to the IO thread that adds the RPH's
107 // ServiceWorkerDispatcherHost to the 113 // ServiceWorkerDispatcherHost to the
108 // EmbeddedWorkerRegistry::process_sender_map_. 114 // EmbeddedWorkerRegistry::process_sender_map_.
109 if (!rph->Init()) { 115 if (!rph->Init()) {
110 LOG(ERROR) << "Couldn't start a new process!"; 116 LOG(ERROR) << "Couldn't start a new process!";
111 BrowserThread::PostTask( 117 BrowserThread::PostTask(
112 BrowserThread::IO, 118 BrowserThread::IO,
113 FROM_HERE, 119 FROM_HERE,
114 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1)); 120 base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED, -1));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 namespace base { 170 namespace base {
165 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the 171 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the
166 // member WeakPtr to safely guard the object's lifetime when used on that 172 // member WeakPtr to safely guard the object's lifetime when used on that
167 // thread. 173 // thread.
168 void DefaultDeleter<content::ServiceWorkerProcessManager>::operator()( 174 void DefaultDeleter<content::ServiceWorkerProcessManager>::operator()(
169 content::ServiceWorkerProcessManager* ptr) const { 175 content::ServiceWorkerProcessManager* ptr) const {
170 content::BrowserThread::DeleteSoon( 176 content::BrowserThread::DeleteSoon(
171 content::BrowserThread::UI, FROM_HERE, ptr); 177 content::BrowserThread::UI, FROM_HERE, ptr);
172 } 178 }
173 } // namespace base 179 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698