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/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/embedded_worker_messages.h" | 10 #include "content/common/service_worker/embedded_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 LOG(ERROR) << "Adding EmbeddedWorkerInstance with id " |
| 25 << next_embedded_worker_id_; |
24 worker_map_[next_embedded_worker_id_++] = worker.get(); | 26 worker_map_[next_embedded_worker_id_++] = worker.get(); |
25 return worker.Pass(); | 27 return worker.Pass(); |
26 } | 28 } |
27 | 29 |
28 bool EmbeddedWorkerRegistry::StartWorker( | 30 bool EmbeddedWorkerRegistry::StartWorker( |
29 int process_id, | 31 int process_id, |
30 int embedded_worker_id, | 32 int embedded_worker_id, |
31 int64 service_worker_version_id, | 33 int64 service_worker_version_id, |
32 const GURL& script_url) { | 34 const GURL& script_url) { |
33 return Send(process_id, | 35 return Send(process_id, |
34 new EmbeddedWorkerMsg_StartWorker(embedded_worker_id, | 36 new EmbeddedWorkerMsg_StartWorker(embedded_worker_id, |
35 service_worker_version_id, | 37 service_worker_version_id, |
36 script_url)); | 38 script_url)); |
37 } | 39 } |
38 | 40 |
39 bool EmbeddedWorkerRegistry::StopWorker(int process_id, | 41 bool EmbeddedWorkerRegistry::StopWorker(int process_id, |
40 int embedded_worker_id) { | 42 int embedded_worker_id) { |
41 return Send(process_id, | 43 return Send(process_id, |
42 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); | 44 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); |
43 } | 45 } |
44 | 46 |
45 void EmbeddedWorkerRegistry::OnWorkerStarted( | 47 void EmbeddedWorkerRegistry::OnWorkerStarted( |
46 int process_id, int thread_id, int embedded_worker_id) { | 48 int process_id, int thread_id, int embedded_worker_id) { |
| 49 LOG(ERROR) << "OnWorkerStarted(" << process_id << ", " << thread_id << ", " |
| 50 << embedded_worker_id << ")"; |
47 DCHECK(!ContainsKey(worker_process_map_, process_id)); | 51 DCHECK(!ContainsKey(worker_process_map_, process_id)); |
48 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); | 52 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
49 if (found == worker_map_.end()) { | 53 if (found == worker_map_.end()) { |
50 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; | 54 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; |
51 return; | 55 return; |
52 } | 56 } |
53 worker_process_map_[process_id] = embedded_worker_id; | 57 worker_process_map_[process_id] = embedded_worker_id; |
54 DCHECK_EQ(found->second->process_id(), process_id); | 58 DCHECK_EQ(found->second->process_id(), process_id); |
55 found->second->OnStarted(thread_id); | 59 found->second->OnStarted(thread_id); |
56 } | 60 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 int embedded_worker_id) { | 105 int embedded_worker_id) { |
102 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); | 106 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
103 if (found == worker_map_.end()) | 107 if (found == worker_map_.end()) |
104 return NULL; | 108 return NULL; |
105 return found->second; | 109 return found->second; |
106 } | 110 } |
107 | 111 |
108 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {} | 112 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() {} |
109 | 113 |
110 bool EmbeddedWorkerRegistry::Send(int process_id, IPC::Message* message) { | 114 bool EmbeddedWorkerRegistry::Send(int process_id, IPC::Message* message) { |
111 if (!context_) | 115 if (!context_) { |
| 116 LOG(ERROR) << "No context, bailing on the send"; |
112 return false; | 117 return false; |
| 118 } |
113 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); | 119 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); |
114 if (found == process_sender_map_.end()) | 120 if (found == process_sender_map_.end()) { |
| 121 LOG(ERROR) << "sender not found for pid " << process_id; |
115 return false; | 122 return false; |
| 123 } |
| 124 LOG(ERROR) << "Sending message to " << process_id; |
116 return found->second->Send(message); | 125 return found->second->Send(message); |
117 } | 126 } |
118 | 127 |
119 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, | 128 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, |
120 int embedded_worker_id) { | 129 int embedded_worker_id) { |
121 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); | 130 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); |
122 worker_map_.erase(embedded_worker_id); | 131 worker_map_.erase(embedded_worker_id); |
123 worker_process_map_.erase(process_id); | 132 worker_process_map_.erase(process_id); |
124 } | 133 } |
125 | 134 |
126 } // namespace content | 135 } // namespace content |
OLD | NEW |