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

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

Issue 261753008: Call EmbeddedWorkerDevToolsManager::ServiceWorkerCreated, WorkerContextStarted and WorkerDestroyed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/embedded_worker_registry.h" 5 #include "content/browser/service_worker/embedded_worker_registry.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/browser/renderer_host/render_widget_helper.h"
10 #include "content/browser/service_worker/embedded_worker_instance.h" 9 #include "content/browser/service_worker/embedded_worker_instance.h"
11 #include "content/browser/service_worker/service_worker_context_core.h" 10 #include "content/browser/service_worker/service_worker_context_core.h"
12 #include "content/browser/service_worker/service_worker_context_wrapper.h" 11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
13 #include "content/common/service_worker/embedded_worker_messages.h" 12 #include "content/common/service_worker/embedded_worker_messages.h"
13 #include "content/common/service_worker/service_worker_messages.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_process_host.h"
15 #include "ipc/ipc_message.h" 16 #include "ipc/ipc_message.h"
16 #include "ipc/ipc_sender.h" 17 #include "ipc/ipc_sender.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( 21 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry(
21 base::WeakPtr<ServiceWorkerContextCore> context) 22 base::WeakPtr<ServiceWorkerContextCore> context)
22 : context_(context), 23 : context_(context),
23 next_embedded_worker_id_(0) {} 24 next_embedded_worker_id_(0) {}
24 25
(...skipping 14 matching lines...) Expand all
39 callback.Run(SERVICE_WORKER_ERROR_ABORT); 40 callback.Run(SERVICE_WORKER_ERROR_ABORT);
40 return; 41 return;
41 } 42 }
42 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( 43 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params(
43 new EmbeddedWorkerMsg_StartWorker_Params()); 44 new EmbeddedWorkerMsg_StartWorker_Params());
44 params->embedded_worker_id = embedded_worker_id; 45 params->embedded_worker_id = embedded_worker_id;
45 params->service_worker_version_id = service_worker_version_id; 46 params->service_worker_version_id = service_worker_version_id;
46 params->scope = scope; 47 params->scope = scope;
47 params->script_url = script_url; 48 params->script_url = script_url;
48 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; 49 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE;
50 params->pause_on_start = false;
49 context_->process_manager()->AllocateWorkerProcess( 51 context_->process_manager()->AllocateWorkerProcess(
50 process_ids, 52 process_ids,
53 context_->storage()->path(),
kinuko 2014/05/02 08:55:47 Getting path from storage() to allocate a process
horo 2014/05/02 10:15:12 Done.
54 scope,
51 script_url, 55 script_url,
52 base::Bind(&EmbeddedWorkerRegistry::StartWorkerWithProcessId, 56 base::Bind(&EmbeddedWorkerRegistry::StartWorkerWithProcessId,
53 this, 57 this,
54 embedded_worker_id,
55 base::Passed(&params), 58 base::Passed(&params),
56 callback)); 59 callback));
57 } 60 }
58 61
59 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( 62 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker(
60 int process_id, int embedded_worker_id) { 63 int process_id, int embedded_worker_id) {
61 if (context_) 64 if (context_)
62 context_->process_manager()->ReleaseWorkerProcess(process_id); 65 context_->process_manager()->ReleaseWorkerProcess(process_id);
63 return Send(process_id, 66 return Send(process_id,
64 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); 67 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (found == worker_map_.end()) 195 if (found == worker_map_.end())
193 return NULL; 196 return NULL;
194 return found->second; 197 return found->second;
195 } 198 }
196 199
197 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { 200 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {
198 Shutdown(); 201 Shutdown();
199 } 202 }
200 203
201 void EmbeddedWorkerRegistry::StartWorkerWithProcessId( 204 void EmbeddedWorkerRegistry::StartWorkerWithProcessId(
202 int embedded_worker_id,
203 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, 205 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
204 const StatusCallback& callback, 206 const StatusCallback& callback,
205 ServiceWorkerStatusCode status, 207 ServiceWorkerStatusCode status,
206 int process_id) { 208 int process_id,
209 int worker_devtools_agent_route_id,
210 bool pause_on_start) {
207 WorkerInstanceMap::const_iterator worker = 211 WorkerInstanceMap::const_iterator worker =
208 worker_map_.find(embedded_worker_id); 212 worker_map_.find(params->embedded_worker_id);
209 if (worker == worker_map_.end()) { 213 if (worker == worker_map_.end()) {
210 // The Instance was destroyed before it could finish starting. Undo what 214 // The Instance was destroyed before it could finish starting. Undo what
211 // we've done so far. 215 // we've done so far.
212 if (context_) 216 if (context_)
213 context_->process_manager()->ReleaseWorkerProcess(process_id); 217 context_->process_manager()->ReleaseWorkerProcess(process_id);
214 callback.Run(SERVICE_WORKER_ERROR_ABORT); 218 callback.Run(SERVICE_WORKER_ERROR_ABORT);
215 return; 219 return;
216 } 220 }
217 if (status == SERVICE_WORKER_OK) {
218 // Gets the new routing id for the renderer process.
219 scoped_refptr<RenderWidgetHelper> helper(
220 RenderWidgetHelper::FromProcessHostID(process_id));
221 // |helper| may be NULL in unittest.
222 params->worker_devtools_agent_route_id =
223 helper ? helper->GetNextRoutingID() : MSG_ROUTING_NONE;
224 }
225 worker->second->RecordProcessId( 221 worker->second->RecordProcessId(
226 process_id, status, params->worker_devtools_agent_route_id); 222 process_id, status, worker_devtools_agent_route_id);
227 223
228 if (status != SERVICE_WORKER_OK) { 224 if (status != SERVICE_WORKER_OK) {
229 callback.Run(status); 225 callback.Run(status);
230 return; 226 return;
231 } 227 }
232 // The ServiceWorkerDispatcherHost is supposed to be created when the process 228 // The ServiceWorkerDispatcherHost is supposed to be created when the process
233 // is created, and keep an entry in process_sender_map_ for its whole 229 // is created, and keep an entry in process_sender_map_ for its whole
234 // lifetime. 230 // lifetime.
235 DCHECK(ContainsKey(process_sender_map_, process_id)); 231 DCHECK(ContainsKey(process_sender_map_, process_id));
232 params->worker_devtools_agent_route_id = worker_devtools_agent_route_id;
233 params->pause_on_start = pause_on_start;
236 callback.Run(Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params))); 234 callback.Run(Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params)));
237 } 235 }
238 236
239 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( 237 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send(
240 int process_id, IPC::Message* message) { 238 int process_id, IPC::Message* message) {
241 if (!context_) 239 if (!context_)
242 return SERVICE_WORKER_ERROR_ABORT; 240 return SERVICE_WORKER_ERROR_ABORT;
243 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); 241 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
244 if (found == process_sender_map_.end()) 242 if (found == process_sender_map_.end())
245 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; 243 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
246 if (!found->second->Send(message)) 244 if (!found->second->Send(message))
247 return SERVICE_WORKER_ERROR_IPC_FAILED; 245 return SERVICE_WORKER_ERROR_IPC_FAILED;
248 return SERVICE_WORKER_OK; 246 return SERVICE_WORKER_OK;
249 } 247 }
250 248
251 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 249 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
252 int embedded_worker_id) { 250 int embedded_worker_id) {
253 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 251 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
254 worker_map_.erase(embedded_worker_id); 252 worker_map_.erase(embedded_worker_id);
255 worker_process_map_.erase(process_id); 253 worker_process_map_.erase(process_id);
256 } 254 }
257 255
258 } // namespace content 256 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698