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

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

Issue 2227593002: ServiceWorker: Implement StartWorker by using mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated with the comments Created 4 years, 3 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/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "content/browser/renderer_host/render_widget_helper.h" 10 #include "content/browser/renderer_host/render_widget_helper.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 : context_(context), 238 : context_(context),
239 next_embedded_worker_id_(initial_embedded_worker_id), 239 next_embedded_worker_id_(initial_embedded_worker_id),
240 initial_embedded_worker_id_(initial_embedded_worker_id) { 240 initial_embedded_worker_id_(initial_embedded_worker_id) {
241 } 241 }
242 242
243 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { 243 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {
244 Shutdown(); 244 Shutdown();
245 } 245 }
246 246
247 ServiceWorkerStatusCode EmbeddedWorkerRegistry::SendStartWorker( 247 ServiceWorkerStatusCode EmbeddedWorkerRegistry::SendStartWorker(
248 std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, 248 std::unique_ptr<EmbeddedWorkerStartParams> params,
249 int process_id) { 249 int process_id) {
250 if (!context_) 250 if (!context_)
251 return SERVICE_WORKER_ERROR_ABORT; 251 return SERVICE_WORKER_ERROR_ABORT;
252 252
253 // The ServiceWorkerDispatcherHost is supposed to be created when the process 253 // The ServiceWorkerDispatcherHost is supposed to be created when the process
254 // is created, and keep an entry in process_sender_map_ for its whole 254 // is created, and keep an entry in process_sender_map_ for its whole
255 // lifetime. 255 // lifetime.
256 DCHECK(base::ContainsKey(process_sender_map_, process_id)); 256 DCHECK(base::ContainsKey(process_sender_map_, process_id));
257 257
258 int embedded_worker_id = params->embedded_worker_id; 258 int embedded_worker_id = params->embedded_worker_id;
259 DCHECK(GetWorker(embedded_worker_id)); 259 DCHECK(GetWorker(embedded_worker_id));
260 DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id); 260 DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id);
261 DCHECK( 261 DCHECK(
262 !base::ContainsKey(worker_process_map_, process_id) || 262 !base::ContainsKey(worker_process_map_, process_id) ||
263 !base::ContainsKey(worker_process_map_[process_id], embedded_worker_id)); 263 !base::ContainsKey(worker_process_map_[process_id], embedded_worker_id));
264 264
265 ServiceWorkerStatusCode status = 265 ServiceWorkerStatusCode status =
266 Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params)); 266 Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params));
267 if (status == SERVICE_WORKER_OK) 267 if (status == SERVICE_WORKER_OK)
268 worker_process_map_[process_id].insert(embedded_worker_id); 268 BindWorkerToProcess(process_id, embedded_worker_id);
269 return status; 269 return status;
270 } 270 }
271 271
272 void EmbeddedWorkerRegistry::BindWorkerToProcess(int process_id,
273 int embedded_worker_id) {
274 // The ServiceWorkerDispatcherHost is supposed to be created when the process
275 // is created, and keep an entry in process_sender_map_ for its whole
276 // lifetime.
277 DCHECK(base::ContainsKey(process_sender_map_, process_id));
278 DCHECK(GetWorker(embedded_worker_id));
279 DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id);
280 DCHECK(
281 !base::ContainsKey(worker_process_map_, process_id) ||
282 !base::ContainsKey(worker_process_map_[process_id], embedded_worker_id));
283
284 worker_process_map_[process_id].insert(embedded_worker_id);
285 }
286
272 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( 287 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send(
273 int process_id, IPC::Message* message_ptr) { 288 int process_id, IPC::Message* message_ptr) {
274 std::unique_ptr<IPC::Message> message(message_ptr); 289 std::unique_ptr<IPC::Message> message(message_ptr);
275 if (!context_) 290 if (!context_)
276 return SERVICE_WORKER_ERROR_ABORT; 291 return SERVICE_WORKER_ERROR_ABORT;
277 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); 292 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
278 if (found == process_sender_map_.end()) 293 if (found == process_sender_map_.end())
279 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; 294 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
280 if (!found->second->Send(message.release())) 295 if (!found->second->Send(message.release()))
281 return SERVICE_WORKER_ERROR_IPC_FAILED; 296 return SERVICE_WORKER_ERROR_IPC_FAILED;
(...skipping 17 matching lines...) Expand all
299 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); 314 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id);
300 if (!worker || worker->process_id() != process_id) { 315 if (!worker || worker->process_id() != process_id) {
301 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); 316 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false);
302 return nullptr; 317 return nullptr;
303 } 318 }
304 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); 319 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true);
305 return worker; 320 return worker;
306 } 321 }
307 322
308 } // namespace content 323 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698