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

Side by Side Diff: content/common/webmessageportchannel_impl.cc

Issue 8556001: Convert NewRunnableFunction/NewRunnableMethod calls to use base::Bind(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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/common/socket_stream_dispatcher.cc ('k') | content/shell/shell_browser_context.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/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
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(
82 NewRunnableMethod(this, &WebMessagePortChannelImpl::postMessage, 83 FROM_HERE,
83 message, channels)); 84 base::Bind(&WebMessagePortChannelImpl::postMessage, this,
85 message, channels));
84 return; 86 return;
85 } 87 }
86 88
87 std::vector<int> message_port_ids(channels ? channels->size() : 0); 89 std::vector<int> message_port_ids(channels ? channels->size() : 0);
88 if (channels) { 90 if (channels) {
89 // Extract the port IDs from the source array, then free it. 91 // Extract the port IDs from the source array, then free it.
90 for (size_t i = 0; i < channels->size(); ++i) { 92 for (size_t i = 0; i < channels->size(); ++i) {
91 WebMessagePortChannelImpl* webchannel = 93 WebMessagePortChannelImpl* webchannel =
92 static_cast<WebMessagePortChannelImpl*>((*channels)[i]); 94 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
93 message_port_ids[i] = webchannel->message_port_id(); 95 message_port_ids[i] = webchannel->message_port_id();
(...skipping 23 matching lines...) Expand all
117 result_ports[i] = channel_array[i]; 119 result_ports[i] = channel_array[i];
118 } 120 }
119 121
120 channels.swap(result_ports); 122 channels.swap(result_ports);
121 message_queue_.pop(); 123 message_queue_.pop();
122 return true; 124 return true;
123 } 125 }
124 126
125 void WebMessagePortChannelImpl::Init() { 127 void WebMessagePortChannelImpl::Init() {
126 if (MessageLoop::current() != ChildThread::current()->message_loop()) { 128 if (MessageLoop::current() != ChildThread::current()->message_loop()) {
127 ChildThread::current()->message_loop()->PostTask(FROM_HERE, 129 ChildThread::current()->message_loop()->PostTask(
128 NewRunnableMethod(this, &WebMessagePortChannelImpl::Init)); 130 FROM_HERE,
131 base::Bind(&WebMessagePortChannelImpl::Init, this));
129 return; 132 return;
130 } 133 }
131 134
132 if (route_id_ == MSG_ROUTING_NONE) { 135 if (route_id_ == MSG_ROUTING_NONE) {
133 DCHECK(message_port_id_ == MSG_ROUTING_NONE); 136 DCHECK(message_port_id_ == MSG_ROUTING_NONE);
134 Send(new WorkerProcessHostMsg_CreateMessagePort( 137 Send(new WorkerProcessHostMsg_CreateMessagePort(
135 &route_id_, &message_port_id_)); 138 &route_id_, &message_port_id_));
136 } 139 }
137 140
138 ChildThread::current()->AddRoute(route_id_, this); 141 ChildThread::current()->AddRoute(route_id_, this);
139 } 142 }
140 143
141 void WebMessagePortChannelImpl::Entangle( 144 void WebMessagePortChannelImpl::Entangle(
142 scoped_refptr<WebMessagePortChannelImpl> channel) { 145 scoped_refptr<WebMessagePortChannelImpl> channel) {
143 if (MessageLoop::current() != ChildThread::current()->message_loop()) { 146 if (MessageLoop::current() != ChildThread::current()->message_loop()) {
144 ChildThread::current()->message_loop()->PostTask(FROM_HERE, 147 ChildThread::current()->message_loop()->PostTask(
145 NewRunnableMethod(this, &WebMessagePortChannelImpl::Entangle, channel)); 148 FROM_HERE,
149 base::Bind(&WebMessagePortChannelImpl::Entangle, this, channel));
146 return; 150 return;
147 } 151 }
148 152
149 Send(new WorkerProcessHostMsg_Entangle( 153 Send(new WorkerProcessHostMsg_Entangle(
150 message_port_id_, channel->message_port_id())); 154 message_port_id_, channel->message_port_id()));
151 } 155 }
152 156
153 void WebMessagePortChannelImpl::QueueMessages() { 157 void WebMessagePortChannelImpl::QueueMessages() {
154 if (MessageLoop::current() != ChildThread::current()->message_loop()) { 158 if (MessageLoop::current() != ChildThread::current()->message_loop()) {
155 ChildThread::current()->message_loop()->PostTask(FROM_HERE, 159 ChildThread::current()->message_loop()->PostTask(
156 NewRunnableMethod(this, &WebMessagePortChannelImpl::QueueMessages)); 160 FROM_HERE,
161 base::Bind(&WebMessagePortChannelImpl::QueueMessages, this));
157 return; 162 return;
158 } 163 }
159 // This message port is being sent elsewhere (perhaps to another process). 164 // This message port is being sent elsewhere (perhaps to another process).
160 // The new endpoint needs to receive the queued messages, including ones that 165 // 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 166 // 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 167 // 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 168 // 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. 169 // them to the ones it queued and it sends them to the new endpoint.
165 Send(new WorkerProcessHostMsg_QueueMessages(message_port_id_)); 170 Send(new WorkerProcessHostMsg_QueueMessages(message_port_id_));
166 171
167 // The process could potentially go away while we're still waiting for 172 // The process could potentially go away while we're still waiting for
168 // in-flight messages. Ensure it stays alive. 173 // in-flight messages. Ensure it stays alive.
169 ChildProcess::current()->AddRefProcess(); 174 ChildProcess::current()->AddRefProcess();
170 } 175 }
171 176
172 void WebMessagePortChannelImpl::Send(IPC::Message* message) { 177 void WebMessagePortChannelImpl::Send(IPC::Message* message) {
173 if (MessageLoop::current() != ChildThread::current()->message_loop()) { 178 if (MessageLoop::current() != ChildThread::current()->message_loop()) {
174 DCHECK(!message->is_sync()); 179 DCHECK(!message->is_sync());
175 ChildThread::current()->message_loop()->PostTask(FROM_HERE, 180 ChildThread::current()->message_loop()->PostTask(
176 NewRunnableMethod(this, &WebMessagePortChannelImpl::Send, message)); 181 FROM_HERE,
182 base::Bind(&WebMessagePortChannelImpl::Send, this, message));
177 return; 183 return;
178 } 184 }
179 185
180 ChildThread::current()->Send(message); 186 ChildThread::current()->Send(message);
181 } 187 }
182 188
183 bool WebMessagePortChannelImpl::OnMessageReceived(const IPC::Message& message) { 189 bool WebMessagePortChannelImpl::OnMessageReceived(const IPC::Message& message) {
184 bool handled = true; 190 bool handled = true;
185 IPC_BEGIN_MESSAGE_MAP(WebMessagePortChannelImpl, message) 191 IPC_BEGIN_MESSAGE_MAP(WebMessagePortChannelImpl, message)
186 IPC_MESSAGE_HANDLER(WorkerProcessMsg_Message, OnMessage) 192 IPC_MESSAGE_HANDLER(WorkerProcessMsg_Message, OnMessage)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 241
236 message_port_id_ = MSG_ROUTING_NONE; 242 message_port_id_ = MSG_ROUTING_NONE;
237 243
238 Release(); 244 Release();
239 ChildProcess::current()->ReleaseProcess(); 245 ChildProcess::current()->ReleaseProcess();
240 } 246 }
241 247
242 WebMessagePortChannelImpl::Message::Message() {} 248 WebMessagePortChannelImpl::Message::Message() {}
243 249
244 WebMessagePortChannelImpl::Message::~Message() {} 250 WebMessagePortChannelImpl::Message::~Message() {}
OLDNEW
« no previous file with comments | « content/common/socket_stream_dispatcher.cc ('k') | content/shell/shell_browser_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698