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

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

Issue 252633003: Introduce worker_devtools_agent_route_id for EmbeddedWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comment 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/service_worker/embedded_worker_instance.h" 10 #include "content/browser/service_worker/embedded_worker_instance.h"
10 #include "content/browser/service_worker/service_worker_context_core.h" 11 #include "content/browser/service_worker/service_worker_context_core.h"
11 #include "content/browser/service_worker/service_worker_context_wrapper.h" 12 #include "content/browser/service_worker/service_worker_context_wrapper.h"
12 #include "content/common/service_worker/embedded_worker_messages.h" 13 #include "content/common/service_worker/embedded_worker_messages.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "ipc/ipc_message.h" 15 #include "ipc/ipc_message.h"
15 #include "ipc/ipc_sender.h" 16 #include "ipc/ipc_sender.h"
16 17
17 namespace content { 18 namespace content {
18 19
(...skipping 12 matching lines...) Expand all
31 void EmbeddedWorkerRegistry::StartWorker(const std::vector<int>& process_ids, 32 void EmbeddedWorkerRegistry::StartWorker(const std::vector<int>& process_ids,
32 int embedded_worker_id, 33 int embedded_worker_id,
33 int64 service_worker_version_id, 34 int64 service_worker_version_id,
34 const GURL& scope, 35 const GURL& scope,
35 const GURL& script_url, 36 const GURL& script_url,
36 const StatusCallback& callback) { 37 const StatusCallback& callback) {
37 if (!context_) { 38 if (!context_) {
38 callback.Run(SERVICE_WORKER_ERROR_ABORT); 39 callback.Run(SERVICE_WORKER_ERROR_ABORT);
39 return; 40 return;
40 } 41 }
42 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params(
43 new EmbeddedWorkerMsg_StartWorker_Params());
44 params->embedded_worker_id = embedded_worker_id;
45 params->service_worker_version_id = service_worker_version_id;
46 params->scope = scope;
47 params->script_url = script_url;
48 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE;
41 context_->process_manager()->AllocateWorkerProcess( 49 context_->process_manager()->AllocateWorkerProcess(
42 process_ids, 50 process_ids,
43 script_url, 51 script_url,
44 base::Bind(&EmbeddedWorkerRegistry::StartWorkerWithProcessId, 52 base::Bind(&EmbeddedWorkerRegistry::StartWorkerWithProcessId,
45 this, 53 this,
46 embedded_worker_id, 54 embedded_worker_id,
47 base::Passed(make_scoped_ptr(new EmbeddedWorkerMsg_StartWorker( 55 base::Passed(&params),
48 embedded_worker_id,
49 service_worker_version_id,
50 scope,
51 script_url))),
52 callback)); 56 callback));
53 } 57 }
54 58
55 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( 59 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker(
56 int process_id, int embedded_worker_id) { 60 int process_id, int embedded_worker_id) {
57 if (context_) 61 if (context_)
58 context_->process_manager()->ReleaseWorkerProcess(process_id); 62 context_->process_manager()->ReleaseWorkerProcess(process_id);
59 return Send(process_id, 63 return Send(process_id,
60 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); 64 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
61 } 65 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return NULL; 171 return NULL;
168 return found->second; 172 return found->second;
169 } 173 }
170 174
171 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { 175 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {
172 Shutdown(); 176 Shutdown();
173 } 177 }
174 178
175 void EmbeddedWorkerRegistry::StartWorkerWithProcessId( 179 void EmbeddedWorkerRegistry::StartWorkerWithProcessId(
176 int embedded_worker_id, 180 int embedded_worker_id,
177 scoped_ptr<EmbeddedWorkerMsg_StartWorker> message, 181 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
178 const StatusCallback& callback, 182 const StatusCallback& callback,
179 ServiceWorkerStatusCode status, 183 ServiceWorkerStatusCode status,
180 int process_id) { 184 int process_id) {
181 WorkerInstanceMap::const_iterator worker = 185 WorkerInstanceMap::const_iterator worker =
182 worker_map_.find(embedded_worker_id); 186 worker_map_.find(embedded_worker_id);
183 if (worker == worker_map_.end()) { 187 if (worker == worker_map_.end()) {
184 // The Instance was destroyed before it could finish starting. Undo what 188 // The Instance was destroyed before it could finish starting. Undo what
185 // we've done so far. 189 // we've done so far.
186 if (context_) 190 if (context_)
187 context_->process_manager()->ReleaseWorkerProcess(process_id); 191 context_->process_manager()->ReleaseWorkerProcess(process_id);
188 callback.Run(SERVICE_WORKER_ERROR_ABORT); 192 callback.Run(SERVICE_WORKER_ERROR_ABORT);
189 return; 193 return;
190 } 194 }
191 worker->second->RecordProcessId(process_id, status); 195 if (status == SERVICE_WORKER_OK) {
196 // Gets the new routing id for the renderer process.
197 scoped_refptr<RenderWidgetHelper> helper(
198 RenderWidgetHelper::FromProcessHostID(process_id));
199 // |helper| may be NULL in unittest.
200 params->worker_devtools_agent_route_id =
201 helper ? helper->GetNextRoutingID() : MSG_ROUTING_NONE;
202 }
203 worker->second->RecordProcessId(
204 process_id, status, params->worker_devtools_agent_route_id);
192 205
193 if (status != SERVICE_WORKER_OK) { 206 if (status != SERVICE_WORKER_OK) {
194 callback.Run(status); 207 callback.Run(status);
195 return; 208 return;
196 } 209 }
197 // The ServiceWorkerDispatcherHost is supposed to be created when the process 210 // The ServiceWorkerDispatcherHost is supposed to be created when the process
198 // is created, and keep an entry in process_sender_map_ for its whole 211 // is created, and keep an entry in process_sender_map_ for its whole
199 // lifetime. 212 // lifetime.
200 DCHECK(ContainsKey(process_sender_map_, process_id)); 213 DCHECK(ContainsKey(process_sender_map_, process_id));
201 callback.Run(Send(process_id, message.release())); 214 callback.Run(Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params)));
202 } 215 }
203 216
204 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( 217 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send(
205 int process_id, IPC::Message* message) { 218 int process_id, IPC::Message* message) {
206 if (!context_) 219 if (!context_)
207 return SERVICE_WORKER_ERROR_ABORT; 220 return SERVICE_WORKER_ERROR_ABORT;
208 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); 221 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
209 if (found == process_sender_map_.end()) 222 if (found == process_sender_map_.end())
210 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; 223 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
211 if (!found->second->Send(message)) 224 if (!found->second->Send(message))
212 return SERVICE_WORKER_ERROR_IPC_FAILED; 225 return SERVICE_WORKER_ERROR_IPC_FAILED;
213 return SERVICE_WORKER_OK; 226 return SERVICE_WORKER_OK;
214 } 227 }
215 228
216 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 229 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
217 int embedded_worker_id) { 230 int embedded_worker_id) {
218 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 231 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
219 worker_map_.erase(embedded_worker_id); 232 worker_map_.erase(embedded_worker_id);
220 worker_process_map_.erase(process_id); 233 worker_process_map_.erase(process_id);
221 } 234 }
222 235
223 } // namespace content 236 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698