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

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

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

Powered by Google App Engine
This is Rietveld 408576698