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

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: fix compile error 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" 9 #include "content/browser/renderer_host/render_widget_helper.h"
10 #include "content/browser/service_worker/embedded_worker_instance.h" 10 #include "content/browser/service_worker/embedded_worker_instance.h"
11 #include "content/browser/service_worker/service_worker_context_core.h" 11 #include "content/browser/service_worker/service_worker_context_core.h"
12 #include "content/browser/service_worker/service_worker_context_wrapper.h" 12 #include "content/browser/service_worker/service_worker_context_wrapper.h"
13 #include "content/common/service_worker/embedded_worker_messages.h" 13 #include "content/common/service_worker/embedded_worker_messages.h"
14 #include "content/common/service_worker/service_worker_messages.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/render_process_host.h"
15 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
16 #include "ipc/ipc_sender.h" 18 #include "ipc/ipc_sender.h"
17 19
18 namespace content { 20 namespace content {
19 21
20 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( 22 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry(
21 base::WeakPtr<ServiceWorkerContextCore> context) 23 base::WeakPtr<ServiceWorkerContextCore> context)
22 : context_(context), 24 : context_(context),
23 next_embedded_worker_id_(0) {} 25 next_embedded_worker_id_(0) {}
24 26
25 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { 27 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() {
26 scoped_ptr<EmbeddedWorkerInstance> worker( 28 scoped_ptr<EmbeddedWorkerInstance> worker(new EmbeddedWorkerInstance(
27 new EmbeddedWorkerInstance(this, next_embedded_worker_id_)); 29 this, next_embedded_worker_id_, context_->storage_partition_path()));
28 worker_map_[next_embedded_worker_id_++] = worker.get(); 30 worker_map_[next_embedded_worker_id_++] = worker.get();
29 return worker.Pass(); 31 return worker.Pass();
30 } 32 }
31 33
32 void EmbeddedWorkerRegistry::StartWorker(const std::vector<int>& process_ids, 34 void EmbeddedWorkerRegistry::StartWorker(const std::vector<int>& process_ids,
33 int embedded_worker_id, 35 int embedded_worker_id,
34 int64 service_worker_version_id, 36 int64 service_worker_version_id,
35 const GURL& scope, 37 const GURL& scope,
36 const GURL& script_url, 38 const GURL& script_url,
37 const StatusCallback& callback) { 39 const StatusCallback& callback) {
38 if (!context_) { 40 if (!context_) {
39 callback.Run(SERVICE_WORKER_ERROR_ABORT); 41 callback.Run(SERVICE_WORKER_ERROR_ABORT);
40 return; 42 return;
41 } 43 }
42 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( 44 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params(
43 new EmbeddedWorkerMsg_StartWorker_Params()); 45 new EmbeddedWorkerMsg_StartWorker_Params());
44 params->embedded_worker_id = embedded_worker_id; 46 params->embedded_worker_id = embedded_worker_id;
45 params->service_worker_version_id = service_worker_version_id; 47 params->service_worker_version_id = service_worker_version_id;
46 params->scope = scope; 48 params->scope = scope;
47 params->script_url = script_url; 49 params->script_url = script_url;
48 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; 50 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE;
51 params->pause_on_start = false;
49 context_->process_manager()->AllocateWorkerProcess( 52 context_->process_manager()->AllocateWorkerProcess(
50 process_ids, 53 process_ids,
51 script_url, 54 script_url,
52 base::Bind(&EmbeddedWorkerRegistry::StartWorkerWithProcessId, 55 base::Bind(&EmbeddedWorkerRegistry::WorkerProcessAllocated,
53 this, 56 this,
54 embedded_worker_id,
55 base::Passed(&params), 57 base::Passed(&params),
56 callback)); 58 callback));
57 } 59 }
58 60
59 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( 61 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker(
60 int process_id, int embedded_worker_id) { 62 int process_id, int embedded_worker_id) {
61 if (context_) 63 if (context_)
62 context_->process_manager()->ReleaseWorkerProcess(process_id); 64 context_->process_manager()->ReleaseWorkerProcess(process_id);
63 return Send(process_id, 65 return Send(process_id,
64 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); 66 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 205 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
204 if (found == worker_map_.end()) 206 if (found == worker_map_.end())
205 return NULL; 207 return NULL;
206 return found->second; 208 return found->second;
207 } 209 }
208 210
209 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { 211 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {
210 Shutdown(); 212 Shutdown();
211 } 213 }
212 214
213 void EmbeddedWorkerRegistry::StartWorkerWithProcessId( 215 void EmbeddedWorkerRegistry::WorkerProcessAllocated(
214 int embedded_worker_id,
215 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, 216 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
216 const StatusCallback& callback, 217 const StatusCallback& callback,
217 ServiceWorkerStatusCode status, 218 ServiceWorkerStatusCode status,
218 int process_id) { 219 int process_id) {
219 WorkerInstanceMap::const_iterator worker = 220 WorkerInstanceMap::const_iterator worker =
220 worker_map_.find(embedded_worker_id); 221 worker_map_.find(params->embedded_worker_id);
221 if (worker == worker_map_.end()) { 222 if (worker == worker_map_.end()) {
222 // The Instance was destroyed before it could finish starting. Undo what 223 // The Instance was destroyed before it could finish starting. Undo what
223 // we've done so far. 224 // we've done so far.
224 if (context_) 225 if (context_)
225 context_->process_manager()->ReleaseWorkerProcess(process_id); 226 context_->process_manager()->ReleaseWorkerProcess(process_id);
226 callback.Run(SERVICE_WORKER_ERROR_ABORT); 227 callback.Run(SERVICE_WORKER_ERROR_ABORT);
227 return; 228 return;
228 } 229 }
229 if (status == SERVICE_WORKER_OK) {
230 // Gets the new routing id for the renderer process.
231 scoped_refptr<RenderWidgetHelper> helper(
232 RenderWidgetHelper::FromProcessHostID(process_id));
233 // |helper| may be NULL in unittest.
234 params->worker_devtools_agent_route_id =
235 helper ? helper->GetNextRoutingID() : MSG_ROUTING_NONE;
236 }
237 worker->second->RecordProcessId(
238 process_id, status, params->worker_devtools_agent_route_id);
239
240 if (status != SERVICE_WORKER_OK) { 230 if (status != SERVICE_WORKER_OK) {
231 worker->second->WorkerProcessAllocationFailed();
241 callback.Run(status); 232 callback.Run(status);
242 return; 233 return;
243 } 234 }
235 worker->second->WorkerProcessAllocated(
236 process_id,
237 base::Bind(&EmbeddedWorkerRegistry::StartWorkerWithProcessId,
238 this,
239 base::Passed(&params),
240 callback,
241 process_id));
kinuko 2014/05/08 11:17:31 The call sequence for starting a worker is becomin
horo 2014/05/08 14:17:46 I think we need to go through Registry after the t
kinuko 2014/05/08 16:34:57 Ok thanks, but I'm not fully convinced by the curr
horo 2014/05/12 10:18:49 Done.
242 }
243
244 void EmbeddedWorkerRegistry::StartWorkerWithProcessId(
245 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
246 const StatusCallback& callback,
247 int process_id,
248 int worker_devtools_agent_route_id,
249 bool pause_on_start) {
250 WorkerInstanceMap::const_iterator worker =
251 worker_map_.find(params->embedded_worker_id);
252 DCHECK(worker != worker_map_.end());
253 worker->second->set_worker_devtools_agent_route_id(
254 worker_devtools_agent_route_id);
244 // The ServiceWorkerDispatcherHost is supposed to be created when the process 255 // The ServiceWorkerDispatcherHost is supposed to be created when the process
245 // is created, and keep an entry in process_sender_map_ for its whole 256 // is created, and keep an entry in process_sender_map_ for its whole
246 // lifetime. 257 // lifetime.
247 DCHECK(ContainsKey(process_sender_map_, process_id)); 258 DCHECK(ContainsKey(process_sender_map_, process_id));
259 params->worker_devtools_agent_route_id = worker_devtools_agent_route_id;
260 params->pause_on_start = pause_on_start;
248 callback.Run(Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params))); 261 callback.Run(Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params)));
249 } 262 }
250 263
251 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( 264 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send(
252 int process_id, IPC::Message* message) { 265 int process_id, IPC::Message* message) {
253 if (!context_) 266 if (!context_)
254 return SERVICE_WORKER_ERROR_ABORT; 267 return SERVICE_WORKER_ERROR_ABORT;
255 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); 268 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
256 if (found == process_sender_map_.end()) 269 if (found == process_sender_map_.end())
257 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; 270 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
258 if (!found->second->Send(message)) 271 if (!found->second->Send(message))
259 return SERVICE_WORKER_ERROR_IPC_FAILED; 272 return SERVICE_WORKER_ERROR_IPC_FAILED;
260 return SERVICE_WORKER_OK; 273 return SERVICE_WORKER_OK;
261 } 274 }
262 275
263 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 276 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
264 int embedded_worker_id) { 277 int embedded_worker_id) {
265 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 278 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
266 worker_map_.erase(embedded_worker_id); 279 worker_map_.erase(embedded_worker_id);
267 worker_process_map_.erase(process_id); 280 worker_process_map_.erase(process_id);
268 } 281 }
269 282
270 } // namespace content 283 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698