diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 00:25:29 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 00:25:29 +0000 |
commit | 7a15d117f34715773a07e821d6d259cc6e726ef9 (patch) | |
tree | 04a63437171eacb6c1b09669d205e8c1a60ee128 /base/bind_helpers.h | |
parent | e210c08d24f9ab65cac1f97127af1fbf6d8574f8 (diff) | |
download | chromium_src-7a15d117f34715773a07e821d6d259cc6e726ef9.zip chromium_src-7a15d117f34715773a07e821d6d259cc6e726ef9.tar.gz chromium_src-7a15d117f34715773a07e821d6d259cc6e726ef9.tar.bz2 |
Support scoped_refptr<> as the object for a method call in base::Bind(). Reduce useless copies.
Patch up an API hole where you can't do base::Bind(&Foo::method, ptr), if ptr is a scoped_refptr.
Also modify Unwrap() to remove a couple of unecessary copies for scoped_refptrs, and WeakPtrs<>.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8171013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104399 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind_helpers.h')
-rw-r--r-- | base/bind_helpers.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/base/bind_helpers.h b/base/bind_helpers.h index 7eb5716..07f11f9 100644 --- a/base/bind_helpers.h +++ b/base/bind_helpers.h @@ -227,6 +227,11 @@ const T& Unwrap(ConstRefWrapper<T> const_ref) { return const_ref.get(); } +template <typename T> +T* Unwrap(const scoped_refptr<T>& o) { return o.get(); } + +template <typename T> +const WeakPtr<T>& Unwrap(const WeakPtr<T>& o) { return o; } // Utility for handling different refcounting semantics in the Bind() // function. @@ -257,6 +262,14 @@ struct MaybeRefcount<base::true_type, T*> { static void Release(T* o) { o->Release(); } }; +// No need to additionally AddRef() and Release() since we are storing a +// scoped_refptr<> inside the storage object already. +template <typename T> +struct MaybeRefcount<base::true_type, scoped_refptr<T> > { + static void AddRef(const scoped_refptr<T>& o) {} + static void Release(const scoped_refptr<T>& o) {} +}; + template <typename T> struct MaybeRefcount<base::true_type, const T*> { static void AddRef(const T* o) { o->AddRef(); } |