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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 AddWorker(process_id, embedded_worker_id); |
269 return status; | 269 return status; |
270 } | 270 } |
271 | 271 |
| 272 ServiceWorkerStatusCode EmbeddedWorkerRegistry::AddWorker( |
| 273 int process_id, |
| 274 int embedded_worker_id) { |
| 275 if (!context_) |
| 276 return SERVICE_WORKER_ERROR_ABORT; |
| 277 |
| 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 return SERVICE_WORKER_OK; |
| 290 } |
| 291 |
272 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( | 292 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( |
273 int process_id, IPC::Message* message_ptr) { | 293 int process_id, IPC::Message* message_ptr) { |
274 std::unique_ptr<IPC::Message> message(message_ptr); | 294 std::unique_ptr<IPC::Message> message(message_ptr); |
275 if (!context_) | 295 if (!context_) |
276 return SERVICE_WORKER_ERROR_ABORT; | 296 return SERVICE_WORKER_ERROR_ABORT; |
277 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); | 297 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); |
278 if (found == process_sender_map_.end()) | 298 if (found == process_sender_map_.end()) |
279 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; | 299 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; |
280 if (!found->second->Send(message.release())) | 300 if (!found->second->Send(message.release())) |
281 return SERVICE_WORKER_ERROR_IPC_FAILED; | 301 return SERVICE_WORKER_ERROR_IPC_FAILED; |
(...skipping 17 matching lines...) Expand all Loading... |
299 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); | 319 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); |
300 if (!worker || worker->process_id() != process_id) { | 320 if (!worker || worker->process_id() != process_id) { |
301 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); | 321 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); |
302 return nullptr; | 322 return nullptr; |
303 } | 323 } |
304 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); | 324 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); |
305 return worker; | 325 return worker; |
306 } | 326 } |
307 | 327 |
308 } // namespace content | 328 } // namespace content |
OLD | NEW |