| 6 |
| 7 | #include "base/logging.h" |
| 8 |
| 9 | namespace base { |
| 10 | namespace internal { |
| 11 |
| 12 | namespace { |
| 13 |
| 14 | bool QueryCancellationTraitsForNonCancellables( |
| 15 | const BindStateBase*, |
| 16 | BindStateBase::CancellationQueryMode mode) { |
| 17 | switch (mode) { |
| 18 | case BindStateBase::IS_CANCELLED: |
| 19 | return false; |
| 20 | case BindStateBase::MAYBE_VALID: |
| 21 | return true; |
| 22 | } |
| 23 | NOTREACHED(); |
| 24 | } |
| 25 |
| 26 | } // namespace |
| 27 |
| 28 | void BindStateBaseRefCountTraits::Destruct(const BindStateBase* bind_state) { |
| 29 | bind_state->destructor_(bind_state); |
| 30 | } |
| 31 |
| 32 | BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke, |
| 33 | void (*destructor)(const BindStateBase*)) |
| 34 | : BindStateBase(polymorphic_invoke, |
| 35 | destructor, |
| 36 | &QueryCancellationTraitsForNonCancellables) {} |
| 37 |
| 38 | BindStateBase::BindStateBase( |
| 39 | InvokeFuncStorage polymorphic_invoke, |
| 40 | void (*destructor)(const BindStateBase*), |
| 41 | bool (*query_cancellation_traits)(const BindStateBase*, |
| 42 | CancellationQueryMode)) |
| 43 | : polymorphic_invoke_(polymorphic_invoke), |
| 44 | destructor_(destructor), |
| 45 | query_cancellation_traits_(query_cancellation_traits) {} |
| 46 |
| 47 | CallbackBase& CallbackBase::operator=(CallbackBase&& c) noexcept = default; |
| 48 | CallbackBase::CallbackBase(const CallbackBaseCopyable& c) |
| 49 | : bind_state_(c.bind_state_) {} |
| 50 |
| 51 | CallbackBase& CallbackBase::operator=(const CallbackBaseCopyable& c) { |
| 52 | bind_state_ = c.bind_state_; |
| 53 | return *this; |
| 54 | } |
| 55 |
| 56 | CallbackBase::CallbackBase(CallbackBaseCopyable&& c) noexcept |
| 57 | : bind_state_(std::move(c.bind_state_)) {} |
| 58 |
| 59 | CallbackBase& CallbackBase::operator=(CallbackBaseCopyable&& c) noexcept { |
| 60 | bind_state_ = std::move(c.bind_state_); |
| 61 | return *this; |
| 62 | } |
| 63 |
| 64 | void CallbackBase::Reset() { |
| 65 | // NULL the bind_state_ last, since it may be holding the last ref to whatever |
| 66 | // object owns us, and we may be deleted after that. |
| 67 | bind_state_ = nullptr; |
| 68 | } |
| 69 |
| 70 | bool CallbackBase::IsCancelled() const { |
| 71 | DCHECK(bind_state_); |
| 72 | return bind_state_->IsCancelled(); |
| 73 | } |
| 74 |
| 75 | bool CallbackBase::MaybeValid() const { |
| 76 | DCHECK(bind_state_); |
| 77 | return bind_state_->MaybeValid(); |
| 78 | } |
| 79 |
| 80 | bool CallbackBase::EqualsInternal(const CallbackBase& other) const { |
| 81 | return bind_state_ == other.bind_state_; |
| 82 | } |
| 83 |
| 84 | CallbackBase::~CallbackBase() = default; |
| 85 |
| 86 | CallbackBaseCopyable::CallbackBaseCopyable(const CallbackBaseCopyable& c) { |
| 87 | bind_state_ = c.bind_state_; |
| 88 | } |
| 89 |
| 90 | CallbackBaseCopyable& CallbackBaseCopyable::operator=( |
| 91 | const CallbackBaseCopyable& c) { |
| 92 | bind_state_ = c.bind_state_; |
| 93 | return *this; |
| 94 | } |
| 95 |
| 96 | CallbackBaseCopyable& CallbackBaseCopyable::operator=( |
| 97 | CallbackBaseCopyable&& c) noexcept = default; |
| 98 |
| 99 | } // namespace internal |
| 100 | } // namespace base |
| 101 |