Skip to content

Commit

Permalink
Support binding WeakPtr<> to methods with void return types.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ajwong@chromium.org committed May 16, 2011
1 parent 409dc6e commit 9354058
Show file tree
Hide file tree
Showing 9 changed files with 676 additions and 76 deletions.
9 changes: 8 additions & 1 deletion base/bind_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#pragma once

#include "base/basictypes.h"
#include "base/memory/weak_ptr.h"
#include "base/template_util.h"

namespace base {
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Loading

0 comments on commit 9354058

Please sign in to comment.