| Index: base/bind_helpers.h
|
| diff --git a/base/bind_helpers.h b/base/bind_helpers.h
|
| index 117fc68e177d59afe3c7dba93b2cd77ebb006a03..81dba6d8433fe604ce153a82f56aba50a437d949 100644
|
| --- a/base/bind_helpers.h
|
| +++ b/base/bind_helpers.h
|
| @@ -28,6 +28,9 @@
|
| // argument will CHECK() because the first invocation would have already
|
| // transferred ownership to the target function.
|
| //
|
| +// RetainedRef() accepts a ref counted object and retains a reference to it.
|
| +// When the callback is called, the object is passed as a raw pointer.
|
| +//
|
| // ConstRef() allows binding a constant reference to an argument rather
|
| // than a copy.
|
| //
|
| @@ -71,6 +74,19 @@
|
| // Without Owned(), someone would have to know to delete |pn| when the last
|
| // reference to the Callback is deleted.
|
| //
|
| +// EXAMPLE OF RetainedRef():
|
| +//
|
| +// void foo(RefCountedBytes* bytes) {}
|
| +//
|
| +// scoped_refptr<RefCountedBytes> bytes = ...;
|
| +// Closure callback = Bind(&foo, base::RetainedRef(bytes));
|
| +// callback.Run();
|
| +//
|
| +// Without RetainedRef, the scoped_refptr would try to implicitly convert to
|
| +// a raw pointer and fail compilation:
|
| +//
|
| +// Closure callback = Bind(&foo, bytes); // ERROR!
|
| +//
|
| //
|
| // EXAMPLE OF ConstRef():
|
| //
|
| @@ -312,6 +328,16 @@ class ConstRefWrapper {
|
| };
|
|
|
| template <typename T>
|
| +class RetainedRefWrapper {
|
| + public:
|
| + explicit RetainedRefWrapper(T* o) : ptr_(o) {}
|
| + explicit RetainedRefWrapper(scoped_refptr<T> o) : ptr_(std::move(o)) {}
|
| + T* get() const { return ptr_.get(); }
|
| + private:
|
| + scoped_refptr<T> ptr_;
|
| +};
|
| +
|
| +template <typename T>
|
| struct IgnoreResultHelper {
|
| explicit IgnoreResultHelper(T functor) : functor_(functor) {}
|
|
|
| @@ -410,6 +436,11 @@ T* Unwrap(const scoped_refptr<T>& o) {
|
| }
|
|
|
| template <typename T>
|
| +T* Unwrap(const RetainedRefWrapper<T>& o) {
|
| + return o.get();
|
| +}
|
| +
|
| +template <typename T>
|
| const WeakPtr<T>& Unwrap(const WeakPtr<T>& o) {
|
| return o;
|
| }
|
| @@ -545,6 +576,16 @@ static inline internal::UnretainedWrapper<T> Unretained(T* o) {
|
| }
|
|
|
| template <typename T>
|
| +static inline internal::RetainedRefWrapper<T> RetainedRef(T* o) {
|
| + return internal::RetainedRefWrapper<T>(o);
|
| +}
|
| +
|
| +template <typename T>
|
| +static inline internal::RetainedRefWrapper<T> RetainedRef(scoped_refptr<T> o) {
|
| + return internal::RetainedRefWrapper<T>(std::move(o));
|
| +}
|
| +
|
| +template <typename T>
|
| static inline internal::ConstRefWrapper<T> ConstRef(const T& o) {
|
| return internal::ConstRefWrapper<T>(o);
|
| }
|
|
|