From 827d7e806a16b934b43abe1ef35f4d7e8a7b634b Mon Sep 17 00:00:00 2001 From: "perkj@webrtc.org" Date: Thu, 29 Jan 2015 08:53:45 +0000 Subject: [PATCH] Change AsyncInvoker to store its closure in a scoped_refptr instead of using a raw pointer. This is just a cosmetic change and does not solve a particular bug. R=henrika@webrtc.org, tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/38749004 Cr-Commit-Position: refs/heads/master@{#8194} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8194 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/base/asyncinvoker-inl.h | 3 ++- webrtc/base/asyncinvoker.cc | 5 ++--- webrtc/base/asyncinvoker.h | 15 ++++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/webrtc/base/asyncinvoker-inl.h b/webrtc/base/asyncinvoker-inl.h index 733cb0e79..e208ee97d 100644 --- a/webrtc/base/asyncinvoker-inl.h +++ b/webrtc/base/asyncinvoker-inl.h @@ -29,10 +29,11 @@ class AsyncInvoker; // lifetime can be independent of AsyncInvoker. class AsyncClosure : public RefCountInterface { public: - virtual ~AsyncClosure() {} // Runs the asynchronous task, and triggers a callback to the calling // thread if needed. Should be called from the target thread. virtual void Execute() = 0; + protected: + virtual ~AsyncClosure() {} }; // Simple closure that doesn't trigger a callback for the calling thread. diff --git a/webrtc/base/asyncinvoker.cc b/webrtc/base/asyncinvoker.cc index ee423f110..3ccdc4bb4 100644 --- a/webrtc/base/asyncinvoker.cc +++ b/webrtc/base/asyncinvoker.cc @@ -52,12 +52,11 @@ void AsyncInvoker::Flush(Thread* thread, uint32 id /*= MQID_ANY*/) { } } -void AsyncInvoker::DoInvoke(Thread* thread, AsyncClosure* closure, +void AsyncInvoker::DoInvoke(Thread* thread, + const scoped_refptr& closure, uint32 id) { if (destroying_) { LOG(LS_WARNING) << "Tried to invoke while destroying the invoker."; - // Since this call transwers ownership of |closure|, we clean it up here. - delete closure; return; } thread->Post(this, id, new ScopedRefMessageData(closure)); diff --git a/webrtc/base/asyncinvoker.h b/webrtc/base/asyncinvoker.h index ee9a03c80..e4591a140 100644 --- a/webrtc/base/asyncinvoker.h +++ b/webrtc/base/asyncinvoker.h @@ -77,8 +77,8 @@ class AsyncInvoker : public MessageHandler { void AsyncInvoke(Thread* thread, const FunctorT& functor, uint32 id = 0) { - AsyncClosure* closure = - new RefCountedObject >(functor); + scoped_refptr closure( + new RefCountedObject >(functor)); DoInvoke(thread, closure, id); } @@ -89,9 +89,9 @@ class AsyncInvoker : public MessageHandler { void (HostT::*callback)(ReturnT), HostT* callback_host, uint32 id = 0) { - AsyncClosure* closure = + scoped_refptr closure( new RefCountedObject >( - this, Thread::Current(), functor, callback, callback_host); + this, Thread::Current(), functor, callback, callback_host)); DoInvoke(thread, closure, id); } @@ -103,9 +103,9 @@ class AsyncInvoker : public MessageHandler { void (HostT::*callback)(), HostT* callback_host, uint32 id = 0) { - AsyncClosure* closure = + scoped_refptr closure( new RefCountedObject >( - this, Thread::Current(), functor, callback, callback_host); + this, Thread::Current(), functor, callback, callback_host)); DoInvoke(thread, closure, id); } @@ -121,7 +121,8 @@ class AsyncInvoker : public MessageHandler { private: virtual void OnMessage(Message* msg); - void DoInvoke(Thread* thread, AsyncClosure* closure, uint32 id); + void DoInvoke(Thread* thread, const scoped_refptr& closure, + uint32 id); bool destroying_;