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/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "content/browser/renderer_host/render_widget_helper.h" | 9 #include "content/browser/renderer_host/render_widget_helper.h" |
10 #include "content/browser/service_worker/embedded_worker_instance.h" | 10 #include "content/browser/service_worker/embedded_worker_instance.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void EmbeddedWorkerRegistry::OnWorkerScriptLoadFailed(int process_id, | 93 void EmbeddedWorkerRegistry::OnWorkerScriptLoadFailed(int process_id, |
94 int embedded_worker_id) { | 94 int embedded_worker_id) { |
95 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); | 95 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
96 DCHECK(found != worker_map_.end()); | 96 DCHECK(found != worker_map_.end()); |
97 DCHECK_EQ(found->second->process_id(), process_id); | 97 DCHECK_EQ(found->second->process_id(), process_id); |
98 if (found == worker_map_.end() || found->second->process_id() != process_id) | 98 if (found == worker_map_.end() || found->second->process_id() != process_id) |
99 return; | 99 return; |
100 found->second->OnScriptLoadFailed(); | 100 found->second->OnScriptLoadFailed(); |
101 } | 101 } |
102 | 102 |
| 103 void EmbeddedWorkerRegistry::OnWorkerScriptEvaluated(int process_id, |
| 104 int embedded_worker_id, |
| 105 bool success) { |
| 106 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
| 107 DCHECK(found != worker_map_.end()); |
| 108 DCHECK_EQ(found->second->process_id(), process_id); |
| 109 if (found == worker_map_.end() || found->second->process_id() != process_id) |
| 110 return; |
| 111 found->second->OnScriptEvaluated(success); |
| 112 } |
| 113 |
103 void EmbeddedWorkerRegistry::OnWorkerStarted( | 114 void EmbeddedWorkerRegistry::OnWorkerStarted( |
104 int process_id, int embedded_worker_id) { | 115 int process_id, int embedded_worker_id) { |
105 DCHECK(!ContainsKey(worker_process_map_, process_id) || | 116 DCHECK(!ContainsKey(worker_process_map_, process_id) || |
106 worker_process_map_[process_id].count(embedded_worker_id) == 0); | 117 worker_process_map_[process_id].count(embedded_worker_id) == 0); |
107 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); | 118 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
108 DCHECK(found != worker_map_.end()); | 119 DCHECK(found != worker_map_.end()); |
109 DCHECK_EQ(found->second->process_id(), process_id); | 120 DCHECK_EQ(found->second->process_id(), process_id); |
110 if (found == worker_map_.end() || found->second->process_id() != process_id) | 121 if (found == worker_map_.end() || found->second->process_id() != process_id) |
111 return; | 122 return; |
112 worker_process_map_[process_id].insert(embedded_worker_id); | 123 worker_process_map_[process_id].insert(embedded_worker_id); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 int initial_embedded_worker_id) | 218 int initial_embedded_worker_id) |
208 : context_(context), | 219 : context_(context), |
209 next_embedded_worker_id_(initial_embedded_worker_id), | 220 next_embedded_worker_id_(initial_embedded_worker_id), |
210 initial_embedded_worker_id_(initial_embedded_worker_id) { | 221 initial_embedded_worker_id_(initial_embedded_worker_id) { |
211 } | 222 } |
212 | 223 |
213 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { | 224 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { |
214 Shutdown(); | 225 Shutdown(); |
215 } | 226 } |
216 | 227 |
217 void EmbeddedWorkerRegistry::SendStartWorker( | 228 ServiceWorkerStatusCode EmbeddedWorkerRegistry::SendStartWorker( |
218 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 229 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, |
219 const StatusCallback& callback, | |
220 int process_id) { | 230 int process_id) { |
221 // The ServiceWorkerDispatcherHost is supposed to be created when the process | 231 // The ServiceWorkerDispatcherHost is supposed to be created when the process |
222 // is created, and keep an entry in process_sender_map_ for its whole | 232 // is created, and keep an entry in process_sender_map_ for its whole |
223 // lifetime. | 233 // lifetime. |
224 DCHECK(ContainsKey(process_sender_map_, process_id)); | 234 DCHECK(ContainsKey(process_sender_map_, process_id)); |
225 callback.Run(Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params))); | 235 return Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params)); |
226 } | 236 } |
227 | 237 |
228 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( | 238 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( |
229 int process_id, IPC::Message* message_ptr) { | 239 int process_id, IPC::Message* message_ptr) { |
230 scoped_ptr<IPC::Message> message(message_ptr); | 240 scoped_ptr<IPC::Message> message(message_ptr); |
231 if (!context_) | 241 if (!context_) |
232 return SERVICE_WORKER_ERROR_ABORT; | 242 return SERVICE_WORKER_ERROR_ABORT; |
233 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); | 243 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); |
234 if (found == process_sender_map_.end()) | 244 if (found == process_sender_map_.end()) |
235 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; | 245 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; |
236 if (!found->second->Send(message.release())) | 246 if (!found->second->Send(message.release())) |
237 return SERVICE_WORKER_ERROR_IPC_FAILED; | 247 return SERVICE_WORKER_ERROR_IPC_FAILED; |
238 return SERVICE_WORKER_OK; | 248 return SERVICE_WORKER_OK; |
239 } | 249 } |
240 | 250 |
241 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, | 251 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, |
242 int embedded_worker_id) { | 252 int embedded_worker_id) { |
243 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); | 253 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); |
244 worker_map_.erase(embedded_worker_id); | 254 worker_map_.erase(embedded_worker_id); |
245 worker_process_map_.erase(process_id); | 255 worker_process_map_.erase(process_id); |
246 } | 256 } |
247 | 257 |
248 } // namespace content | 258 } // namespace content |
OLD | NEW |