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

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

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Add missing ScopedAsyncTaskScheduler instance for the new unit tests; required by a recent change t… 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 base::TimeTicks::Now() - creation_time_); 167 base::TimeTicks::Now() - creation_time_);
165 } 168 }
166 169
167 void SharedWorkerHost::WorkerScriptLoadFailed() { 170 void SharedWorkerHost::WorkerScriptLoadFailed() {
168 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed", 171 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed",
169 base::TimeTicks::Now() - creation_time_); 172 base::TimeTicks::Now() - creation_time_);
170 for (const FilterInfo& info : filters_) 173 for (const FilterInfo& info : filters_)
171 info.filter()->Send(new ViewMsg_WorkerScriptLoadFailed(info.route_id())); 174 info.filter()->Send(new ViewMsg_WorkerScriptLoadFailed(info.route_id()));
172 } 175 }
173 176
174 void SharedWorkerHost::WorkerConnected(int message_port_id) { 177 void SharedWorkerHost::WorkerConnected(int connection_request_id) {
178 if (!instance_)
179 return;
175 for (const FilterInfo& info : filters_) { 180 for (const FilterInfo& info : filters_) {
176 if (info.message_port_id() != message_port_id) 181 if (info.connection_request_id() != connection_request_id)
177 continue; 182 continue;
178 info.filter()->Send( 183 info.filter()->Send(
179 new ViewMsg_WorkerConnected(info.route_id(), used_features_)); 184 new ViewMsg_WorkerConnected(info.route_id(), used_features_));
180 return; 185 return;
181 } 186 }
182 } 187 }
183 188
184 void SharedWorkerHost::AllowFileSystem( 189 void SharedWorkerHost::AllowFileSystem(
185 const GURL& url, 190 const GURL& url,
186 std::unique_ptr<IPC::Message> reply_msg) { 191 std::unique_ptr<IPC::Message> reply_msg) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 257
253 bool SharedWorkerHost::HasFilter(SharedWorkerMessageFilter* filter, 258 bool SharedWorkerHost::HasFilter(SharedWorkerMessageFilter* filter,
254 int route_id) const { 259 int route_id) const {
255 for (const FilterInfo& info : filters_) { 260 for (const FilterInfo& info : filters_) {
256 if (info.filter() == filter && info.route_id() == route_id) 261 if (info.filter() == filter && info.route_id() == route_id)
257 return true; 262 return true;
258 } 263 }
259 return false; 264 return false;
260 } 265 }
261 266
262 void SharedWorkerHost::Connect(int route_id, 267 void SharedWorkerHost::SetConnectionRequestID(SharedWorkerMessageFilter* filter,
263 int sent_message_port_id, 268 int route_id,
264 SharedWorkerMessageFilter* incoming_filter) { 269 int connection_request_id) {
265 DCHECK(IsAvailable()); 270 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) {
266 DCHECK(HasFilter(incoming_filter, route_id)); 271 if (i->filter() == filter && i->route_id() == route_id) {
267 DCHECK(worker_render_filter_); 272 i->set_connection_request_id(connection_request_id);
268
269 int new_routing_id = worker_render_filter_->GetNextRoutingID();
270 MessagePortService::GetInstance()->UpdateMessagePort(
271 sent_message_port_id,
272 worker_render_filter_->message_port_message_filter(), new_routing_id);
273 SetMessagePortID(incoming_filter, route_id, sent_message_port_id);
274 Send(new WorkerMsg_Connect(worker_route_id_, sent_message_port_id,
275 new_routing_id));
276
277 // Send any queued messages for the sent port.
278 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible(
279 sent_message_port_id);
280 }
281
282 void SharedWorkerHost::SetMessagePortID(SharedWorkerMessageFilter* filter,
283 int route_id,
284 int message_port_id) {
285 for (FilterInfo& info : filters_) {
286 if (info.filter() == filter && info.route_id() == route_id) {
287 info.set_message_port_id(message_port_id);
288 return; 273 return;
289 } 274 }
290 } 275 }
291 } 276 }
292 277
293 bool SharedWorkerHost::Send(IPC::Message* message) { 278 bool SharedWorkerHost::Send(IPC::Message* message) {
294 return worker_render_filter_->Send(message); 279 return worker_render_filter_->Send(message);
295 } 280 }
296 281
297 } // namespace content 282 } // 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