Chromium Code Reviews| Index: base/bind_helpers.h |
| diff --git a/base/bind_helpers.h b/base/bind_helpers.h |
| index c7c7be8ee840a7b52206787fa8f717dcc4de4e30..1902341324e1c0bf42429191b522ef366df8239d 100644 |
| --- a/base/bind_helpers.h |
| +++ b/base/bind_helpers.h |
| @@ -179,6 +179,9 @@ struct BindUnwrapTraits; |
| namespace internal { |
| +template <typename Functor, typename SFINAE = void> |
| +struct FunctorTraits; |
| + |
| template <typename T> |
| class UnretainedWrapper { |
| public: |
| @@ -521,6 +524,47 @@ struct BindUnwrapTraits<internal::PassedWrapper<T>> { |
| } |
| }; |
| +// An injection point to support Callback::IsCancelled in a specific form of |
| +// base::Bind. |
| +// Specialize BindCancellationChecker to support Callback::IsCancelled, set |
| +// is_cancellable to true in the specialization, and implement Run() method. |
| +// BindCancellationChecker<>::Run() should return true if the resulting callback |
| +// is cancelled. |
| +template <typename Functor, typename BoundArgsTuple, typename SFINAE = void> |
| +struct BindCancellationChecker { |
|
dcheng
2016/11/10 06:29:23
My main thoughts are around naming.
Most of our i
tzik
2016/11/10 07:21:14
Done.
|
| + static constexpr bool is_cancellable = false; |
| +}; |
| + |
| +// Specialization for method bound to weak pointer receiver. |
| +template <typename Functor, typename... BoundArgs> |
| +struct BindCancellationChecker<Functor, |
| + std::tuple<BoundArgs...>, |
| + typename std::enable_if<internal::IsWeakMethod< |
| + internal::FunctorTraits<Functor>::is_method, |
| + BoundArgs...>::value>::type> { |
| + static constexpr bool is_cancellable = true; |
| + |
| + template <typename Receiver, typename... Args> |
| + static bool Run(const Functor&, const Receiver& receiver, const Args&...) { |
|
dcheng
2016/11/10 06:29:23
Similarly, I think calling this Run() is a bit con
tzik
2016/11/10 07:21:14
Done.
|
| + return !receiver; |
| + } |
| +}; |
| + |
| +// Specialization for a nested bind. |
| +template <typename Signature, |
| + typename... BoundArgs, |
| + internal::CopyMode copy_mode, |
| + internal::RepeatMode repeat_mode> |
| +struct BindCancellationChecker<Callback<Signature, copy_mode, repeat_mode>, |
| + std::tuple<BoundArgs...>> { |
| + static constexpr bool is_cancellable = true; |
| + |
| + template <typename Functor> |
| + static bool Run(const Functor& functor, const BoundArgs&...) { |
| + return functor.IsCancelled(); |
| + } |
| +}; |
| + |
| } // namespace base |
| #endif // BASE_BIND_HELPERS_H_ |