Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: content/browser/service_worker/embedded_worker_registry.cc

Issue 1223193009: WIP attempt to replace StartWorker/StopWorker IPCs with a new mojo EmbeddedWorker service. Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-event-dispatching-option2
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 24 matching lines...) Expand all
35 return registry; 35 return registry;
36 } 36 }
37 37
38 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { 38 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() {
39 scoped_ptr<EmbeddedWorkerInstance> worker( 39 scoped_ptr<EmbeddedWorkerInstance> worker(
40 new EmbeddedWorkerInstance(context_, next_embedded_worker_id_)); 40 new EmbeddedWorkerInstance(context_, next_embedded_worker_id_));
41 worker_map_[next_embedded_worker_id_++] = worker.get(); 41 worker_map_[next_embedded_worker_id_++] = worker.get();
42 return worker.Pass(); 42 return worker.Pass();
43 } 43 }
44 44
45 ServiceWorkerStatusCode EmbeddedWorkerRegistry::StopWorker(
46 int process_id, int embedded_worker_id) {
47 return Send(process_id,
48 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
49 }
50
51 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message, 45 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message,
52 int process_id) { 46 int process_id) {
53 // TODO(kinuko): Move all EmbeddedWorker message handling from 47 // TODO(kinuko): Move all EmbeddedWorker message handling from
54 // ServiceWorkerDispatcherHost. 48 // ServiceWorkerDispatcherHost.
55 49
56 WorkerInstanceMap::iterator found = worker_map_.find(message.routing_id()); 50 WorkerInstanceMap::iterator found = worker_map_.find(message.routing_id());
57 DCHECK(found != worker_map_.end()); 51 DCHECK(found != worker_map_.end());
58 if (found == worker_map_.end() || found->second->process_id() != process_id) 52 if (found == worker_map_.end() || found->second->process_id() != process_id)
59 return false; 53 return false;
60 return found->second->OnMessageReceived(message); 54 return found->second->OnMessageReceived(message);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 int initial_embedded_worker_id) 220 int initial_embedded_worker_id)
227 : context_(context), 221 : context_(context),
228 next_embedded_worker_id_(initial_embedded_worker_id), 222 next_embedded_worker_id_(initial_embedded_worker_id),
229 initial_embedded_worker_id_(initial_embedded_worker_id) { 223 initial_embedded_worker_id_(initial_embedded_worker_id) {
230 } 224 }
231 225
232 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { 226 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {
233 Shutdown(); 227 Shutdown();
234 } 228 }
235 229
236 ServiceWorkerStatusCode EmbeddedWorkerRegistry::SendStartWorker( 230 void EmbeddedWorkerRegistry::WorkerStarting(int embedded_worker_id,
237 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, 231 int process_id) {
238 int process_id) {
239 if (!context_)
240 return SERVICE_WORKER_ERROR_ABORT;
241
242 // The ServiceWorkerDispatcherHost is supposed to be created when the process 232 // The ServiceWorkerDispatcherHost is supposed to be created when the process
243 // is created, and keep an entry in process_sender_map_ for its whole 233 // is created, and keep an entry in process_sender_map_ for its whole
244 // lifetime. 234 // lifetime.
245 DCHECK(ContainsKey(process_sender_map_, process_id)); 235 DCHECK(ContainsKey(process_sender_map_, process_id));
246 236
247 int embedded_worker_id = params->embedded_worker_id;
248 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 237 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
249 DCHECK(found != worker_map_.end()); 238 DCHECK(found != worker_map_.end());
250 DCHECK_EQ(found->second->process_id(), process_id); 239 DCHECK_EQ(found->second->process_id(), process_id);
251 240
252 DCHECK(!ContainsKey(worker_process_map_, process_id) || 241 DCHECK(!ContainsKey(worker_process_map_, process_id) ||
253 worker_process_map_[process_id].count(embedded_worker_id) == 0); 242 worker_process_map_[process_id].count(embedded_worker_id) == 0);
254 243
255 ServiceWorkerStatusCode status = 244 worker_process_map_[process_id].insert(embedded_worker_id);
256 Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params));
257 if (status == SERVICE_WORKER_OK)
258 worker_process_map_[process_id].insert(embedded_worker_id);
259 return status;
260 } 245 }
261 246
262 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( 247 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send(
263 int process_id, IPC::Message* message_ptr) { 248 int process_id, IPC::Message* message_ptr) {
264 scoped_ptr<IPC::Message> message(message_ptr); 249 scoped_ptr<IPC::Message> message(message_ptr);
265 if (!context_) 250 if (!context_)
266 return SERVICE_WORKER_ERROR_ABORT; 251 return SERVICE_WORKER_ERROR_ABORT;
267 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); 252 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
268 if (found == process_sender_map_.end()) 253 if (found == process_sender_map_.end())
269 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; 254 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
270 if (!found->second->Send(message.release())) 255 if (!found->second->Send(message.release()))
271 return SERVICE_WORKER_ERROR_IPC_FAILED; 256 return SERVICE_WORKER_ERROR_IPC_FAILED;
272 return SERVICE_WORKER_OK; 257 return SERVICE_WORKER_OK;
273 } 258 }
274 259
275 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 260 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
276 int embedded_worker_id) { 261 int embedded_worker_id) {
277 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 262 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
278 worker_map_.erase(embedded_worker_id); 263 worker_map_.erase(embedded_worker_id);
279 worker_process_map_.erase(process_id); 264 worker_process_map_.erase(process_id);
280 } 265 }
281 266
282 } // namespace content 267 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698