Index: base/bind_helpers.h |
diff --git a/base/bind_helpers.h b/base/bind_helpers.h |
index c7c7be8ee840a7b52206787fa8f717dcc4de4e30..68e9320f9da24b4e9a85f842ccda92cf4019ebb0 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,50 @@ struct BindUnwrapTraits<internal::PassedWrapper<T>> { |
} |
}; |
+// An injection point to support Callback::IsCancelled in a specific form of |
+// base::Bind. |
dcheng
2016/11/10 07:36:23
Nit: I'd make this comment mostly descriptive abou
alex clarke (OOO till 29th)
2016/11/10 10:02:21
+1
tzik
2016/11/15 11:40:35
Done.
|
+// Specialize CallbackCancellationTraits to support Callback::IsCancelled, set |
+// is_cancellable to true in the specialization, and implement Run() method. |
+// CallbackCancellationTraits<>::Run() should return true if the resulting |
+// callback is cancelled. |
+template <typename Functor, typename BoundArgsTuple, typename SFINAE = void> |
+struct CallbackCancellationTraits { |
+ static constexpr bool is_cancellable = false; |
+}; |
+ |
+// Specialization for method bound to weak pointer receiver. |
+template <typename Functor, typename... BoundArgs> |
+struct CallbackCancellationTraits< |
+ 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 IsCancelled(const Functor&, |
+ const Receiver& receiver, |
+ const Args&...) { |
+ return !receiver; |
+ } |
+}; |
+ |
+// Specialization for a nested bind. |
+template <typename Signature, |
+ typename... BoundArgs, |
+ internal::CopyMode copy_mode, |
+ internal::RepeatMode repeat_mode> |
+struct CallbackCancellationTraits<Callback<Signature, copy_mode, repeat_mode>, |
+ std::tuple<BoundArgs...>> { |
+ static constexpr bool is_cancellable = true; |
+ |
+ template <typename Functor> |
+ static bool IsCancelled(const Functor& functor, const BoundArgs&...) { |
+ return functor.IsCancelled(); |
+ } |
+}; |
+ |
} // namespace base |
#endif // BASE_BIND_HELPERS_H_ |