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

Unified Diff: base/bind_internal.h

Issue 2289703002: Add Callback::IsCancelled (Closed)
Patch Set: revert to PS5 Created 4 years, 3 months 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_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_internal.h
diff --git a/base/bind_internal.h b/base/bind_internal.h
index 0c7c8abda227de1cb2b29c2ab211106c20a5a8c9..98a73908375394b8e03b70eea60b40741aba4b0d 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -373,6 +373,38 @@ IsNull(const Functor&) {
return false;
}
+template <typename Functor, typename... BoundArgs>
+struct BindState;
+
+template <typename BindStateType, typename SFINAE = void>
+struct CancellationChecker {
+ static bool Run(const BindStateBase*) {
+ return false;
+ }
+};
+
+template <typename Functor, typename... BoundArgs>
+struct CancellationChecker<
+ BindState<Functor, BoundArgs...>,
+ typename std::enable_if<IsWeakMethod<FunctorTraits<Functor>::is_method,
+ BoundArgs...>::value>::type> {
+ static bool Run(const BindStateBase* base) {
+ using BindStateType = BindState<Functor, BoundArgs...>;
+ const BindStateType* bind_state = static_cast<const BindStateType*>(base);
+ return !base::get<0>(bind_state->bound_args_);
+ }
+};
+
+template <typename Signature, typename... BoundArgs>
+struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> {
+ static bool Run(const BindStateBase* base) {
+ using Functor = Callback<Signature>;
+ using BindStateType = BindState<Functor, BoundArgs...>;
+ const BindStateType* bind_state = static_cast<const BindStateType*>(base);
+ return bind_state->functor_.IsCancelled();
+ }
+};
+
// BindState<>
//
// This stores all the state passed into Bind().
@@ -382,7 +414,8 @@ struct BindState final : BindStateBase {
explicit BindState(BindStateBase::InvokeFuncStorage invoke_func,
ForwardFunctor&& functor,
ForwardBoundArgs&&... bound_args)
- : BindStateBase(invoke_func, &Destroy),
+ : BindStateBase(invoke_func, &Destroy,
+ &CancellationChecker<BindState>::Run),
functor_(std::forward<ForwardFunctor>(functor)),
bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) {
DCHECK(!IsNull(functor_));
« no previous file with comments | « no previous file | base/bind_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698