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

Unified Diff: base/bind_internal.h

Issue 2322313002: Split BindStateBase ctor for non-cancellable Bind (Closed)
Patch Set: revert to PS2 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/callback_internal.h » ('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 13e6bc152e8a2a8689ff94ae8532a5db522ab2ac..5845a4d031de9c3df658820a4b2f4cc3e545fe61 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -392,6 +392,7 @@ struct BindState;
template <typename BindStateType, typename SFINAE = void>
struct CancellationChecker {
+ static constexpr bool is_cancellable = false;
static bool Run(const BindStateBase*) {
return false;
}
@@ -402,6 +403,7 @@ struct CancellationChecker<
BindState<Functor, BoundArgs...>,
typename std::enable_if<IsWeakMethod<FunctorTraits<Functor>::is_method,
BoundArgs...>::value>::type> {
+ static constexpr bool is_cancellable = true;
static bool Run(const BindStateBase* base) {
using BindStateType = BindState<Functor, BoundArgs...>;
const BindStateType* bind_state = static_cast<const BindStateType*>(base);
@@ -411,6 +413,7 @@ struct CancellationChecker<
template <typename Signature, typename... BoundArgs>
struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> {
+ static constexpr bool is_cancellable = true;
static bool Run(const BindStateBase* base) {
using Functor = Callback<Signature>;
using BindStateType = BindState<Functor, BoundArgs...>;
@@ -424,10 +427,29 @@ struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> {
// This stores all the state passed into Bind().
template <typename Functor, typename... BoundArgs>
struct BindState final : BindStateBase {
+ using IsCancellable = std::integral_constant<
+ bool, CancellationChecker<BindState>::is_cancellable>;
+
template <typename ForwardFunctor, typename... ForwardBoundArgs>
explicit BindState(BindStateBase::InvokeFuncStorage invoke_func,
ForwardFunctor&& functor,
ForwardBoundArgs&&... bound_args)
+ // IsCancellable is std::false_type if the CancellationChecker<>::Run
+ // returns always false. Otherwise, it's std::true_type.
+ : BindState(IsCancellable{},
+ invoke_func,
+ std::forward<ForwardFunctor>(functor),
+ std::forward<ForwardBoundArgs>(bound_args)...) {}
+
+ Functor functor_;
+ std::tuple<BoundArgs...> bound_args_;
+
+ private:
+ template <typename ForwardFunctor, typename... ForwardBoundArgs>
+ explicit BindState(std::true_type,
+ BindStateBase::InvokeFuncStorage invoke_func,
+ ForwardFunctor&& functor,
+ ForwardBoundArgs&&... bound_args)
: BindStateBase(invoke_func, &Destroy,
&CancellationChecker<BindState>::Run),
functor_(std::forward<ForwardFunctor>(functor)),
@@ -435,10 +457,17 @@ struct BindState final : BindStateBase {
DCHECK(!IsNull(functor_));
}
- Functor functor_;
- std::tuple<BoundArgs...> bound_args_;
+ template <typename ForwardFunctor, typename... ForwardBoundArgs>
+ explicit BindState(std::false_type,
+ BindStateBase::InvokeFuncStorage invoke_func,
+ ForwardFunctor&& functor,
+ ForwardBoundArgs&&... bound_args)
+ : BindStateBase(invoke_func, &Destroy),
+ functor_(std::forward<ForwardFunctor>(functor)),
+ bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) {
+ DCHECK(!IsNull(functor_));
+ }
- private:
~BindState() {}
static void Destroy(BindStateBase* self) {
« no previous file with comments | « no previous file | base/callback_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698