| OLD | NEW |
| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 int initial_embedded_worker_id) | 237 int initial_embedded_worker_id) |
| 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( | |
| 248 std::unique_ptr<EmbeddedWorkerStartParams> params, | |
| 249 int process_id) { | |
| 250 if (!context_) | |
| 251 return SERVICE_WORKER_ERROR_ABORT; | |
| 252 | |
| 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 | |
| 255 // lifetime. | |
| 256 DCHECK(base::ContainsKey(process_sender_map_, process_id)); | |
| 257 | |
| 258 int embedded_worker_id = params->embedded_worker_id; | |
| 259 DCHECK(GetWorker(embedded_worker_id)); | |
| 260 DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id); | |
| 261 DCHECK( | |
| 262 !base::ContainsKey(worker_process_map_, process_id) || | |
| 263 !base::ContainsKey(worker_process_map_[process_id], embedded_worker_id)); | |
| 264 | |
| 265 ServiceWorkerStatusCode status = | |
| 266 Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params)); | |
| 267 if (status == SERVICE_WORKER_OK) | |
| 268 BindWorkerToProcess(process_id, embedded_worker_id); | |
| 269 return status; | |
| 270 } | |
| 271 | |
| 272 void EmbeddedWorkerRegistry::BindWorkerToProcess(int process_id, | 247 void EmbeddedWorkerRegistry::BindWorkerToProcess(int process_id, |
| 273 int embedded_worker_id) { | 248 int embedded_worker_id) { |
| 274 // The ServiceWorkerDispatcherHost is supposed to be created when the process | 249 // The ServiceWorkerDispatcherHost is supposed to be created when the process |
| 275 // is created, and keep an entry in process_sender_map_ for its whole | 250 // is created, and keep an entry in process_sender_map_ for its whole |
| 276 // lifetime. | 251 // lifetime. |
| 277 DCHECK(base::ContainsKey(process_sender_map_, process_id)); | 252 DCHECK(base::ContainsKey(process_sender_map_, process_id)); |
| 278 DCHECK(GetWorker(embedded_worker_id)); | 253 DCHECK(GetWorker(embedded_worker_id)); |
| 279 DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id); | 254 DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id); |
| 280 DCHECK( | 255 DCHECK( |
| 281 !base::ContainsKey(worker_process_map_, process_id) || | 256 !base::ContainsKey(worker_process_map_, process_id) || |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); | 295 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); |
| 321 if (!worker || worker->process_id() != process_id) { | 296 if (!worker || worker->process_id() != process_id) { |
| 322 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); | 297 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); |
| 323 return nullptr; | 298 return nullptr; |
| 324 } | 299 } |
| 325 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); | 300 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); |
| 326 return worker; | 301 return worker; |
| 327 } | 302 } |
| 328 | 303 |
| 329 } // namespace content | 304 } // namespace content |
| OLD | NEW |