Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1962)

Unified Diff: base/bind_helpers.h

Issue 2487493004: Support external task cancellation mechanisms in base::Callback::IsCancelled (Closed)
Patch Set: s/BindCancellationChecker/CallbackCancellationTraits/ Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698