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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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<EmbeddedWorkerStartParams> params, | 252 std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> 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 BindWorkerToProcess(process_id, embedded_worker_id); | 272 worker_process_map_[process_id].insert(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 | |
291 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( | 276 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( |
292 int process_id, IPC::Message* message_ptr) { | 277 int process_id, IPC::Message* message_ptr) { |
293 std::unique_ptr<IPC::Message> message(message_ptr); | 278 std::unique_ptr<IPC::Message> message(message_ptr); |
294 if (!context_) | 279 if (!context_) |
295 return SERVICE_WORKER_ERROR_ABORT; | 280 return SERVICE_WORKER_ERROR_ABORT; |
296 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); | 281 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); |
297 if (found == process_sender_map_.end()) | 282 if (found == process_sender_map_.end()) |
298 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; | 283 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; |
299 if (!found->second->Send(message.release())) | 284 if (!found->second->Send(message.release())) |
300 return SERVICE_WORKER_ERROR_IPC_FAILED; | 285 return SERVICE_WORKER_ERROR_IPC_FAILED; |
(...skipping 17 matching lines...) Expand all Loading... |
318 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); | 303 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); |
319 if (!worker || worker->process_id() != process_id) { | 304 if (!worker || worker->process_id() != process_id) { |
320 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); | 305 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); |
321 return nullptr; | 306 return nullptr; |
322 } | 307 } |
323 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); | 308 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); |
324 return worker; | 309 return worker; |
325 } | 310 } |
326 | 311 |
327 } // namespace content | 312 } // namespace content |
OLD | NEW |