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/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/renderer_host/render_widget_helper.h" | 10 #include "content/browser/renderer_host/render_widget_helper.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 const base::string16& message, | 172 const base::string16& message, |
173 int line_number, | 173 int line_number, |
174 const GURL& source_url) { | 174 const GURL& source_url) { |
175 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); | 175 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); |
176 if (!worker) | 176 if (!worker) |
177 return; | 177 return; |
178 worker->OnReportConsoleMessage(source_identifier, message_level, message, | 178 worker->OnReportConsoleMessage(source_identifier, message_level, message, |
179 line_number, source_url); | 179 line_number, source_url); |
180 } | 180 } |
181 | 181 |
182 void EmbeddedWorkerRegistry::AddChildProcessSender( | 182 void EmbeddedWorkerRegistry::AddChildProcessSender(int process_id, |
183 int process_id, | 183 IPC::Sender* sender) { |
184 IPC::Sender* sender, | |
185 MessagePortMessageFilter* message_port_message_filter) { | |
186 process_sender_map_[process_id] = sender; | 184 process_sender_map_[process_id] = sender; |
187 process_message_port_message_filter_map_[process_id] = | |
188 message_port_message_filter; | |
189 DCHECK(!base::ContainsKey(worker_process_map_, process_id)); | 185 DCHECK(!base::ContainsKey(worker_process_map_, process_id)); |
190 } | 186 } |
191 | 187 |
192 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) { | 188 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) { |
193 process_sender_map_.erase(process_id); | 189 process_sender_map_.erase(process_id); |
194 process_message_port_message_filter_map_.erase(process_id); | |
195 std::map<int, std::set<int> >::iterator found = | 190 std::map<int, std::set<int> >::iterator found = |
196 worker_process_map_.find(process_id); | 191 worker_process_map_.find(process_id); |
197 if (found != worker_process_map_.end()) { | 192 if (found != worker_process_map_.end()) { |
198 const std::set<int>& worker_set = worker_process_map_[process_id]; | 193 const std::set<int>& worker_set = worker_process_map_[process_id]; |
199 for (std::set<int>::const_iterator it = worker_set.begin(); | 194 for (std::set<int>::const_iterator it = worker_set.begin(); |
200 it != worker_set.end(); | 195 it != worker_set.end(); |
201 ++it) { | 196 ++it) { |
202 int embedded_worker_id = *it; | 197 int embedded_worker_id = *it; |
203 DCHECK(base::ContainsKey(worker_map_, embedded_worker_id)); | 198 DCHECK(base::ContainsKey(worker_map_, embedded_worker_id)); |
204 // Somehow the worker thread has lost contact with the browser process. | 199 // Somehow the worker thread has lost contact with the browser process. |
(...skipping 15 matching lines...) Expand all Loading... |
220 } | 215 } |
221 | 216 |
222 bool EmbeddedWorkerRegistry::CanHandle(int embedded_worker_id) const { | 217 bool EmbeddedWorkerRegistry::CanHandle(int embedded_worker_id) const { |
223 if (embedded_worker_id < initial_embedded_worker_id_ || | 218 if (embedded_worker_id < initial_embedded_worker_id_ || |
224 next_embedded_worker_id_ <= embedded_worker_id) { | 219 next_embedded_worker_id_ <= embedded_worker_id) { |
225 return false; | 220 return false; |
226 } | 221 } |
227 return true; | 222 return true; |
228 } | 223 } |
229 | 224 |
230 MessagePortMessageFilter* | |
231 EmbeddedWorkerRegistry::MessagePortMessageFilterForProcess(int process_id) { | |
232 return process_message_port_message_filter_map_[process_id]; | |
233 } | |
234 | |
235 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( | 225 EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( |
236 const base::WeakPtr<ServiceWorkerContextCore>& context, | 226 const base::WeakPtr<ServiceWorkerContextCore>& context, |
237 int initial_embedded_worker_id) | 227 int initial_embedded_worker_id) |
238 : context_(context), | 228 : context_(context), |
239 next_embedded_worker_id_(initial_embedded_worker_id), | 229 next_embedded_worker_id_(initial_embedded_worker_id), |
240 initial_embedded_worker_id_(initial_embedded_worker_id) { | 230 initial_embedded_worker_id_(initial_embedded_worker_id) { |
241 } | 231 } |
242 | 232 |
243 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { | 233 EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { |
244 Shutdown(); | 234 Shutdown(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); | 285 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); |
296 if (!worker || worker->process_id() != process_id) { | 286 if (!worker || worker->process_id() != process_id) { |
297 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); | 287 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); |
298 return nullptr; | 288 return nullptr; |
299 } | 289 } |
300 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); | 290 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); |
301 return worker; | 291 return worker; |
302 } | 292 } |
303 | 293 |
304 } // namespace content | 294 } // namespace content |
OLD | NEW |