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

Unified Diff: content/renderer/websharedworker_proxy.cc

Issue 2612043004: SharedWorker: Simplify message queueing mechanism in WebSharedWorkerProxy (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/websharedworker_proxy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/websharedworker_proxy.cc
diff --git a/content/renderer/websharedworker_proxy.cc b/content/renderer/websharedworker_proxy.cc
index 212521363e2c0aaf17604c7b8e77afd4bc66d600..61ea7f9c21762fe6b6bc20150d31e3eda2bdf815 100644
--- a/content/renderer/websharedworker_proxy.cc
+++ b/content/renderer/websharedworker_proxy.cc
@@ -10,8 +10,6 @@
#include "content/common/view_messages.h"
#include "content/common/worker_messages.h"
#include "ipc/message_router.h"
-#include "third_party/WebKit/public/platform/WebURL.h"
-#include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
namespace content {
@@ -19,8 +17,8 @@ WebSharedWorkerProxy::WebSharedWorkerProxy(IPC::MessageRouter* router,
int route_id)
: route_id_(route_id),
router_(router),
- connect_listener_(nullptr),
- created_(false) {
+ message_port_id_(MSG_ROUTING_NONE),
+ connect_listener_(nullptr) {
DCHECK_NE(MSG_ROUTING_NONE, route_id_);
router_->AddRoute(route_id_, this);
}
@@ -29,43 +27,15 @@ 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) {
horo 2017/01/06 06:59:45 DCHECK_EQ(MSG_ROUTING_NONE, message_port_id_);
nhiroki 2017/01/06 07:20:47 Done.
WebMessagePortChannelImpl* webchannel =
static_cast<WebMessagePortChannelImpl*>(channel);
-
- int message_port_id = webchannel->message_port_id();
- DCHECK_NE(MSG_ROUTING_NONE, message_port_id);
+ message_port_id_ = webchannel->message_port_id();
+ DCHECK_NE(MSG_ROUTING_NONE, message_port_id_);
webchannel->QueueMessages();
-
- Send(base::MakeUnique<ViewHostMsg_ConnectToWorker>(route_id_,
- message_port_id));
connect_listener_ = listener;
+ // An actual connection request will be issued on OnWorkerCreated().
}
bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) {
@@ -82,9 +52,12 @@ bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) {
}
void WebSharedWorkerProxy::OnWorkerCreated() {
- created_ = true;
- // The worker is created - now send off the WorkerMsg_Connect message.
- SendQueuedMessages();
+ // connect() should be called before.
+ DCHECK_NE(MSG_ROUTING_NONE, message_port_id_);
+
+ // The worker is created - now send off the connection request.
+ router_->Send(
+ new ViewHostMsg_ConnectToWorker(route_id_, message_port_id_));
}
void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() {
« no previous file with comments | « content/renderer/websharedworker_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698