OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shared_worker/shared_worker_host.h" | 5 #include "content/browser/shared_worker/shared_worker_host.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "content/browser/devtools/shared_worker_devtools_manager.h" | 8 #include "content/browser/devtools/shared_worker_devtools_manager.h" |
9 #include "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 WorkerProcessMsg_CreateWorker_Params params; | 87 WorkerProcessMsg_CreateWorker_Params params; |
88 params.url = instance_->url(); | 88 params.url = instance_->url(); |
89 params.name = instance_->name(); | 89 params.name = instance_->name(); |
90 params.content_security_policy = instance_->content_security_policy(); | 90 params.content_security_policy = instance_->content_security_policy(); |
91 params.security_policy_type = instance_->security_policy_type(); | 91 params.security_policy_type = instance_->security_policy_type(); |
92 params.creation_address_space = instance_->creation_address_space(); | 92 params.creation_address_space = instance_->creation_address_space(); |
93 params.pause_on_start = pause_on_start; | 93 params.pause_on_start = pause_on_start; |
94 params.route_id = worker_route_id_; | 94 params.route_id = worker_route_id_; |
95 Send(new WorkerProcessMsg_CreateWorker(params)); | 95 Send(new WorkerProcessMsg_CreateWorker(params)); |
96 | 96 |
97 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); | 97 for (const FilterInfo& info : filters_) |
98 ++i) { | 98 info.filter()->Send(new ViewMsg_WorkerCreated(info.route_id())); |
99 i->filter()->Send(new ViewMsg_WorkerCreated(i->route_id())); | |
100 } | |
101 } | 99 } |
102 | 100 |
103 bool SharedWorkerHost::FilterMessage(const IPC::Message& message, | 101 bool SharedWorkerHost::FilterMessage(const IPC::Message& message, |
104 SharedWorkerMessageFilter* filter) { | 102 SharedWorkerMessageFilter* filter) { |
105 if (!IsAvailable() || !HasFilter(filter, message.routing_id())) | 103 if (!IsAvailable() || !HasFilter(filter, message.routing_id())) |
106 return false; | 104 return false; |
107 | 105 |
108 RelayMessage(message, filter); | 106 RelayMessage(message, filter); |
109 return true; | 107 return true; |
110 } | 108 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 void SharedWorkerHost::WorkerScriptLoaded() { | 168 void SharedWorkerHost::WorkerScriptLoaded() { |
171 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoaded", | 169 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoaded", |
172 base::TimeTicks::Now() - creation_time_); | 170 base::TimeTicks::Now() - creation_time_); |
173 } | 171 } |
174 | 172 |
175 void SharedWorkerHost::WorkerScriptLoadFailed() { | 173 void SharedWorkerHost::WorkerScriptLoadFailed() { |
176 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed", | 174 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed", |
177 base::TimeTicks::Now() - creation_time_); | 175 base::TimeTicks::Now() - creation_time_); |
178 if (!instance_) | 176 if (!instance_) |
179 return; | 177 return; |
180 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); | 178 for (const FilterInfo& info : filters_) |
181 ++i) { | 179 info.filter()->Send(new ViewMsg_WorkerScriptLoadFailed(info.route_id())); |
182 i->filter()->Send(new ViewMsg_WorkerScriptLoadFailed(i->route_id())); | |
183 } | |
184 } | 180 } |
185 | 181 |
186 void SharedWorkerHost::WorkerConnected(int message_port_id) { | 182 void SharedWorkerHost::WorkerConnected(int message_port_id) { |
187 if (!instance_) | 183 if (!instance_) |
188 return; | 184 return; |
189 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); | 185 for (const FilterInfo& info : filters_) { |
190 ++i) { | 186 if (info.message_port_id() != message_port_id) |
191 if (i->message_port_id() != message_port_id) | |
192 continue; | 187 continue; |
193 i->filter()->Send(new ViewMsg_WorkerConnected(i->route_id())); | 188 info.filter()->Send(new ViewMsg_WorkerConnected(info.route_id())); |
194 return; | 189 return; |
195 } | 190 } |
196 } | 191 } |
197 | 192 |
198 void SharedWorkerHost::AllowFileSystem( | 193 void SharedWorkerHost::AllowFileSystem( |
199 const GURL& url, | 194 const GURL& url, |
200 std::unique_ptr<IPC::Message> reply_msg) { | 195 std::unique_ptr<IPC::Message> reply_msg) { |
201 if (!instance_) | 196 if (!instance_) |
202 return; | 197 return; |
203 GetContentClient()->browser()->AllowWorkerFileSystem( | 198 GetContentClient()->browser()->AllowWorkerFileSystem( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id_)); | 265 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id_)); |
271 } | 266 } |
272 | 267 |
273 std::vector<std::pair<int, int> > | 268 std::vector<std::pair<int, int> > |
274 SharedWorkerHost::GetRenderFrameIDsForWorker() { | 269 SharedWorkerHost::GetRenderFrameIDsForWorker() { |
275 std::vector<std::pair<int, int> > result; | 270 std::vector<std::pair<int, int> > result; |
276 if (!instance_) | 271 if (!instance_) |
277 return result; | 272 return result; |
278 const WorkerDocumentSet::DocumentInfoSet& documents = | 273 const WorkerDocumentSet::DocumentInfoSet& documents = |
279 worker_document_set_->documents(); | 274 worker_document_set_->documents(); |
280 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = | 275 for (const WorkerDocumentSet::DocumentInfo& doc : documents) { |
281 documents.begin(); | |
282 doc != documents.end(); | |
283 ++doc) { | |
284 result.push_back( | 276 result.push_back( |
285 std::make_pair(doc->render_process_id(), doc->render_frame_id())); | 277 std::make_pair(doc.render_process_id(), doc.render_frame_id())); |
286 } | 278 } |
287 return result; | 279 return result; |
288 } | 280 } |
289 | 281 |
290 bool SharedWorkerHost::IsAvailable() const { | 282 bool SharedWorkerHost::IsAvailable() const { |
291 return instance_ && !termination_message_sent_ && !closed_; | 283 return instance_ && !termination_message_sent_ && !closed_; |
292 } | 284 } |
293 | 285 |
294 void SharedWorkerHost::AddFilter(SharedWorkerMessageFilter* filter, | 286 void SharedWorkerHost::AddFilter(SharedWorkerMessageFilter* filter, |
295 int route_id) { | 287 int route_id) { |
(...skipping 28 matching lines...) Expand all Loading... |
324 int message_port_id) { | 316 int message_port_id) { |
325 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { | 317 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { |
326 if (i->filter() == filter && i->route_id() == route_id) { | 318 if (i->filter() == filter && i->route_id() == route_id) { |
327 i->set_message_port_id(message_port_id); | 319 i->set_message_port_id(message_port_id); |
328 return; | 320 return; |
329 } | 321 } |
330 } | 322 } |
331 } | 323 } |
332 | 324 |
333 } // namespace content | 325 } // namespace content |
OLD | NEW |