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

Side by Side Diff: content/renderer/websharedworker_proxy.cc

Issue 2601893002: SharedWorker: Remove message forwarding mechanism (Closed)
Patch Set: 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/renderer/websharedworker_proxy.h" 5 #include "content/renderer/websharedworker_proxy.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "content/child/webmessageportchannel_impl.h" 9 #include "content/child/webmessageportchannel_impl.h"
10 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
(...skipping 26 matching lines...) Expand all
37 // terminate independently, already sent messages may still be in the pipe. 37 // terminate independently, already sent messages may still be in the pipe.
38 router_->RemoveRoute(route_id_); 38 router_->RemoveRoute(route_id_);
39 39
40 route_id_ = MSG_ROUTING_NONE; 40 route_id_ = MSG_ROUTING_NONE;
41 } 41 }
42 42
43 bool WebSharedWorkerProxy::Send(std::unique_ptr<IPC::Message> message) { 43 bool WebSharedWorkerProxy::Send(std::unique_ptr<IPC::Message> message) {
44 // It's possible that messages will be sent before the worker is created, in 44 // It's possible that messages will be sent before the worker is created, in
45 // which case route_id_ will be none. Or the worker object can be interacted 45 // which case route_id_ will be none. Or the worker object can be interacted
46 // with before the browser process told us that it started, in which case we 46 // with before the browser process told us that it started, in which case we
47 // also want to queue the message. 47 // also want to queue the message.
nhiroki 2016/12/28 08:04:20 Question: How is the case where |route_id_| is non
nhiroki 2016/12/28 08:16:19 I understand this. A route_id passed to the ctor o
nhiroki 2016/12/28 09:48:26 Created a patch: https://codereview.chromium.org/2
48 if (!created_) { 48 if (!created_) {
49 queued_messages_.push_back(std::move(message)); 49 queued_messages_.push_back(std::move(message));
50 return true; 50 return true;
51 } 51 }
52 52
53 // For now we proxy all messages to the worker process through the browser. 53 // For now we proxy all messages to the worker process through the browser.
54 // Revisit if we find this slow. 54 // Revisit if we find this slow.
55 // TODO(jabdelmalek): handle sync messages if we need them. 55 // TODO(jabdelmalek): handle sync messages if we need them.
56 return router_->Send(new ViewHostMsg_ForwardToWorker(*message)); 56 return router_->Send(message.release());
57 } 57 }
58 58
59 void WebSharedWorkerProxy::SendQueuedMessages() { 59 void WebSharedWorkerProxy::SendQueuedMessages() {
60 DCHECK(created_); 60 DCHECK(created_);
61 DCHECK(queued_messages_.size()); 61 DCHECK(queued_messages_.size());
62 std::vector<std::unique_ptr<IPC::Message>> queued_messages; 62 std::vector<std::unique_ptr<IPC::Message>> queued_messages;
63 queued_messages.swap(queued_messages_); 63 queued_messages.swap(queued_messages_);
64 for (size_t i = 0; i < queued_messages.size(); ++i) { 64 for (size_t i = 0; i < queued_messages.size(); ++i) {
65 queued_messages[i]->set_routing_id(route_id_); 65 queued_messages[i]->set_routing_id(route_id_);
66 Send(std::move(queued_messages[i])); 66 Send(std::move(queued_messages[i]));
67 } 67 }
68 } 68 }
69 69
70 void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel, 70 void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel,
71 ConnectListener* listener) { 71 ConnectListener* listener) {
72 WebMessagePortChannelImpl* webchannel = 72 WebMessagePortChannelImpl* webchannel =
73 static_cast<WebMessagePortChannelImpl*>(channel); 73 static_cast<WebMessagePortChannelImpl*>(channel);
74 74
75 int message_port_id = webchannel->message_port_id(); 75 int message_port_id = webchannel->message_port_id();
76 DCHECK_NE(MSG_ROUTING_NONE, message_port_id); 76 DCHECK_NE(MSG_ROUTING_NONE, message_port_id);
77 webchannel->QueueMessages(); 77 webchannel->QueueMessages();
78 78
79 Send(base::MakeUnique<WorkerMsg_Connect>(route_id_, message_port_id, 79 Send(base::MakeUnique<ViewHostMsg_ConnectToWorker>(route_id_,
80 MSG_ROUTING_NONE)); 80 message_port_id));
81 connect_listener_ = listener; 81 connect_listener_ = listener;
82 } 82 }
83 83
84 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { 84 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) {
85 bool handled = true; 85 bool handled = true;
86 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) 86 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message)
87 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) 87 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated)
88 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed, 88 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed,
89 OnWorkerScriptLoadFailed) 89 OnWorkerScriptLoadFailed)
90 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, 90 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected,
(...skipping 18 matching lines...) Expand all
109 } 109 }
110 110
111 void WebSharedWorkerProxy::OnWorkerConnected() { 111 void WebSharedWorkerProxy::OnWorkerConnected() {
112 if (connect_listener_) { 112 if (connect_listener_) {
113 // This can result in this object being freed. 113 // This can result in this object being freed.
114 connect_listener_->connected(); 114 connect_listener_->connected();
115 } 115 }
116 } 116 }
117 117
118 } // namespace content 118 } // namespace content
OLDNEW
« content/browser/shared_worker/shared_worker_service_impl.cc ('K') | « content/common/view_messages.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698