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/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
8 #include "content/browser/service_worker/embedded_worker_instance.h" | 9 #include "content/browser/service_worker/embedded_worker_instance.h" |
9 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
10 #include "content/common/service_worker/embedded_worker_messages.h" | 11 #include "content/common/service_worker/embedded_worker_messages.h" |
11 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
12 #include "ipc/ipc_sender.h" | 13 #include "ipc/ipc_sender.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( | 17 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( |
17 base::WeakPtr<ServiceWorkerContextCore> context) | 18 base::WeakPtr<ServiceWorkerContextCore> context) |
18 : context_(context), | 19 : context_(context), |
19 next_embedded_worker_id_(0) {} | 20 next_embedded_worker_id_(0) {} |
20 | 21 |
21 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { | 22 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { |
22 scoped_ptr<EmbeddedWorkerInstance> worker( | 23 scoped_ptr<EmbeddedWorkerInstance> worker( |
23 new EmbeddedWorkerInstance(this, next_embedded_worker_id_)); | 24 new EmbeddedWorkerInstance(this, next_embedded_worker_id_)); |
24 worker_map_[next_embedded_worker_id_++] = worker.get(); | 25 worker_map_[next_embedded_worker_id_++] = worker.get(); |
25 return worker.Pass(); | 26 return worker.Pass(); |
26 } | 27 } |
27 | 28 |
28 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StartWorker( | 29 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StartWorker( |
29 int process_id, | 30 int process_id, |
30 int embedded_worker_id, | 31 int embedded_worker_id, |
31 int64 service_worker_version_id, | 32 int64 service_worker_version_id, |
32 const GURL& scope, | 33 const GURL& scope, |
33 const GURL& script_url) { | 34 const GURL& script_url, |
| 35 int* worker_devtools_agent_route_id) { |
| 36 *worker_devtools_agent_route_id = |
| 37 RenderProcessHostImpl::GetNextRoutingIDForProcess(process_id); |
34 return Send( | 38 return Send( |
35 process_id, | 39 process_id, |
36 new EmbeddedWorkerMsg_StartWorker( | 40 new EmbeddedWorkerMsg_StartWorker(embedded_worker_id, |
37 embedded_worker_id, service_worker_version_id, scope, script_url)); | 41 service_worker_version_id, |
| 42 scope, |
| 43 script_url, |
| 44 *worker_devtools_agent_route_id)); |
38 } | 45 } |
39 | 46 |
40 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( | 47 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( |
41 int process_id, int embedded_worker_id) { | 48 int process_id, int embedded_worker_id) { |
42 return Send(process_id, | 49 return Send(process_id, |
43 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); | 50 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); |
44 } | 51 } |
45 | 52 |
46 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) { | 53 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) { |
47 // TODO(kinuko): Move all EmbeddedWorker message handling from | 54 // TODO(kinuko): Move all EmbeddedWorker message handling from |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 165 } |
159 | 166 |
160 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, | 167 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, |
161 int embedded_worker_id) { | 168 int embedded_worker_id) { |
162 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); | 169 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); |
163 worker_map_.erase(embedded_worker_id); | 170 worker_map_.erase(embedded_worker_id); |
164 worker_process_map_.erase(process_id); | 171 worker_process_map_.erase(process_id); |
165 } | 172 } |
166 | 173 |
167 } // namespace content | 174 } // namespace content |
OLD | NEW |