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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 if (found == process_sender_map_.end()) | 293 if (found == process_sender_map_.end()) |
294 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; | 294 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; |
295 if (!found->second->Send(message.release())) | 295 if (!found->second->Send(message.release())) |
296 return SERVICE_WORKER_ERROR_IPC_FAILED; | 296 return SERVICE_WORKER_ERROR_IPC_FAILED; |
297 return SERVICE_WORKER_OK; | 297 return SERVICE_WORKER_OK; |
298 } | 298 } |
299 | 299 |
300 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, | 300 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, |
301 int embedded_worker_id) { | 301 int embedded_worker_id) { |
302 DCHECK(base::ContainsKey(worker_map_, embedded_worker_id)); | 302 DCHECK(base::ContainsKey(worker_map_, embedded_worker_id)); |
| 303 DetachWorker(process_id, embedded_worker_id); |
303 worker_map_.erase(embedded_worker_id); | 304 worker_map_.erase(embedded_worker_id); |
| 305 } |
| 306 |
| 307 void EmbeddedWorkerRegistry::DetachWorker(int process_id, |
| 308 int embedded_worker_id) { |
| 309 DCHECK(base::ContainsKey(worker_map_, embedded_worker_id)); |
304 if (!base::ContainsKey(worker_process_map_, process_id)) | 310 if (!base::ContainsKey(worker_process_map_, process_id)) |
305 return; | 311 return; |
306 worker_process_map_[process_id].erase(embedded_worker_id); | 312 worker_process_map_[process_id].erase(embedded_worker_id); |
307 if (worker_process_map_[process_id].empty()) | 313 if (worker_process_map_[process_id].empty()) |
308 worker_process_map_.erase(process_id); | 314 worker_process_map_.erase(process_id); |
309 } | 315 } |
310 | 316 |
311 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorkerForMessage( | 317 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorkerForMessage( |
312 int process_id, | 318 int process_id, |
313 int embedded_worker_id) { | 319 int embedded_worker_id) { |
314 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); | 320 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); |
315 if (!worker || worker->process_id() != process_id) { | 321 if (!worker || worker->process_id() != process_id) { |
316 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); | 322 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); |
317 return nullptr; | 323 return nullptr; |
318 } | 324 } |
319 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); | 325 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); |
320 return worker; | 326 return worker; |
321 } | 327 } |
322 | 328 |
323 } // namespace content | 329 } // namespace content |
OLD | NEW |