summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-12 21:16:41 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-12 21:16:41 +0000
commit72b6f8e29c17e3752847dd318821f18968b23dc8 (patch)
tree6c42c429354a669b48522219a8d386026365bc43
parent4af95959968ce9b309f91fc504bca97762b9e8f5 (diff)
downloadchromium_src-72b6f8e29c17e3752847dd318821f18968b23dc8.zip
chromium_src-72b6f8e29c17e3752847dd318821f18968b23dc8.tar.gz
chromium_src-72b6f8e29c17e3752847dd318821f18968b23dc8.tar.bz2
base:Bind: Convert ipc/.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8539036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109810 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ipc/ipc_channel_proxy.cc35
-rw-r--r--ipc/ipc_channel_win.cc9
-rw-r--r--ipc/ipc_channel_win.h3
-rw-r--r--ipc/ipc_logging.cc15
-rw-r--r--ipc/ipc_sync_channel.cc20
-rw-r--r--ipc/ipc_sync_channel_unittest.cc44
-rw-r--r--ipc/ipc_sync_message_filter.cc7
7 files changed, 71 insertions, 62 deletions
diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc
index 44933ae..26d285a 100644
--- a/ipc/ipc_channel_proxy.cc
+++ b/ipc/ipc_channel_proxy.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -111,8 +112,8 @@ bool ChannelProxy::Context::OnMessageReceivedNoFilter(const Message& message) {
// this thread is active. That should be a reasonable assumption, but it
// feels risky. We may want to invent some more indirect way of referring to
// a MessageLoop if this becomes a problem.
- listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Context::OnDispatchMessage, message));
+ listener_message_loop_->PostTask(
+ FROM_HERE, base::Bind(&Context::OnDispatchMessage, this, message));
return true;
}
@@ -129,8 +130,8 @@ void ChannelProxy::Context::OnChannelConnected(int32 peer_pid) {
filters_[i]->OnChannelConnected(peer_pid);
// See above comment about using listener_message_loop_ here.
- listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Context::OnDispatchConnected));
+ listener_message_loop_->PostTask(
+ FROM_HERE, base::Bind(&Context::OnDispatchConnected, this));
}
// Called on the IPC::Channel thread
@@ -139,8 +140,8 @@ void ChannelProxy::Context::OnChannelError() {
filters_[i]->OnChannelError();
// See above comment about using listener_message_loop_ here.
- listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Context::OnDispatchError));
+ listener_message_loop_->PostTask(
+ FROM_HERE, base::Bind(&Context::OnDispatchError, this));
}
// Called on the IPC::Channel thread
@@ -232,8 +233,7 @@ void ChannelProxy::Context::AddFilter(MessageFilter* filter) {
base::AutoLock auto_lock(pending_filters_lock_);
pending_filters_.push_back(make_scoped_refptr(filter));
ipc_message_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &Context::OnAddFilter));
+ FROM_HERE, base::Bind(&Context::OnAddFilter, this));
}
// Called on the listener's thread
@@ -324,13 +324,14 @@ void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle,
// to connect and get an error since the pipe doesn't exist yet.
context_->CreateChannel(channel_handle, mode);
} else {
- context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- context_.get(), &Context::CreateChannel, channel_handle, mode));
+ context_->ipc_message_loop()->PostTask(
+ FROM_HERE, base::Bind(&Context::CreateChannel, context_.get(),
+ channel_handle, mode));
}
// complete initialization on the background thread
- context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- context_.get(), &Context::OnChannelOpened));
+ context_->ipc_message_loop()->PostTask(
+ FROM_HERE, base::Bind(&Context::OnChannelOpened, context_.get()));
}
void ChannelProxy::Close() {
@@ -340,8 +341,8 @@ void ChannelProxy::Close() {
context_->Clear();
if (context_->ipc_message_loop()) {
- context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- context_.get(), &Context::OnChannelClosed));
+ context_->ipc_message_loop()->PostTask(
+ FROM_HERE, base::Bind(&Context::OnChannelClosed, context_.get()));
}
}
@@ -364,10 +365,8 @@ void ChannelProxy::AddFilter(MessageFilter* filter) {
void ChannelProxy::RemoveFilter(MessageFilter* filter) {
context_->ipc_message_loop()->PostTask(
- FROM_HERE, NewRunnableMethod(
- context_.get(),
- &Context::OnRemoveFilter,
- make_scoped_refptr(filter)));
+ FROM_HERE, base::Bind(&Context::OnRemoveFilter, context_.get(),
+ make_scoped_refptr(filter)));
}
void ChannelProxy::ClearIPCMessageLoop() {
diff --git a/ipc/ipc_channel_win.cc b/ipc/ipc_channel_win.cc
index 3a85a16..cd313d2 100644
--- a/ipc/ipc_channel_win.cc
+++ b/ipc/ipc_channel_win.cc
@@ -7,6 +7,7 @@
#include <windows.h>
#include "base/auto_reset.h"
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/threading/non_thread_safe.h"
@@ -35,7 +36,7 @@ Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle,
listener_(listener),
waiting_connect_(mode & MODE_SERVER_FLAG),
processing_incoming_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
CreatePipe(channel_handle, mode);
}
@@ -177,8 +178,10 @@ bool Channel::ChannelImpl::Connect() {
// Complete setup asynchronously. By not setting input_state_.is_pending
// to true, we indicate to OnIOCompleted that this is the special
// initialization signal.
- MessageLoopForIO::current()->PostTask(FROM_HERE, factory_.NewRunnableMethod(
- &Channel::ChannelImpl::OnIOCompleted, &input_state_.context, 0, 0));
+ MessageLoopForIO::current()->PostTask(
+ FROM_HERE, base::Bind(&Channel::ChannelImpl::OnIOCompleted,
+ weak_factory_.GetWeakPtr(), &input_state_.context,
+ 0, 0));
}
if (!waiting_connect_)
diff --git a/ipc/ipc_channel_win.h b/ipc/ipc_channel_win.h
index ada88ac..77bc119 100644
--- a/ipc/ipc_channel_win.h
+++ b/ipc/ipc_channel_win.h
@@ -12,6 +12,7 @@
#include <string>
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
namespace base {
@@ -79,7 +80,7 @@ class Channel::ChannelImpl : public MessageLoopForIO::IOHandler {
// problems. TODO(darin): make this unnecessary
bool processing_incoming_;
- ScopedRunnableMethodFactory<ChannelImpl> factory_;
+ base::WeakPtrFactory<ChannelImpl> weak_factory_;
scoped_ptr<base::NonThreadSafe> thread_check_;
diff --git a/ipc/ipc_logging.cc b/ipc/ipc_logging.cc
index f6e91c4..9f615bd 100644
--- a/ipc/ipc_logging.cc
+++ b/ipc/ipc_logging.cc
@@ -8,6 +8,8 @@
#define IPC_MESSAGE_MACROS_LOG_ENABLED
#endif
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/logging.h"
@@ -29,10 +31,6 @@
using base::Time;
-// IPC::Logging is allocated as a singleton, so we don't need any kind of
-// special retention program.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(IPC::Logging);
-
namespace IPC {
const int kLogSendDelayMs = 100;
@@ -163,8 +161,8 @@ void Logging::OnPostDispatchMessage(const Message& message,
if (MessageLoop::current() == main_thread_) {
Log(data);
} else {
- main_thread_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Logging::Log, data));
+ main_thread_->PostTask(
+ FROM_HERE, base::Bind(&Logging::Log, base::Unretained(this), data));
}
}
@@ -233,8 +231,9 @@ void Logging::Log(const LogData& data) {
queued_logs_.push_back(data);
if (!queue_invoke_later_pending_) {
queue_invoke_later_pending_ = true;
- MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(
- this, &Logging::OnSendLogs), kLogSendDelayMs);
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, base::Bind(&Logging::OnSendLogs, base::Unretained(this)),
+ kLogSendDelayMs);
}
}
}
diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc
index 8fe5c37..e3b74ba 100644
--- a/ipc/ipc_sync_channel.cc
+++ b/ipc/ipc_sync_channel.cc
@@ -4,6 +4,7 @@
#include "ipc/ipc_sync_channel.h"
+#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/logging.h"
@@ -67,10 +68,9 @@ class SyncChannel::ReceivedSyncMsgQueue :
dispatch_event_.Signal();
if (!was_task_pending) {
- listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this,
- &ReceivedSyncMsgQueue::DispatchMessagesTask,
- scoped_refptr<SyncContext>(context)));
+ listener_message_loop_->PostTask(
+ FROM_HERE, base::Bind(&ReceivedSyncMsgQueue::DispatchMessagesTask,
+ this, scoped_refptr<SyncContext>(context)));
}
}
@@ -259,8 +259,9 @@ bool SyncChannel::SyncContext::Pop() {
// blocking Send() call, whose reply we received after we made this last
// Send() call. So check if we have any queued replies available that
// can now unblock the listener thread.
- ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- received_sync_msgs_.get(), &ReceivedSyncMsgQueue::DispatchReplies));
+ ipc_message_loop()->PostTask(
+ FROM_HERE, base::Bind(&ReceivedSyncMsgQueue::DispatchReplies,
+ received_sync_msgs_.get()));
return result;
}
@@ -427,9 +428,10 @@ bool SyncChannel::SendWithTimeout(Message* message, int timeout_ms) {
// We use the sync message id so that when a message times out, we don't
// confuse it with another send that is either above/below this Send in
// the call stack.
- context->ipc_message_loop()->PostDelayedTask(FROM_HERE,
- NewRunnableMethod(context.get(),
- &SyncContext::OnSendTimeout, message_id), timeout_ms);
+ context->ipc_message_loop()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&SyncContext::OnSendTimeout, context.get(), message_id),
+ timeout_ms);
}
// Wait for reply, or for any other incoming synchronous messages.
diff --git a/ipc/ipc_sync_channel_unittest.cc b/ipc/ipc_sync_channel_unittest.cc
index bdd83eb..029e49c 100644
--- a/ipc/ipc_sync_channel_unittest.cc
+++ b/ipc/ipc_sync_channel_unittest.cc
@@ -10,6 +10,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
@@ -70,9 +71,9 @@ class Worker : public Channel::Listener, public Message::Sender {
// destruction.
virtual ~Worker() {
WaitableEvent listener_done(false, false), ipc_done(false, false);
- ListenerThread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Worker::OnListenerThreadShutdown1, &listener_done,
- &ipc_done));
+ ListenerThread()->message_loop()->PostTask(
+ FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown1, this,
+ &listener_done, &ipc_done));
listener_done.Wait();
ipc_done.Wait();
ipc_thread_.Stop();
@@ -92,8 +93,8 @@ class Worker : public Channel::Listener, public Message::Sender {
}
void Start() {
StartThread(&listener_thread_, MessageLoop::TYPE_DEFAULT);
- ListenerThread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Worker::OnStart));
+ ListenerThread()->message_loop()->PostTask(
+ FROM_HERE, base::Bind(&Worker::OnStart, this));
}
void OverrideThread(base::Thread* overrided_thread) {
DCHECK(overrided_thread_ == NULL);
@@ -180,8 +181,9 @@ class Worker : public Channel::Listener, public Message::Sender {
MessageLoop::current()->RunAllPending();
- ipc_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Worker::OnIPCThreadShutdown, listener_event, ipc_event));
+ ipc_thread_.message_loop()->PostTask(
+ FROM_HERE, base::Bind(&Worker::OnIPCThreadShutdown, this,
+ listener_event, ipc_event));
}
void OnIPCThreadShutdown(WaitableEvent* listener_event,
@@ -189,8 +191,9 @@ class Worker : public Channel::Listener, public Message::Sender {
MessageLoop::current()->RunAllPending();
ipc_event->Signal();
- listener_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Worker::OnListenerThreadShutdown2, listener_event));
+ listener_thread_.message_loop()->PostTask(
+ FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown2, this,
+ listener_event));
}
void OnListenerThreadShutdown2(WaitableEvent* listener_event) {
@@ -1024,8 +1027,9 @@ class TestSyncMessageFilter : public SyncMessageFilter {
virtual void OnFilterAdded(Channel* channel) {
SyncMessageFilter::OnFilterAdded(channel);
- thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &TestSyncMessageFilter::SendMessageOnHelperThread));
+ thread_.message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&TestSyncMessageFilter::SendMessageOnHelperThread, this));
}
void SendMessageOnHelperThread() {
@@ -1065,8 +1069,10 @@ class ServerSendAfterClose : public Worker {
}
bool SendDummy() {
- ListenerThread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ServerSendAfterClose::Send, new SyncChannelTestMsg_NoArgs));
+ ListenerThread()->message_loop()->PostTask(
+ FROM_HERE, base::IgnoreReturn<bool>(
+ base::Bind(&ServerSendAfterClose::Send, this,
+ new SyncChannelTestMsg_NoArgs)));
return true;
}
@@ -1130,8 +1136,8 @@ class RestrictedDispatchServer : public Worker {
Send(msg);
// Signal the event after the message has been sent on the channel, on the
// IPC thread.
- ipc_thread().message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &RestrictedDispatchServer::OnPingSent));
+ ipc_thread().message_loop()->PostTask(
+ FROM_HERE, base::Bind(&RestrictedDispatchServer::OnPingSent, this));
}
base::Thread* ListenerThread() { return Worker::ListenerThread(); }
@@ -1186,8 +1192,8 @@ class RestrictedDispatchClient : public Worker {
// send a message on that same channel.
channel()->SetRestrictDispatchToSameChannel(true);
- server_->ListenerThread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(server_, &RestrictedDispatchServer::OnDoPing, 1));
+ server_->ListenerThread()->message_loop()->PostTask(
+ FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1));
sent_ping_event_->Wait();
Send(new SyncChannelTestMsg_NoArgs);
if (ping_ == 1)
@@ -1199,8 +1205,8 @@ class RestrictedDispatchClient : public Worker {
"non_restricted_channel", Channel::MODE_CLIENT, this,
ipc_thread().message_loop_proxy(), true, shutdown_event()));
- server_->ListenerThread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(server_, &RestrictedDispatchServer::OnDoPing, 2));
+ server_->ListenerThread()->message_loop()->PostTask(
+ FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 2));
sent_ping_event_->Wait();
// Check that the incoming message is *not* dispatched when sending on the
// non restricted channel.
diff --git a/ipc/ipc_sync_message_filter.cc b/ipc/ipc_sync_message_filter.cc
index f307573..e49ebd6 100644
--- a/ipc/ipc_sync_message_filter.cc
+++ b/ipc/ipc_sync_message_filter.cc
@@ -4,6 +4,7 @@
#include "ipc/ipc_sync_message_filter.h"
+#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop_proxy.h"
@@ -34,8 +35,7 @@ bool SyncMessageFilter::Send(Message* message) {
if (!message->is_sync()) {
io_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &SyncMessageFilter::SendOnIOThread, message));
+ FROM_HERE, base::Bind(&SyncMessageFilter::SendOnIOThread, this, message));
return true;
}
@@ -55,8 +55,7 @@ bool SyncMessageFilter::Send(Message* message) {
}
io_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &SyncMessageFilter::SendOnIOThread, message));
+ FROM_HERE, base::Bind(&SyncMessageFilter::SendOnIOThread, this, message));
base::WaitableEvent* events[2] = { shutdown_event_, &done_event };
base::WaitableEvent::WaitMany(events, 2);