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

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

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Address feedback from yusuf Created 3 years, 10 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"
10 #include "content/browser/message_port_service.h"
11 #include "content/browser/shared_worker/shared_worker_instance.h" 9 #include "content/browser/shared_worker/shared_worker_instance.h"
12 #include "content/browser/shared_worker/shared_worker_message_filter.h" 10 #include "content/browser/shared_worker/shared_worker_message_filter.h"
13 #include "content/browser/shared_worker/shared_worker_service_impl.h" 11 #include "content/browser/shared_worker/shared_worker_service_impl.h"
14 #include "content/common/view_messages.h" 12 #include "content/common/view_messages.h"
15 #include "content/common/worker_messages.h" 13 #include "content/common/worker_messages.h"
16 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
18 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
19 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
20 18
(...skipping 29 matching lines...) Expand all
50 } // namespace 48 } // namespace
51 49
52 SharedWorkerHost::SharedWorkerHost(SharedWorkerInstance* instance, 50 SharedWorkerHost::SharedWorkerHost(SharedWorkerInstance* instance,
53 SharedWorkerMessageFilter* filter, 51 SharedWorkerMessageFilter* filter,
54 int worker_route_id) 52 int worker_route_id)
55 : instance_(instance), 53 : instance_(instance),
56 worker_document_set_(new WorkerDocumentSet()), 54 worker_document_set_(new WorkerDocumentSet()),
57 worker_render_filter_(filter), 55 worker_render_filter_(filter),
58 worker_process_id_(filter->render_process_id()), 56 worker_process_id_(filter->render_process_id()),
59 worker_route_id_(worker_route_id), 57 worker_route_id_(worker_route_id),
58 next_connection_request_id_(1),
60 creation_time_(base::TimeTicks::Now()), 59 creation_time_(base::TimeTicks::Now()),
61 weak_factory_(this) { 60 weak_factory_(this) {
62 DCHECK_CURRENTLY_ON(BrowserThread::IO); 61 DCHECK_CURRENTLY_ON(BrowserThread::IO);
63 DCHECK(instance_); 62 DCHECK(instance_);
64 DCHECK(worker_render_filter_); 63 DCHECK(worker_render_filter_);
65 } 64 }
66 65
67 SharedWorkerHost::~SharedWorkerHost() { 66 SharedWorkerHost::~SharedWorkerHost() {
68 DCHECK_CURRENTLY_ON(BrowserThread::IO); 67 DCHECK_CURRENTLY_ON(BrowserThread::IO);
69 UMA_HISTOGRAM_LONG_TIMES("SharedWorker.TimeToDeleted", 68 UMA_HISTOGRAM_LONG_TIMES("SharedWorker.TimeToDeleted",
(...skipping 12 matching lines...) Expand all
82 params.security_policy_type = instance_->security_policy_type(); 81 params.security_policy_type = instance_->security_policy_type();
83 params.creation_address_space = instance_->creation_address_space(); 82 params.creation_address_space = instance_->creation_address_space();
84 params.pause_on_start = pause_on_start; 83 params.pause_on_start = pause_on_start;
85 params.route_id = worker_route_id_; 84 params.route_id = worker_route_id_;
86 Send(new WorkerProcessMsg_CreateWorker(params)); 85 Send(new WorkerProcessMsg_CreateWorker(params));
87 86
88 for (const FilterInfo& info : filters_) 87 for (const FilterInfo& info : filters_)
89 info.filter()->Send(new ViewMsg_WorkerCreated(info.route_id())); 88 info.filter()->Send(new ViewMsg_WorkerCreated(info.route_id()));
90 } 89 }
91 90
92 bool SharedWorkerHost::FilterConnectionMessage( 91 bool SharedWorkerHost::SendConnectToWorker(int worker_route_id,
93 int route_id, 92 const MessagePort& port,
94 int sent_message_port_id, 93 SharedWorkerMessageFilter* filter) {
95 SharedWorkerMessageFilter* incoming_filter) { 94 if (!IsAvailable() || !HasFilter(filter, worker_route_id))
96 if (!IsAvailable() || !HasFilter(incoming_filter, route_id))
97 return false; 95 return false;
98 96
99 Connect(route_id, sent_message_port_id, incoming_filter); 97 int connection_request_id = next_connection_request_id_++;
98
99 SetConnectionRequestID(filter, worker_route_id, connection_request_id);
100
101 // Send the connect message with the new connection_request_id.
102 Send(new WorkerMsg_Connect(worker_route_id_, connection_request_id, port));
100 return true; 103 return true;
101 } 104 }
102 105
103 void SharedWorkerHost::FilterShutdown(SharedWorkerMessageFilter* filter) { 106 void SharedWorkerHost::FilterShutdown(SharedWorkerMessageFilter* filter) {
104 RemoveFilters(filter); 107 RemoveFilters(filter);
105 worker_document_set_->RemoveAll(filter); 108 worker_document_set_->RemoveAll(filter);
106 if (worker_document_set_->IsEmpty()) { 109 if (worker_document_set_->IsEmpty()) {
107 // This worker has no more associated documents - shut it down. 110 // This worker has no more associated documents - shut it down.
108 TerminateWorker(); 111 TerminateWorker();
109 } 112 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 base::TimeTicks::Now() - creation_time_); 151 base::TimeTicks::Now() - creation_time_);
149 } 152 }
150 153
151 void SharedWorkerHost::WorkerScriptLoadFailed() { 154 void SharedWorkerHost::WorkerScriptLoadFailed() {
152 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed", 155 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed",
153 base::TimeTicks::Now() - creation_time_); 156 base::TimeTicks::Now() - creation_time_);
154 for (const FilterInfo& info : filters_) 157 for (const FilterInfo& info : filters_)
155 info.filter()->Send(new ViewMsg_WorkerScriptLoadFailed(info.route_id())); 158 info.filter()->Send(new ViewMsg_WorkerScriptLoadFailed(info.route_id()));
156 } 159 }
157 160
158 void SharedWorkerHost::WorkerConnected(int message_port_id) { 161 void SharedWorkerHost::WorkerConnected(int connection_request_id) {
162 if (!instance_)
163 return;
159 for (const FilterInfo& info : filters_) { 164 for (const FilterInfo& info : filters_) {
160 if (info.message_port_id() != message_port_id) 165 if (info.connection_request_id() != connection_request_id)
161 continue; 166 continue;
162 info.filter()->Send(new ViewMsg_WorkerConnected(info.route_id())); 167 info.filter()->Send(new ViewMsg_WorkerConnected(info.route_id()));
163 return; 168 return;
164 } 169 }
165 } 170 }
166 171
167 void SharedWorkerHost::AllowFileSystem( 172 void SharedWorkerHost::AllowFileSystem(
168 const GURL& url, 173 const GURL& url,
169 std::unique_ptr<IPC::Message> reply_msg) { 174 std::unique_ptr<IPC::Message> reply_msg) {
170 GetContentClient()->browser()->AllowWorkerFileSystem( 175 GetContentClient()->browser()->AllowWorkerFileSystem(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 240
236 bool SharedWorkerHost::HasFilter(SharedWorkerMessageFilter* filter, 241 bool SharedWorkerHost::HasFilter(SharedWorkerMessageFilter* filter,
237 int route_id) const { 242 int route_id) const {
238 for (const FilterInfo& info : filters_) { 243 for (const FilterInfo& info : filters_) {
239 if (info.filter() == filter && info.route_id() == route_id) 244 if (info.filter() == filter && info.route_id() == route_id)
240 return true; 245 return true;
241 } 246 }
242 return false; 247 return false;
243 } 248 }
244 249
245 void SharedWorkerHost::Connect(int route_id, 250 void SharedWorkerHost::SetConnectionRequestID(SharedWorkerMessageFilter* filter,
246 int sent_message_port_id, 251 int route_id,
247 SharedWorkerMessageFilter* incoming_filter) { 252 int connection_request_id) {
248 DCHECK(IsAvailable()); 253 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) {
249 DCHECK(HasFilter(incoming_filter, route_id)); 254 if (i->filter() == filter && i->route_id() == route_id) {
250 DCHECK(worker_render_filter_); 255 i->set_connection_request_id(connection_request_id);
251
252 int new_routing_id = worker_render_filter_->GetNextRoutingID();
253 MessagePortService::GetInstance()->UpdateMessagePort(
254 sent_message_port_id,
255 worker_render_filter_->message_port_message_filter(), new_routing_id);
256 SetMessagePortID(incoming_filter, route_id, sent_message_port_id);
257 Send(new WorkerMsg_Connect(worker_route_id_, sent_message_port_id,
258 new_routing_id));
259
260 // Send any queued messages for the sent port.
261 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible(
262 sent_message_port_id);
263 }
264
265 void SharedWorkerHost::SetMessagePortID(SharedWorkerMessageFilter* filter,
266 int route_id,
267 int message_port_id) {
268 for (FilterInfo& info : filters_) {
269 if (info.filter() == filter && info.route_id() == route_id) {
270 info.set_message_port_id(message_port_id);
271 return; 256 return;
272 } 257 }
273 } 258 }
274 } 259 }
275 260
276 bool SharedWorkerHost::Send(IPC::Message* message) { 261 bool SharedWorkerHost::Send(IPC::Message* message) {
277 return worker_render_filter_->Send(message); 262 return worker_render_filter_->Send(message);
278 } 263 }
279 264
280 } // namespace content 265 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698