| Index: base/bind_helpers.h
|
| diff --git a/base/bind_helpers.h b/base/bind_helpers.h
|
| index 6e0f8fe72742a06f7875d5f73a4b9e0ec97f6c45..c6e0e1c2b1cc09a33b8441fc68f450d8806ea164 100644
|
| --- a/base/bind_helpers.h
|
| +++ b/base/bind_helpers.h
|
| @@ -90,6 +90,7 @@
|
| #include "base/basictypes.h"
|
| #include "base/bind.h"
|
| #include "base/callback.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/template_util.h"
|
|
|
| @@ -287,6 +288,19 @@ class OwnedWrapper {
|
| mutable T* ptr_;
|
| };
|
|
|
| +template <typename T>
|
| +class PassScopedWrapper {
|
| + public:
|
| + explicit PassScopedWrapper(T scoper) : scoper_(scoper.Pass()) {}
|
| + PassScopedWrapper(const PassScopedWrapper& other)
|
| + : scoper_(other.scoper_.Pass()) {
|
| + }
|
| + T Pass() const { return scoper_.Pass(); }
|
| +
|
| + private:
|
| + mutable T scoper_;
|
| +};
|
| +
|
| // Unwrap the stored parameters for the wrappers above.
|
| template <typename T>
|
| struct UnwrapTraits {
|
| @@ -330,9 +344,16 @@ struct UnwrapTraits<OwnedWrapper<T> > {
|
| }
|
| };
|
|
|
| +
|
| +template <typename T>
|
| +T& BindMoveSupport(T& t) { return t; }
|
| +
|
| +template <typename T>
|
| +T BindMoveSupport(const PassScopedWrapper<T>& p) { return p.Pass(); }
|
| +
|
| // Utility for handling different refcounting semantics in the Bind()
|
| // function.
|
| -template <bool, typename T>
|
| +template <bool is_method, typename T>
|
| struct MaybeRefcount;
|
|
|
| template <typename T>
|
| @@ -348,21 +369,15 @@ struct MaybeRefcount<false, T[n]> {
|
| };
|
|
|
| template <typename T>
|
| -struct MaybeRefcount<true, T*> {
|
| - static void AddRef(T* o) { o->AddRef(); }
|
| - static void Release(T* o) { o->Release(); }
|
| -};
|
| -
|
| -template <typename T>
|
| -struct MaybeRefcount<true, UnretainedWrapper<T> > {
|
| - static void AddRef(const UnretainedWrapper<T>&) {}
|
| - static void Release(const UnretainedWrapper<T>&) {}
|
| +struct MaybeRefcount<true, T> {
|
| + static void AddRef(const T&) {}
|
| + static void Release(const T&) {}
|
| };
|
|
|
| template <typename T>
|
| -struct MaybeRefcount<true, OwnedWrapper<T> > {
|
| - static void AddRef(const OwnedWrapper<T>&) {}
|
| - static void Release(const OwnedWrapper<T>&) {}
|
| +struct MaybeRefcount<true, T*> {
|
| + static void AddRef(T* o) { o->AddRef(); }
|
| + static void Release(T* o) { o->Release(); }
|
| };
|
|
|
| // No need to additionally AddRef() and Release() since we are storing a
|
| @@ -379,12 +394,6 @@ struct MaybeRefcount<true, const T*> {
|
| static void Release(const T* o) { o->Release(); }
|
| };
|
|
|
| -template <typename T>
|
| -struct MaybeRefcount<true, WeakPtr<T> > {
|
| - static void AddRef(const WeakPtr<T>&) {}
|
| - static void Release(const WeakPtr<T>&) {}
|
| -};
|
| -
|
| template <typename R>
|
| void VoidReturnAdapter(Callback<R(void)> callback) {
|
| callback.Run();
|
| @@ -422,6 +431,11 @@ static inline internal::OwnedWrapper<T> Owned(T* o) {
|
| return internal::OwnedWrapper<T>(o);
|
| }
|
|
|
| +template <typename T>
|
| +static inline internal::PassScopedWrapper<T> PassScoped(T* scoper) {
|
| + return internal::PassScopedWrapper<T>(scoper->Pass());
|
| +}
|
| +
|
| template <typename R>
|
| static inline Closure IgnoreReturn(Callback<R(void)> callback) {
|
| return Bind(&internal::VoidReturnAdapter<R>, callback);
|
| @@ -438,7 +452,6 @@ IgnoreResult(const Callback<T>& data) {
|
| return internal::IgnoreResultHelper<Callback<T> >(data);
|
| }
|
|
|
| -
|
| } // namespace base
|
|
|
| #endif // BASE_BIND_HELPERS_H_
|
|
|