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

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

Issue 118103002: Add IPC stubs between browser and ServiceWorker's worker context in the child process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 11 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 | Annotate | Revision Log
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/stl_util.h" 7 #include "base/stl_util.h"
8 #include "content/browser/service_worker/embedded_worker_instance.h" 8 #include "content/browser/service_worker/embedded_worker_instance.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/common/service_worker_messages.h" 10 #include "content/common/service_worker_messages.h"
11 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_sender.h" 12 #include "ipc/ipc_sender.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( 16 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry(
17 base::WeakPtr<ServiceWorkerContextCore> context) 17 base::WeakPtr<ServiceWorkerContextCore> context)
18 : context_(context), 18 : context_(context),
19 next_embedded_worker_id_(0) {} 19 next_embedded_worker_id_(0) {}
20 20
21 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() { 21 scoped_ptr<EmbeddedWorkerInstance> EmbeddedWorkerRegistry::CreateWorker() {
22 scoped_ptr<EmbeddedWorkerInstance> worker( 22 scoped_ptr<EmbeddedWorkerInstance> worker(
23 new EmbeddedWorkerInstance(this, next_embedded_worker_id_)); 23 new EmbeddedWorkerInstance(this, next_embedded_worker_id_));
24 worker_map_[next_embedded_worker_id_++] = worker.get(); 24 worker_map_[next_embedded_worker_id_++] = worker.get();
25 return worker.Pass(); 25 return worker.Pass();
26 } 26 }
27 27
28 void EmbeddedWorkerRegistry::RemoveWorker(int embedded_worker_id) {
29 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
30 worker_map_.erase(embedded_worker_id);
31 }
32
33 bool EmbeddedWorkerRegistry::StartWorker( 28 bool EmbeddedWorkerRegistry::StartWorker(
34 int process_id, 29 int process_id,
35 int embedded_worker_id, 30 int embedded_worker_id,
36 int64 service_worker_version_id, 31 int64 service_worker_version_id,
37 const GURL& script_url) { 32 const GURL& script_url) {
38 return Send(process_id, 33 return Send(process_id,
39 new ServiceWorkerMsg_StartWorker(embedded_worker_id, 34 new EmbeddedWorkerMsg_StartWorker(embedded_worker_id,
40 service_worker_version_id, 35 service_worker_version_id,
41 script_url)); 36 script_url));
42 } 37 }
43 38
44 bool EmbeddedWorkerRegistry::StopWorker(int process_id, 39 bool EmbeddedWorkerRegistry::StopWorker(int process_id,
45 int embedded_worker_id) { 40 int embedded_worker_id) {
46 return Send(process_id, 41 return Send(process_id,
47 new ServiceWorkerMsg_TerminateWorker(embedded_worker_id)); 42 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
43 }
44
45 void EmbeddedWorkerRegistry::OnWorkerStarted(
46 int process_id, int thread_id, int embedded_worker_id) {
47 DCHECK(!ContainsKey(worker_process_map_, process_id));
48 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
49 if (found == worker_map_.end()) {
50 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
51 return;
52 }
53 worker_process_map_[process_id] = embedded_worker_id;
54 DCHECK_EQ(found->second->process_id(), process_id);
55 found->second->OnStarted(thread_id);
56 }
57
58 void EmbeddedWorkerRegistry::OnWorkerStopped(
59 int process_id, int embedded_worker_id) {
60 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
61 if (found == worker_map_.end()) {
62 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
63 return;
64 }
65 DCHECK_EQ(found->second->process_id(), process_id);
66 worker_process_map_.erase(process_id);
67 found->second->OnStopped();
48 } 68 }
49 69
50 void EmbeddedWorkerRegistry::AddChildProcessSender( 70 void EmbeddedWorkerRegistry::AddChildProcessSender(
51 int process_id, IPC::Sender* sender) { 71 int process_id, IPC::Sender* sender) {
52 process_sender_map_[process_id] = sender; 72 process_sender_map_[process_id] = sender;
73 DCHECK(!ContainsKey(worker_process_map_, process_id));
53 } 74 }
54 75
55 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) { 76 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) {
56 process_sender_map_.erase(process_id); 77 process_sender_map_.erase(process_id);
78 std::map<int, int>::iterator found = worker_process_map_.find(process_id);
79 if (found != worker_process_map_.end()) {
80 int embedded_worker_id = found->second;
81 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
82 worker_map_[embedded_worker_id]->OnStopped();
83 worker_process_map_.erase(found);
84 }
57 } 85 }
58 86
59 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {} 87 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {}
60 88
61 bool EmbeddedWorkerRegistry::Send(int process_id, IPC::Message* message) { 89 bool EmbeddedWorkerRegistry::Send(int process_id, IPC::Message* message) {
62 if (!context_) 90 if (!context_)
63 return false; 91 return false;
64 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); 92 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
65 if (found == process_sender_map_.end()) 93 if (found == process_sender_map_.end())
66 return false; 94 return false;
67 return found->second->Send(message); 95 return found->second->Send(message);
68 } 96 }
69 97
98 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
99 int embedded_worker_id) {
100 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
101 worker_map_.erase(embedded_worker_id);
102 worker_process_map_.erase(process_id);
103 }
104
70 } // namespace content 105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698