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/devtools/shared_worker_devtools_manager.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" |
12 #include "content/common/service_worker/service_worker_messages.h" | |
13 #include "content/public/browser/browser_thread.h" | |
14 #include "content/public/browser/render_process_host.h" | |
11 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
12 #include "ipc/ipc_sender.h" | 16 #include "ipc/ipc_sender.h" |
13 | 17 |
14 namespace content { | 18 namespace content { |
15 | 19 |
16 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( | 20 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( |
17 base::WeakPtr<ServiceWorkerContextCore> context) | 21 base::WeakPtr<ServiceWorkerContextCore> context) |
18 : context_(context), | 22 : context_(context), |
19 next_embedded_worker_id_(0) {} | 23 next_embedded_worker_id_(0) {} |
20 | 24 |
21 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { | 25 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { |
22 scoped_ptr<EmbeddedWorkerInstance> worker( | 26 scoped_ptr<EmbeddedWorkerInstance> worker( |
23 new EmbeddedWorkerInstance(this, next_embedded_worker_id_)); | 27 new EmbeddedWorkerInstance(this, next_embedded_worker_id_)); |
24 worker_map_[next_embedded_worker_id_++] = worker.get(); | 28 worker_map_[next_embedded_worker_id_++] = worker.get(); |
25 return worker.Pass(); | 29 return worker.Pass(); |
26 } | 30 } |
27 | 31 |
28 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StartWorker( | 32 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StartWorker( |
29 int process_id, | 33 int process_id, |
30 int embedded_worker_id, | 34 int embedded_worker_id, |
31 int64 service_worker_version_id, | 35 int64 service_worker_version_id, |
32 const GURL& scope, | 36 const GURL& scope, |
33 const GURL& script_url) { | 37 const GURL& script_url, |
34 return Send( | 38 int* worker_route_id) { |
35 process_id, | 39 ProcessToNextRoutingIDCallbackMap::iterator found_callback = |
36 new EmbeddedWorkerMsg_StartWorker( | 40 process_next_id_callback_map_.find(process_id); |
37 embedded_worker_id, service_worker_version_id, scope, script_url)); | 41 if (found_callback == process_next_id_callback_map_.end()) |
42 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; | |
43 *worker_route_id = found_callback->second.Run(); | |
44 return Send(process_id, | |
45 new EmbeddedWorkerMsg_StartWorker(*worker_route_id, | |
michaeln
2014/04/25 02:53:15
Can we not route/identify based on the existing em
horo
2014/04/25 04:34:44
I want to reuse the architecture of DevTools for S
| |
46 embedded_worker_id, | |
47 service_worker_version_id, | |
48 scope, | |
49 script_url)); | |
38 } | 50 } |
39 | 51 |
40 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( | 52 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker( |
41 int process_id, int embedded_worker_id) { | 53 int process_id, int embedded_worker_id) { |
42 return Send(process_id, | 54 return Send(process_id, |
43 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); | 55 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); |
44 } | 56 } |
45 | 57 |
46 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) { | 58 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) { |
47 // TODO(kinuko): Move all EmbeddedWorker message handling from | 59 // TODO(kinuko): Move all EmbeddedWorker message handling from |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 it != worker_set.end(); | 140 it != worker_set.end(); |
129 ++it) { | 141 ++it) { |
130 int embedded_worker_id = *it; | 142 int embedded_worker_id = *it; |
131 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); | 143 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); |
132 worker_map_[embedded_worker_id]->OnStopped(); | 144 worker_map_[embedded_worker_id]->OnStopped(); |
133 } | 145 } |
134 worker_process_map_.erase(found); | 146 worker_process_map_.erase(found); |
135 } | 147 } |
136 } | 148 } |
137 | 149 |
150 void EmbeddedWorkerRegistry::AddChildProcessNextRoutingIDCallback( | |
151 int process_id, | |
152 const base::Callback<int(void)>& callback) { | |
153 process_next_id_callback_map_.insert(std::make_pair(process_id, callback)); | |
154 } | |
155 | |
156 void EmbeddedWorkerRegistry::RemoveChildProcessNextRoutingIDCallback( | |
157 int process_id) { | |
158 process_next_id_callback_map_.erase(process_id); | |
159 } | |
160 | |
138 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker( | 161 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorker( |
139 int embedded_worker_id) { | 162 int embedded_worker_id) { |
140 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); | 163 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
141 if (found == worker_map_.end()) | 164 if (found == worker_map_.end()) |
142 return NULL; | 165 return NULL; |
143 return found->second; | 166 return found->second; |
144 } | 167 } |
145 | 168 |
146 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {} | 169 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {} |
147 | 170 |
(...skipping 10 matching lines...) Expand all Loading... | |
158 } | 181 } |
159 | 182 |
160 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, | 183 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, |
161 int embedded_worker_id) { | 184 int embedded_worker_id) { |
162 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); | 185 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); |
163 worker_map_.erase(embedded_worker_id); | 186 worker_map_.erase(embedded_worker_id); |
164 worker_process_map_.erase(process_id); | 187 worker_process_map_.erase(process_id); |
165 } | 188 } |
166 | 189 |
167 } // namespace content | 190 } // namespace content |
OLD | NEW |