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