diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-16 22:35:14 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-16 22:35:14 +0000 |
commit | 935405891d4f2cb40c4fe287e3e4c06ade5c38ce (patch) | |
tree | d71dd33fe46eeddb200d92dda1d02c9c0b8a7c10 /base/bind_helpers.h | |
parent | 409dc6ef2d6095d71f6ea4f59b07106b91626d24 (diff) | |
download | chromium_src-935405891d4f2cb40c4fe287e3e4c06ade5c38ce.zip chromium_src-935405891d4f2cb40c4fe287e3e4c06ade5c38ce.tar.gz chromium_src-935405891d4f2cb40c4fe287e3e4c06ade5c38ce.tar.bz2 |
Support binding WeakPtr<> to methods with void return types.
This should give functionality similar to ScopedRunnableMethodFactory.
Note that binding a WeakPtr only make sense with methods with void return types. If the return type is not void, then it is unclear what the function should return when the pointer is invalidated.
This code adds a compile time assert to check the return type.
BUG=35223
TEST=unittests
Review URL: http://codereview.chromium.org/7015064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind_helpers.h')
-rw-r--r-- | base/bind_helpers.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/base/bind_helpers.h b/base/bind_helpers.h index 73fd81e..e4b4a17 100644 --- a/base/bind_helpers.h +++ b/base/bind_helpers.h @@ -52,6 +52,7 @@ #pragma once #include "base/basictypes.h" +#include "base/memory/weak_ptr.h" #include "base/template_util.h" namespace base { @@ -215,7 +216,7 @@ const T& Unwrap(ConstRefWrapper<T> const_ref) { // Utility for handling different refcounting semantics in the Bind() // function. -template <typename ref, typename T> +template <typename IsMethod, typename T> struct MaybeRefcount; template <typename T> @@ -248,6 +249,12 @@ struct MaybeRefcount<base::true_type, const T*> { static void Release(const T* o) { o->Release(); } }; +template <typename T> +struct MaybeRefcount<base::true_type, WeakPtr<T> > { + static void AddRef(const WeakPtr<T>&) {} + static void Release(const WeakPtr<T>&) {} +}; + } // namespace internal template <typename T> |