diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-21 23:10:57 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-21 23:10:57 +0000 |
commit | af4876d348f986491afae8818613351d48192bfd (patch) | |
tree | c43ac118a1436eb7e244ab99d9cc9f986923f11b /net/base/completion_callback.h | |
parent | 2296ac4b146d7614d812dc56aeee53c14459b342 (diff) | |
download | chromium_src-af4876d348f986491afae8818613351d48192bfd.zip chromium_src-af4876d348f986491afae8818613351d48192bfd.tar.gz chromium_src-af4876d348f986491afae8818613351d48192bfd.tar.bz2 |
Remove HttpTransaction::Destroy(), and do automatic memory management with scoped_ptr<>.
Review URL: http://codereview.chromium.org/7532
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3701 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/completion_callback.h')
-rw-r--r-- | net/base/completion_callback.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/net/base/completion_callback.h b/net/base/completion_callback.h index 0c8c922..4013f71 100644 --- a/net/base/completion_callback.h +++ b/net/base/completion_callback.h @@ -23,6 +23,36 @@ class CompletionCallbackImpl : } }; +// CancelableCompletionCallback is used for completion callbacks +// which may outlive the target for the method dispatch. In such a case, the +// provider of the callback calls Cancel() to mark the callback as +// "canceled". When the canceled callback is eventually run it does nothing +// other than to decrement the refcount to 0 and free the memory. +template <class T> +class CancelableCompletionCallback : + public CompletionCallbackImpl<T>, + public base::RefCounted<CancelableCompletionCallback<T> > { + public: + CancelableCompletionCallback(T* obj, void (T::* meth)(int)) + : CompletionCallbackImpl<T>(obj, meth), is_canceled_(false) { + } + + void Cancel() { + is_canceled_ = true; + } + + virtual void RunWithParams(const Tuple1<int>& params) { + if (is_canceled_) { + base::RefCounted<CancelableCompletionCallback<T> >::Release(); + } else { + CompletionCallbackImpl<T>::RunWithParams(params); + } + } + + private: + bool is_canceled_; +}; + } // namespace net #endif // NET_BASE_COMPLETION_CALLBACK_H__ |