diff options
-rw-r--r-- | ipc/ipc_channel_proxy.cc | 28 | ||||
-rw-r--r-- | ipc/ipc_channel_proxy.h | 5 |
2 files changed, 30 insertions, 3 deletions
diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc index eba506d..cbe8cc2 100644 --- a/ipc/ipc_channel_proxy.cc +++ b/ipc/ipc_channel_proxy.cc @@ -10,7 +10,29 @@ namespace IPC { -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------------ + +// This task ensures the message is deleted if the task is deleted without +// having been run. +class SendTask : public Task { + public: + SendTask(ChannelProxy::Context* context, Message* message) + : context_(context), + message_(message) { + } + + virtual void Run() { + context_->OnSendMessage(message_.release()); + } + + private: + scoped_refptr<ChannelProxy::Context> context_; + scoped_ptr<Message> message_; + + DISALLOW_COPY_AND_ASSIGN(SendTask); +}; + +//------------------------------------------------------------------------------ ChannelProxy::Context::Context(Channel::Listener* listener, MessageFilter* filter, @@ -254,8 +276,8 @@ bool ChannelProxy::Send(Message* message) { Logging::current()->OnSendMessage(message, context_->channel_id()); #endif - context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( - context_.get(), &Context::OnSendMessage, message)); + context_->ipc_message_loop()->PostTask(FROM_HERE, + new SendTask(context_.get(), message)); return true; } diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h index 77ddd87..e884818 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -14,6 +14,8 @@ class MessageLoop; namespace IPC { +class SendTask; + //----------------------------------------------------------------------------- // IPC::ChannelProxy // @@ -174,6 +176,7 @@ class ChannelProxy : public Message::Sender { private: friend class ChannelProxy; + friend class SendTask; // Create the Channel void CreateChannel(const std::string& id, const Channel::Mode& mode); @@ -199,6 +202,8 @@ class ChannelProxy : public Message::Sender { Context* context() { return context_; } private: + friend class SendTask; + void Init(const std::string& channel_id, Channel::Mode mode, MessageLoop* ipc_thread_loop, bool create_pipe_now); |