Index: content/renderer/websharedworker_proxy.cc |
diff --git a/content/renderer/websharedworker_proxy.cc b/content/renderer/websharedworker_proxy.cc |
index 212521363e2c0aaf17604c7b8e77afd4bc66d600..893413e244f086c3e3af6786feb006d12028f4b4 100644 |
--- a/content/renderer/websharedworker_proxy.cc |
+++ b/content/renderer/websharedworker_proxy.cc |
@@ -29,42 +29,19 @@ WebSharedWorkerProxy::~WebSharedWorkerProxy() { |
router_->RemoveRoute(route_id_); |
} |
-bool WebSharedWorkerProxy::Send(std::unique_ptr<IPC::Message> message) { |
- // The worker object can be interacted with before the browser process told us |
- // that it started, in which case we want to queue the message. |
- if (!created_) { |
- queued_messages_.push_back(std::move(message)); |
- return true; |
- } |
- |
- // For now we proxy all messages to the worker process through the browser. |
- // Revisit if we find this slow. |
- // TODO(jabdelmalek): handle sync messages if we need them. |
- return router_->Send(message.release()); |
-} |
- |
-void WebSharedWorkerProxy::SendQueuedMessages() { |
- DCHECK(created_); |
- DCHECK(queued_messages_.size()); |
- std::vector<std::unique_ptr<IPC::Message>> queued_messages; |
- queued_messages.swap(queued_messages_); |
- for (size_t i = 0; i < queued_messages.size(); ++i) { |
- queued_messages[i]->set_routing_id(route_id_); |
- Send(std::move(queued_messages[i])); |
- } |
-} |
- |
void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel, |
ConnectListener* listener) { |
- WebMessagePortChannelImpl* webchannel = |
- static_cast<WebMessagePortChannelImpl*>(channel); |
+ // Accept ownership of the channel. |
+ std::unique_ptr<WebMessagePortChannelImpl> channel_impl( |
+ static_cast<WebMessagePortChannelImpl*>(channel)); |
- int message_port_id = webchannel->message_port_id(); |
- DCHECK_NE(MSG_ROUTING_NONE, message_port_id); |
- webchannel->QueueMessages(); |
+ DCHECK(!queued_connect_message_); |
+ |
+ queued_connect_message_ = base::MakeUnique<ViewHostMsg_ConnectToWorker>( |
+ route_id_, channel_impl->ReleaseMessagePort()); |
+ if (created_) |
+ router_->Send(queued_connect_message_.release()); |
- Send(base::MakeUnique<ViewHostMsg_ConnectToWorker>(route_id_, |
- message_port_id)); |
connect_listener_ = listener; |
} |
@@ -83,8 +60,10 @@ bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { |
void WebSharedWorkerProxy::OnWorkerCreated() { |
created_ = true; |
- // The worker is created - now send off the WorkerMsg_Connect message. |
- SendQueuedMessages(); |
+ |
+ // The worker is created - now send off the connect message. |
+ if (queued_connect_message_) |
+ router_->Send(queued_connect_message_.release()); |
} |
void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() { |