Chromium Code Reviews| Index: base/bind_helpers.h |
| diff --git a/base/bind_helpers.h b/base/bind_helpers.h |
| index 590d788b96e0a650e22065884d4c8dc41d63531e..1e0d8f3f6b60005310a39dec414cd190046d5f25 100644 |
| --- a/base/bind_helpers.h |
| +++ b/base/bind_helpers.h |
| @@ -170,6 +170,10 @@ |
| #include "build/build_config.h" |
| namespace base { |
| + |
| +template <typename T> |
| +struct IsWeakReceiver; |
| + |
| namespace internal { |
| // Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T |
| @@ -459,15 +463,10 @@ T Unwrap(PassedWrapper<T>& o) { |
| // The first argument should be the type of the object that will be received by |
| // the method. |
| template <bool IsMethod, typename... Args> |
| -struct IsWeakMethod : public std::false_type {}; |
| +struct IsWeakMethod : std::false_type {}; |
| template <typename T, typename... Args> |
| -struct IsWeakMethod<true, WeakPtr<T>, Args...> : public std::true_type {}; |
| - |
| -template <typename T, typename... Args> |
| -struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T>>, Args...> |
| - : public std::true_type {}; |
| - |
| +struct IsWeakMethod<true, T, Args...> : IsWeakReceiver<T> {}; |
| // Packs a list of types to hold them in a single type. |
| template <typename... Types> |
| @@ -627,6 +626,25 @@ void DeletePointer(T* obj) { |
| delete obj; |
| } |
| +// An injection point to control |this| pointer behavior on a method invocation. |
| +// If IsWeakReceiver<> is true_type for |T| and |T| is used for a receiver of a |
| +// method, base::Bind cancels the method invocation if the receiver is null. |
|
danakj
2016/06/10 23:36:18
"if the receiver is tested as false" may be more a
tzik
2016/06/14 12:06:10
Done.
|
| +// E.g. Foo::bar() is not called: |
| +// struct Foo : base::SupportsWeakPtr<Foo> { |
| +// void bar() {} |
| +// }; |
| +// |
| +// WeakPtr<Foo> oo = nullptr; |
| +// base::Bind(&Foo::bar, oo).Run(); |
| +template <typename T> |
| +struct IsWeakReceiver : std::false_type {}; |
| + |
| +template <typename T> |
| +struct IsWeakReceiver<WeakPtr<T>> : std::true_type {}; |
| + |
| +template <typename T> |
| +struct IsWeakReceiver<internal::ConstRefWrapper<T>> : IsWeakReceiver<T> {}; |
|
danakj
2016/06/10 23:36:17
nit: Does it compile if you put this above the Wea
tzik
2016/06/14 12:06:10
Done.
|
| + |
| } // namespace base |
| #endif // BASE_BIND_HELPERS_H_ |