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

Side by Side Diff: base/bind_internal.h

Issue 2355763002: Support nested OnceCallback on Callback::IsCancelled (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_BIND_INTERNAL_H_ 5 #ifndef BASE_BIND_INTERNAL_H_
6 #define BASE_BIND_INTERNAL_H_ 6 #define BASE_BIND_INTERNAL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <tuple> 10 #include <tuple>
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 typename std::enable_if<IsWeakMethod<FunctorTraits<Functor>::is_method, 404 typename std::enable_if<IsWeakMethod<FunctorTraits<Functor>::is_method,
405 BoundArgs...>::value>::type> { 405 BoundArgs...>::value>::type> {
406 static constexpr bool is_cancellable = true; 406 static constexpr bool is_cancellable = true;
407 static bool Run(const BindStateBase* base) { 407 static bool Run(const BindStateBase* base) {
408 using BindStateType = BindState<Functor, BoundArgs...>; 408 using BindStateType = BindState<Functor, BoundArgs...>;
409 const BindStateType* bind_state = static_cast<const BindStateType*>(base); 409 const BindStateType* bind_state = static_cast<const BindStateType*>(base);
410 return !base::get<0>(bind_state->bound_args_); 410 return !base::get<0>(bind_state->bound_args_);
411 } 411 }
412 }; 412 };
413 413
414 template <typename BindStateType>
415 struct CallbackCancellationChecker {
416 static constexpr bool is_cancellable = true;
417 static bool Run(const BindStateBase* base) {
418 return static_cast<const BindStateType*>(base)->functor_.IsCancelled();
419 }
420 };
421
414 template <typename Signature, typename... BoundArgs> 422 template <typename Signature, typename... BoundArgs>
415 struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> { 423 struct CancellationChecker<BindState<OnceCallback<Signature>, BoundArgs...>>
416 static constexpr bool is_cancellable = true; 424 : CallbackCancellationChecker<
417 static bool Run(const BindStateBase* base) { 425 BindState<OnceCallback<Signature>, BoundArgs...>> {};
418 using Functor = Callback<Signature>; 426
419 using BindStateType = BindState<Functor, BoundArgs...>; 427 template <typename Signature, typename... BoundArgs>
420 const BindStateType* bind_state = static_cast<const BindStateType*>(base); 428 struct CancellationChecker<
421 return bind_state->functor_.IsCancelled(); 429 BindState<RepeatingCallback<Signature>, BoundArgs...>>
422 } 430 : CallbackCancellationChecker<
423 }; 431 BindState<RepeatingCallback<Signature>, BoundArgs...>> {};
424 432
425 // BindState<> 433 // BindState<>
426 // 434 //
427 // This stores all the state passed into Bind(). 435 // This stores all the state passed into Bind().
428 template <typename Functor, typename... BoundArgs> 436 template <typename Functor, typename... BoundArgs>
429 struct BindState final : BindStateBase { 437 struct BindState final : BindStateBase {
430 using IsCancellable = std::integral_constant< 438 using IsCancellable = std::integral_constant<
431 bool, CancellationChecker<BindState>::is_cancellable>; 439 bool, CancellationChecker<BindState>::is_cancellable>;
432 440
433 template <typename ForwardFunctor, typename... ForwardBoundArgs> 441 template <typename ForwardFunctor, typename... ForwardBoundArgs>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 531
524 // Returns a RunType of bound functor. 532 // Returns a RunType of bound functor.
525 // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C). 533 // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C).
526 template <typename Functor, typename... BoundArgs> 534 template <typename Functor, typename... BoundArgs>
527 using MakeUnboundRunType = 535 using MakeUnboundRunType =
528 typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type; 536 typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type;
529 537
530 } // namespace base 538 } // namespace base
531 539
532 #endif // BASE_BIND_INTERNAL_H_ 540 #endif // BASE_BIND_INTERNAL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698