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

Side by Side Diff: content/browser/shared_worker/shared_worker_host.cc

Issue 2601893002: SharedWorker: Remove message forwarding mechanism (Closed)
Patch Set: style fix Created 3 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
OLDNEW
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (const FilterInfo& info : filters_) 97 for (const FilterInfo& info : filters_)
98 info.filter()->Send(new ViewMsg_WorkerCreated(info.route_id())); 98 info.filter()->Send(new ViewMsg_WorkerCreated(info.route_id()));
99 } 99 }
100 100
101 bool SharedWorkerHost::FilterMessage(const IPC::Message& message, 101 bool SharedWorkerHost::FilterConnectionMessage(
102 SharedWorkerMessageFilter* filter) { 102 int route_id,
103 if (!IsAvailable() || !HasFilter(filter, message.routing_id())) 103 int sent_message_port_id,
104 SharedWorkerMessageFilter* incoming_filter) {
105 if (!IsAvailable() || !HasFilter(incoming_filter, route_id))
104 return false; 106 return false;
105 107
106 RelayMessage(message, filter); 108 Connect(route_id, sent_message_port_id, incoming_filter);
107 return true; 109 return true;
108 } 110 }
109 111
110 void SharedWorkerHost::FilterShutdown(SharedWorkerMessageFilter* filter) { 112 void SharedWorkerHost::FilterShutdown(SharedWorkerMessageFilter* filter) {
111 if (!instance_) 113 if (!instance_)
112 return; 114 return;
113 RemoveFilters(filter); 115 RemoveFilters(filter);
114 worker_document_set_->RemoveAll(filter); 116 worker_document_set_->RemoveAll(filter);
115 if (worker_document_set_->IsEmpty()) { 117 if (worker_document_set_->IsEmpty()) {
116 // This worker has no more associated documents - shut it down. 118 // This worker has no more associated documents - shut it down.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 217
216 void SharedWorkerHost::AllowIndexedDB(const GURL& url, 218 void SharedWorkerHost::AllowIndexedDB(const GURL& url,
217 const base::string16& name, 219 const base::string16& name,
218 bool* result) { 220 bool* result) {
219 if (!instance_) 221 if (!instance_)
220 return; 222 return;
221 *result = GetContentClient()->browser()->AllowWorkerIndexedDB( 223 *result = GetContentClient()->browser()->AllowWorkerIndexedDB(
222 url, name, instance_->resource_context(), GetRenderFrameIDsForWorker()); 224 url, name, instance_->resource_context(), GetRenderFrameIDsForWorker());
223 } 225 }
224 226
225 void SharedWorkerHost::RelayMessage(
226 const IPC::Message& message,
227 SharedWorkerMessageFilter* incoming_filter) {
228 if (!instance_)
229 return;
230 if (message.type() == WorkerMsg_Connect::ID) {
231 // Crack the SharedWorker Connect message to setup routing for the port.
232 WorkerMsg_Connect::Param param;
233 if (!WorkerMsg_Connect::Read(&message, &param))
234 return;
235 int sent_message_port_id = std::get<0>(param);
236 int new_routing_id = std::get<1>(param);
237
238 DCHECK(container_render_filter_);
239 new_routing_id = container_render_filter_->GetNextRoutingID();
240 MessagePortService::GetInstance()->UpdateMessagePort(
241 sent_message_port_id,
242 container_render_filter_->message_port_message_filter(),
243 new_routing_id);
244 SetMessagePortID(
245 incoming_filter, message.routing_id(), sent_message_port_id);
246 // Resend the message with the new routing id.
247 Send(new WorkerMsg_Connect(
248 worker_route_id_, sent_message_port_id, new_routing_id));
249
250 // Send any queued messages for the sent port.
251 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible(
252 sent_message_port_id);
253 } else {
254 IPC::Message* new_message = new IPC::Message(message);
255 new_message->set_routing_id(worker_route_id_);
256 Send(new_message);
257 return;
258 }
259 }
260
261 void SharedWorkerHost::TerminateWorker() { 227 void SharedWorkerHost::TerminateWorker() {
262 termination_message_sent_ = true; 228 termination_message_sent_ = true;
263 if (!closed_) 229 if (!closed_)
264 NotifyWorkerDestroyed(worker_process_id_, worker_route_id_); 230 NotifyWorkerDestroyed(worker_process_id_, worker_route_id_);
265 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id_)); 231 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id_));
266 } 232 }
267 233
268 std::vector<std::pair<int, int> > 234 std::vector<std::pair<int, int> >
269 SharedWorkerHost::GetRenderFrameIDsForWorker() { 235 SharedWorkerHost::GetRenderFrameIDsForWorker() {
270 std::vector<std::pair<int, int> > result; 236 std::vector<std::pair<int, int> > result;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 bool SharedWorkerHost::HasFilter(SharedWorkerMessageFilter* filter, 270 bool SharedWorkerHost::HasFilter(SharedWorkerMessageFilter* filter,
305 int route_id) const { 271 int route_id) const {
306 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end(); 272 for (FilterList::const_iterator i = filters_.begin(); i != filters_.end();
307 ++i) { 273 ++i) {
308 if (i->filter() == filter && i->route_id() == route_id) 274 if (i->filter() == filter && i->route_id() == route_id)
309 return true; 275 return true;
310 } 276 }
311 return false; 277 return false;
312 } 278 }
313 279
280 void SharedWorkerHost::Connect(int route_id,
281 int sent_message_port_id,
282 SharedWorkerMessageFilter* incoming_filter) {
283 DCHECK(IsAvailable());
284 DCHECK(HasFilter(incoming_filter, route_id));
285 DCHECK(container_render_filter_);
286
287 int new_routing_id = container_render_filter_->GetNextRoutingID();
288 MessagePortService::GetInstance()->UpdateMessagePort(
289 sent_message_port_id,
290 container_render_filter_->message_port_message_filter(), new_routing_id);
291 SetMessagePortID(incoming_filter, route_id, sent_message_port_id);
292 Send(new WorkerMsg_Connect(worker_route_id_, sent_message_port_id,
293 new_routing_id));
294
295 // Send any queued messages for the sent port.
296 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible(
297 sent_message_port_id);
298 }
299
314 void SharedWorkerHost::SetMessagePortID(SharedWorkerMessageFilter* filter, 300 void SharedWorkerHost::SetMessagePortID(SharedWorkerMessageFilter* filter,
315 int route_id, 301 int route_id,
316 int message_port_id) { 302 int message_port_id) {
317 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { 303 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) {
318 if (i->filter() == filter && i->route_id() == route_id) { 304 if (i->filter() == filter && i->route_id() == route_id) {
319 i->set_message_port_id(message_port_id); 305 i->set_message_port_id(message_port_id);
320 return; 306 return;
321 } 307 }
322 } 308 }
323 } 309 }
324 310
325 } // namespace content 311 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/shared_worker/shared_worker_host.h ('k') | content/browser/shared_worker/shared_worker_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698