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

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

Issue 198073003: Remove some content_child dependency from content_common (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ffd442cb fix for bots barfing on clang style checks Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/websharedworker_proxy.h ('k') | content/worker/websharedworker_stub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/child/child_thread.h"
8 #include "content/child/webmessageportchannel_impl.h" 7 #include "content/child/webmessageportchannel_impl.h"
8 #include "content/common/message_router.h"
9 #include "content/common/view_messages.h" 9 #include "content/common/view_messages.h"
10 #include "content/common/worker_messages.h" 10 #include "content/common/worker_messages.h"
11 #include "third_party/WebKit/public/platform/WebURL.h" 11 #include "third_party/WebKit/public/platform/WebURL.h"
12 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h" 12 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 WebSharedWorkerProxy::WebSharedWorkerProxy(ChildThread* child_thread, 16 WebSharedWorkerProxy::WebSharedWorkerProxy(MessageRouter* router,
17 unsigned long long document_id, 17 unsigned long long document_id,
18 int route_id, 18 int route_id,
19 int render_frame_route_id) 19 int render_frame_route_id)
20 : route_id_(route_id), 20 : route_id_(route_id),
21 render_frame_route_id_(render_frame_route_id), 21 render_frame_route_id_(render_frame_route_id),
22 child_thread_(child_thread), 22 router_(router),
23 document_id_(document_id), 23 document_id_(document_id),
24 pending_route_id_(route_id), 24 pending_route_id_(route_id),
25 connect_listener_(NULL), 25 connect_listener_(NULL),
26 created_(false) { 26 created_(false) {
27 child_thread_->AddRoute(route_id_, this); 27 router_->AddRoute(route_id_, this);
28 } 28 }
29 29
30 WebSharedWorkerProxy::~WebSharedWorkerProxy() { 30 WebSharedWorkerProxy::~WebSharedWorkerProxy() {
31 Disconnect(); 31 Disconnect();
32 32
33 // Free up any unsent queued messages. 33 // Free up any unsent queued messages.
34 for (size_t i = 0; i < queued_messages_.size(); ++i) 34 for (size_t i = 0; i < queued_messages_.size(); ++i)
35 delete queued_messages_[i]; 35 delete queued_messages_[i];
36 } 36 }
37 37
38 void WebSharedWorkerProxy::Disconnect() { 38 void WebSharedWorkerProxy::Disconnect() {
39 if (route_id_ == MSG_ROUTING_NONE) 39 if (route_id_ == MSG_ROUTING_NONE)
40 return; 40 return;
41 41
42 // So the messages from WorkerContext (like WorkerContextDestroyed) do not 42 // So the messages from WorkerContext (like WorkerContextDestroyed) do not
43 // come after nobody is listening. Since Worker and WorkerContext can 43 // come after nobody is listening. Since Worker and WorkerContext can
44 // terminate independently, already sent messages may still be in the pipe. 44 // terminate independently, already sent messages may still be in the pipe.
45 child_thread_->RemoveRoute(route_id_); 45 router_->RemoveRoute(route_id_);
46 46
47 route_id_ = MSG_ROUTING_NONE; 47 route_id_ = MSG_ROUTING_NONE;
48 } 48 }
49 49
50 bool WebSharedWorkerProxy::Send(IPC::Message* message) { 50 bool WebSharedWorkerProxy::Send(IPC::Message* message) {
51 // It's possible that messages will be sent before the worker is created, in 51 // It's possible that messages will be sent before the worker is created, in
52 // which case route_id_ will be none. Or the worker object can be interacted 52 // which case route_id_ will be none. Or the worker object can be interacted
53 // with before the browser process told us that it started, in which case we 53 // with before the browser process told us that it started, in which case we
54 // also want to queue the message. 54 // also want to queue the message.
55 if (!created_) { 55 if (!created_) {
56 queued_messages_.push_back(message); 56 queued_messages_.push_back(message);
57 return true; 57 return true;
58 } 58 }
59 59
60 // For now we proxy all messages to the worker process through the browser. 60 // For now we proxy all messages to the worker process through the browser.
61 // Revisit if we find this slow. 61 // Revisit if we find this slow.
62 // TODO(jabdelmalek): handle sync messages if we need them. 62 // TODO(jabdelmalek): handle sync messages if we need them.
63 IPC::Message* wrapped_msg = new ViewHostMsg_ForwardToWorker(*message); 63 IPC::Message* wrapped_msg = new ViewHostMsg_ForwardToWorker(*message);
64 delete message; 64 delete message;
65 return child_thread_->Send(wrapped_msg); 65 return router_->Send(wrapped_msg);
66 } 66 }
67 67
68 void WebSharedWorkerProxy::SendQueuedMessages() { 68 void WebSharedWorkerProxy::SendQueuedMessages() {
69 DCHECK(queued_messages_.size()); 69 DCHECK(queued_messages_.size());
70 std::vector<IPC::Message*> queued_messages = queued_messages_; 70 std::vector<IPC::Message*> queued_messages = queued_messages_;
71 queued_messages_.clear(); 71 queued_messages_.clear();
72 for (size_t i = 0; i < queued_messages.size(); ++i) { 72 for (size_t i = 0; i < queued_messages.size(); ++i) {
73 queued_messages[i]->set_routing_id(route_id_); 73 queued_messages[i]->set_routing_id(route_id_);
74 Send(queued_messages[i]); 74 Send(queued_messages[i]);
75 } 75 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 117
118 void WebSharedWorkerProxy::OnWorkerConnected() { 118 void WebSharedWorkerProxy::OnWorkerConnected() {
119 if (connect_listener_) { 119 if (connect_listener_) {
120 // This can result in this object being freed. 120 // This can result in this object being freed.
121 connect_listener_->connected(); 121 connect_listener_->connected();
122 } 122 }
123 } 123 }
124 124
125 } // namespace content 125 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/websharedworker_proxy.h ('k') | content/worker/websharedworker_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698