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

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

Issue 2627123003: SharedWorker: Simplify connection sequence (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/shared_worker/websharedworker_proxy.h" 5 #include "content/renderer/shared_worker/websharedworker_proxy.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "content/child/child_thread_impl.h"
9 #include "content/child/webmessageportchannel_impl.h" 10 #include "content/child/webmessageportchannel_impl.h"
10 #include "content/common/view_messages.h" 11 #include "content/common/view_messages.h"
11 #include "content/common/worker_messages.h" 12 #include "content/common/worker_messages.h"
12 #include "ipc/message_router.h" 13 #include "ipc/message_router.h"
14 #include "third_party/WebKit/public/web/WebSharedWorkerConnectListener.h"
13 15
14 namespace content { 16 namespace content {
15 17
16 WebSharedWorkerProxy::WebSharedWorkerProxy(IPC::MessageRouter* router, 18 WebSharedWorkerProxy::WebSharedWorkerProxy(
17 int route_id) 19 std::unique_ptr<blink::WebSharedWorkerConnectListener> listener)
18 : route_id_(route_id), 20 : route_id_(MSG_ROUTING_NONE),
19 router_(router), 21 router_(ChildThreadImpl::current()->GetRouter()),
20 message_port_id_(MSG_ROUTING_NONE), 22 message_port_id_(MSG_ROUTING_NONE),
21 connect_listener_(nullptr) { 23 listener_(std::move(listener)) {}
22 DCHECK_NE(MSG_ROUTING_NONE, route_id_);
23 router_->AddRoute(route_id_, this);
24 }
25 24
26 WebSharedWorkerProxy::~WebSharedWorkerProxy() { 25 WebSharedWorkerProxy::~WebSharedWorkerProxy() {
26 DCHECK_NE(MSG_ROUTING_NONE, route_id_);
27 router_->RemoveRoute(route_id_); 27 router_->RemoveRoute(route_id_);
28 } 28 }
29 29
30 void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel, 30 void WebSharedWorkerProxy::connect(ViewHostMsg_CreateWorker_Params params,
nhiroki 2017/01/13 05:28:53 Question: Who owns this |channel|? AFAICS, this is
kinuko 2017/01/13 07:31:34 The comment says: "The object owns itself and is s
horo 2017/01/16 07:11:03 Humm... It looks leaking after this change. https:
nhiroki 2017/01/18 05:42:37 Thank you. As horo's another comment, this seems t
31 ConnectListener* listener) { 31 blink::WebMessagePortChannel* channel) {
32 // Send synchronous IPC to get |route_id|.
33 // TODO(nhiroki): Stop using synchronous IPC (https://crbug.com/679654).
34 ViewHostMsg_CreateWorker_Reply reply;
35 router_->Send(new ViewHostMsg_CreateWorker(params, &reply));
36 route_id_ = reply.route_id;
37 router_->AddRoute(route_id_, this);
38 listener_->workerCreated(reply.error);
39
32 DCHECK_EQ(MSG_ROUTING_NONE, message_port_id_); 40 DCHECK_EQ(MSG_ROUTING_NONE, message_port_id_);
33 WebMessagePortChannelImpl* webchannel = 41 WebMessagePortChannelImpl* webchannel =
34 static_cast<WebMessagePortChannelImpl*>(channel); 42 static_cast<WebMessagePortChannelImpl*>(channel);
35 message_port_id_ = webchannel->message_port_id(); 43 message_port_id_ = webchannel->message_port_id();
36 DCHECK_NE(MSG_ROUTING_NONE, message_port_id_); 44 DCHECK_NE(MSG_ROUTING_NONE, message_port_id_);
37 webchannel->QueueMessages(); 45 webchannel->QueueMessages();
38 connect_listener_ = listener; 46 listener_->connecting();
kinuko 2017/01/13 07:31:34 Why do we need this method separately from workerC
nhiroki 2017/01/18 05:42:37 Yeah, this is not necessary. Removed.
39 // An actual connection request will be issued on OnWorkerCreated(). 47 // An actual connection request will be issued on OnWorkerCreated().
40 } 48 }
41 49
42 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { 50 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) {
43 bool handled = true; 51 bool handled = true;
44 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) 52 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message)
45 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) 53 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated)
46 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed, 54 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed,
47 OnWorkerScriptLoadFailed) 55 OnWorkerScriptLoadFailed)
48 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, 56 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected,
49 OnWorkerConnected) 57 OnWorkerConnected)
50 IPC_MESSAGE_UNHANDLED(handled = false) 58 IPC_MESSAGE_UNHANDLED(handled = false)
51 IPC_END_MESSAGE_MAP() 59 IPC_END_MESSAGE_MAP()
52 return handled; 60 return handled;
53 } 61 }
54 62
55 void WebSharedWorkerProxy::OnWorkerCreated() { 63 void WebSharedWorkerProxy::OnWorkerCreated() {
56 // connect() should be called before.
57 DCHECK_NE(MSG_ROUTING_NONE, message_port_id_);
58
59 // The worker is created - now send off the connection request. 64 // The worker is created - now send off the connection request.
60 router_->Send( 65 router_->Send(
61 new ViewHostMsg_ConnectToWorker(route_id_, message_port_id_)); 66 new ViewHostMsg_ConnectToWorker(route_id_, message_port_id_));
62 } 67 }
63 68
64 void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() { 69 void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() {
65 if (connect_listener_) { 70 listener_->scriptLoadFailed();
66 // This can result in this object being freed. 71 delete this;
kinuko 2017/01/13 07:31:34 would have been nice if we could remove this... bu
nhiroki 2017/01/18 05:42:37 Acknowledged.
67 connect_listener_->scriptLoadFailed();
68 }
69 } 72 }
70 73
71 void WebSharedWorkerProxy::OnWorkerConnected() { 74 void WebSharedWorkerProxy::OnWorkerConnected() {
72 if (connect_listener_) { 75 listener_->connected();
73 // This can result in this object being freed. 76 delete this;
74 connect_listener_->connected();
75 }
76 } 77 }
77 78
78 } // namespace content 79 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/shared_worker/websharedworker_proxy.h ('k') | third_party/WebKit/Source/core/workers/SharedWorker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698