From b53225088747643b4ef35bc4e10e2622ec63ce30 Mon Sep 17 00:00:00 2001 From: "jhawkins@chromium.org" Date: Tue, 29 Nov 2011 02:24:28 +0000 Subject: base::Bind: Convert IPC::SendTask. BUG=none TEST=none R=groby@chromium.org Review URL: http://codereview.chromium.org/8714003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111837 0039d316-1c4b-4281-b951-d872f2087c98 --- ipc/ipc_channel_proxy.cc | 20 +++++++++++--------- ipc/ipc_channel_proxy.h | 6 +++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc index fb365d6..f542eae 100644 --- a/ipc/ipc_channel_proxy.cc +++ b/ipc/ipc_channel_proxy.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/compiler_specific.h" #include "base/location.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -12,18 +13,17 @@ namespace IPC { -//------------------------------------------------------------------------------ - -// This task ensures the message is deleted if the task is deleted without +// This helper ensures the message is deleted if the task is deleted without // having been run. -class SendTask : public Task { +class SendCallbackHelper + : public base::RefCountedThreadSafe { public: - SendTask(ChannelProxy::Context* context, Message* message) + SendCallbackHelper(ChannelProxy::Context* context, Message* message) : context_(context), message_(message) { } - virtual void Run() { + void Send() { context_->OnSendMessage(message_.release()); } @@ -31,7 +31,7 @@ class SendTask : public Task { scoped_refptr context_; scoped_ptr message_; - DISALLOW_COPY_AND_ASSIGN(SendTask); + DISALLOW_COPY_AND_ASSIGN(SendCallbackHelper); }; //------------------------------------------------------------------------------ @@ -354,8 +354,10 @@ bool ChannelProxy::Send(Message* message) { Logging::GetInstance()->OnSendMessage(message, context_->channel_id()); #endif - context_->ipc_message_loop()->PostTask(FROM_HERE, - new SendTask(context_.get(), message)); + context_->ipc_message_loop()->PostTask( + FROM_HERE, + base::Bind(&SendCallbackHelper::Send, + new SendCallbackHelper(context_.get(), message))); return true; } diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h index ea951fe..49d237e 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -17,7 +17,7 @@ namespace IPC { -class SendTask; +class SendCallbackHelper; //----------------------------------------------------------------------------- // IPC::ChannelProxy @@ -222,7 +222,7 @@ class IPC_EXPORT ChannelProxy : public Message::Sender { private: friend class ChannelProxy; - friend class SendTask; + friend class SendCallbackHelper; // Create the Channel void CreateChannel(const IPC::ChannelHandle& channel_handle, @@ -263,7 +263,7 @@ class IPC_EXPORT ChannelProxy : public Message::Sender { } private: - friend class SendTask; + friend class SendCallbackHelper; // By maintaining this indirection (ref-counted) to our internal state, we // can safely be destroyed while the background thread continues to do stuff -- cgit v1.1