OLD | NEW |
---|---|
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/common/webmessageportchannel_impl.h" | 5 #include "content/common/webmessageportchannel_impl.h" |
6 | 6 |
7 #include "base/bind.h" | |
7 #include "content/common/child_process.h" | 8 #include "content/common/child_process.h" |
8 #include "content/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
9 #include "content/common/worker_messages.h" | 10 #include "content/common/worker_messages.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel Client.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel Client.h" |
12 | 13 |
13 using WebKit::WebMessagePortChannel; | 14 using WebKit::WebMessagePortChannel; |
14 using WebKit::WebMessagePortChannelArray; | 15 using WebKit::WebMessagePortChannelArray; |
15 using WebKit::WebMessagePortChannelClient; | 16 using WebKit::WebMessagePortChannelClient; |
16 using WebKit::WebString; | 17 using WebKit::WebString; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 // before getting the other message port id. | 72 // before getting the other message port id. |
72 scoped_refptr<WebMessagePortChannelImpl> webchannel( | 73 scoped_refptr<WebMessagePortChannelImpl> webchannel( |
73 static_cast<WebMessagePortChannelImpl*>(channel)); | 74 static_cast<WebMessagePortChannelImpl*>(channel)); |
74 Entangle(webchannel); | 75 Entangle(webchannel); |
75 } | 76 } |
76 | 77 |
77 void WebMessagePortChannelImpl::postMessage( | 78 void WebMessagePortChannelImpl::postMessage( |
78 const WebString& message, | 79 const WebString& message, |
79 WebMessagePortChannelArray* channels) { | 80 WebMessagePortChannelArray* channels) { |
80 if (MessageLoop::current() != ChildThread::current()->message_loop()) { | 81 if (MessageLoop::current() != ChildThread::current()->message_loop()) { |
81 ChildThread::current()->message_loop()->PostTask(FROM_HERE, | 82 ChildThread::current()->message_loop()->PostTask(FROM_HERE, |
James Hawkins
2011/11/14 17:57:06
Start of parameters must be on the same column.
dcheng
2011/11/14 20:47:49
Done.
| |
82 NewRunnableMethod(this, &WebMessagePortChannelImpl::postMessage, | 83 base::Bind(&WebMessagePortChannelImpl::postMessage, this, |
83 message, channels)); | 84 message, channels)); |
84 return; | 85 return; |
85 } | 86 } |
86 | 87 |
87 std::vector<int> message_port_ids(channels ? channels->size() : 0); | 88 std::vector<int> message_port_ids(channels ? channels->size() : 0); |
88 if (channels) { | 89 if (channels) { |
89 // Extract the port IDs from the source array, then free it. | 90 // Extract the port IDs from the source array, then free it. |
90 for (size_t i = 0; i < channels->size(); ++i) { | 91 for (size_t i = 0; i < channels->size(); ++i) { |
91 WebMessagePortChannelImpl* webchannel = | 92 WebMessagePortChannelImpl* webchannel = |
92 static_cast<WebMessagePortChannelImpl*>((*channels)[i]); | 93 static_cast<WebMessagePortChannelImpl*>((*channels)[i]); |
(...skipping 25 matching lines...) Expand all Loading... | |
118 } | 119 } |
119 | 120 |
120 channels.swap(result_ports); | 121 channels.swap(result_ports); |
121 message_queue_.pop(); | 122 message_queue_.pop(); |
122 return true; | 123 return true; |
123 } | 124 } |
124 | 125 |
125 void WebMessagePortChannelImpl::Init() { | 126 void WebMessagePortChannelImpl::Init() { |
126 if (MessageLoop::current() != ChildThread::current()->message_loop()) { | 127 if (MessageLoop::current() != ChildThread::current()->message_loop()) { |
127 ChildThread::current()->message_loop()->PostTask(FROM_HERE, | 128 ChildThread::current()->message_loop()->PostTask(FROM_HERE, |
128 NewRunnableMethod(this, &WebMessagePortChannelImpl::Init)); | 129 base::Bind(&WebMessagePortChannelImpl::Init, this)); |
129 return; | 130 return; |
130 } | 131 } |
131 | 132 |
132 if (route_id_ == MSG_ROUTING_NONE) { | 133 if (route_id_ == MSG_ROUTING_NONE) { |
133 DCHECK(message_port_id_ == MSG_ROUTING_NONE); | 134 DCHECK(message_port_id_ == MSG_ROUTING_NONE); |
134 Send(new WorkerProcessHostMsg_CreateMessagePort( | 135 Send(new WorkerProcessHostMsg_CreateMessagePort( |
135 &route_id_, &message_port_id_)); | 136 &route_id_, &message_port_id_)); |
136 } | 137 } |
137 | 138 |
138 ChildThread::current()->AddRoute(route_id_, this); | 139 ChildThread::current()->AddRoute(route_id_, this); |
139 } | 140 } |
140 | 141 |
141 void WebMessagePortChannelImpl::Entangle( | 142 void WebMessagePortChannelImpl::Entangle( |
142 scoped_refptr<WebMessagePortChannelImpl> channel) { | 143 scoped_refptr<WebMessagePortChannelImpl> channel) { |
143 if (MessageLoop::current() != ChildThread::current()->message_loop()) { | 144 if (MessageLoop::current() != ChildThread::current()->message_loop()) { |
144 ChildThread::current()->message_loop()->PostTask(FROM_HERE, | 145 ChildThread::current()->message_loop()->PostTask(FROM_HERE, |
145 NewRunnableMethod(this, &WebMessagePortChannelImpl::Entangle, channel)); | 146 base::Bind(&WebMessagePortChannelImpl::Entangle, this, channel)); |
146 return; | 147 return; |
147 } | 148 } |
148 | 149 |
149 Send(new WorkerProcessHostMsg_Entangle( | 150 Send(new WorkerProcessHostMsg_Entangle( |
150 message_port_id_, channel->message_port_id())); | 151 message_port_id_, channel->message_port_id())); |
151 } | 152 } |
152 | 153 |
153 void WebMessagePortChannelImpl::QueueMessages() { | 154 void WebMessagePortChannelImpl::QueueMessages() { |
154 if (MessageLoop::current() != ChildThread::current()->message_loop()) { | 155 if (MessageLoop::current() != ChildThread::current()->message_loop()) { |
155 ChildThread::current()->message_loop()->PostTask(FROM_HERE, | 156 ChildThread::current()->message_loop()->PostTask(FROM_HERE, |
156 NewRunnableMethod(this, &WebMessagePortChannelImpl::QueueMessages)); | 157 base::Bind(&WebMessagePortChannelImpl::QueueMessages, this)); |
157 return; | 158 return; |
158 } | 159 } |
159 // This message port is being sent elsewhere (perhaps to another process). | 160 // This message port is being sent elsewhere (perhaps to another process). |
160 // The new endpoint needs to receive the queued messages, including ones that | 161 // The new endpoint needs to receive the queued messages, including ones that |
161 // could still be in-flight. So we tell the browser to queue messages, and it | 162 // could still be in-flight. So we tell the browser to queue messages, and it |
162 // sends us an ack, whose receipt we know means that no more messages are | 163 // sends us an ack, whose receipt we know means that no more messages are |
163 // in-flight. We then send the queued messages to the browser, which prepends | 164 // in-flight. We then send the queued messages to the browser, which prepends |
164 // them to the ones it queued and it sends them to the new endpoint. | 165 // them to the ones it queued and it sends them to the new endpoint. |
165 Send(new WorkerProcessHostMsg_QueueMessages(message_port_id_)); | 166 Send(new WorkerProcessHostMsg_QueueMessages(message_port_id_)); |
166 | 167 |
167 // The process could potentially go away while we're still waiting for | 168 // The process could potentially go away while we're still waiting for |
168 // in-flight messages. Ensure it stays alive. | 169 // in-flight messages. Ensure it stays alive. |
169 ChildProcess::current()->AddRefProcess(); | 170 ChildProcess::current()->AddRefProcess(); |
170 } | 171 } |
171 | 172 |
172 void WebMessagePortChannelImpl::Send(IPC::Message* message) { | 173 void WebMessagePortChannelImpl::Send(IPC::Message* message) { |
173 if (MessageLoop::current() != ChildThread::current()->message_loop()) { | 174 if (MessageLoop::current() != ChildThread::current()->message_loop()) { |
174 DCHECK(!message->is_sync()); | 175 DCHECK(!message->is_sync()); |
175 ChildThread::current()->message_loop()->PostTask(FROM_HERE, | 176 ChildThread::current()->message_loop()->PostTask(FROM_HERE, |
176 NewRunnableMethod(this, &WebMessagePortChannelImpl::Send, message)); | 177 base::Bind(&WebMessagePortChannelImpl::Send, this, message)); |
177 return; | 178 return; |
178 } | 179 } |
179 | 180 |
180 ChildThread::current()->Send(message); | 181 ChildThread::current()->Send(message); |
181 } | 182 } |
182 | 183 |
183 bool WebMessagePortChannelImpl::OnMessageReceived(const IPC::Message& message) { | 184 bool WebMessagePortChannelImpl::OnMessageReceived(const IPC::Message& message) { |
184 bool handled = true; | 185 bool handled = true; |
185 IPC_BEGIN_MESSAGE_MAP(WebMessagePortChannelImpl, message) | 186 IPC_BEGIN_MESSAGE_MAP(WebMessagePortChannelImpl, message) |
186 IPC_MESSAGE_HANDLER(WorkerProcessMsg_Message, OnMessage) | 187 IPC_MESSAGE_HANDLER(WorkerProcessMsg_Message, OnMessage) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 | 236 |
236 message_port_id_ = MSG_ROUTING_NONE; | 237 message_port_id_ = MSG_ROUTING_NONE; |
237 | 238 |
238 Release(); | 239 Release(); |
239 ChildProcess::current()->ReleaseProcess(); | 240 ChildProcess::current()->ReleaseProcess(); |
240 } | 241 } |
241 | 242 |
242 WebMessagePortChannelImpl::Message::Message() {} | 243 WebMessagePortChannelImpl::Message::Message() {} |
243 | 244 |
244 WebMessagePortChannelImpl::Message::~Message() {} | 245 WebMessagePortChannelImpl::Message::~Message() {} |
OLD | NEW |