1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/callback_internal.h"
7 #include "base/check.h"
8 #include "base/notreached.h"
15 bool QueryCancellationTraitsForNonCancellables(
17 BindStateBase::CancellationQueryMode mode) {
19 case BindStateBase::IS_CANCELLED:
21 case BindStateBase::MAYBE_VALID:
29 void BindStateBaseRefCountTraits::Destruct(const BindStateBase* bind_state) {
30 bind_state->destructor_(bind_state);
33 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
34 void (*destructor)(const BindStateBase*))
35 : BindStateBase(polymorphic_invoke,
37 &QueryCancellationTraitsForNonCancellables) {}
39 BindStateBase::BindStateBase(
40 InvokeFuncStorage polymorphic_invoke,
41 void (*destructor)(const BindStateBase*),
42 bool (*query_cancellation_traits)(const BindStateBase*,
43 CancellationQueryMode))
44 : polymorphic_invoke_(polymorphic_invoke),
45 destructor_(destructor),
46 query_cancellation_traits_(query_cancellation_traits) {}
48 CallbackBase& CallbackBase::operator=(CallbackBase&& c) noexcept = default;
49 CallbackBase::CallbackBase(const CallbackBaseCopyable& c)
50 : bind_state_(c.bind_state_) {}
52 CallbackBase& CallbackBase::operator=(const CallbackBaseCopyable& c) {
53 bind_state_ = c.bind_state_;
57 CallbackBase::CallbackBase(CallbackBaseCopyable&& c) noexcept
58 : bind_state_(std::move(c.bind_state_)) {}
60 CallbackBase& CallbackBase::operator=(CallbackBaseCopyable&& c) noexcept {
61 bind_state_ = std::move(c.bind_state_);
65 void CallbackBase::Reset() {
66 // NULL the bind_state_ last, since it may be holding the last ref to whatever
67 // object owns us, and we may be deleted after that.
68 bind_state_ = nullptr;
71 bool CallbackBase::IsCancelled() const {
73 return bind_state_->IsCancelled();
76 bool CallbackBase::MaybeValid() const {
78 return bind_state_->MaybeValid();
81 bool CallbackBase::EqualsInternal(const CallbackBase& other) const {
82 return bind_state_ == other.bind_state_;
85 CallbackBase::~CallbackBase() = default;
87 CallbackBaseCopyable::CallbackBaseCopyable(const CallbackBaseCopyable& c) {
88 bind_state_ = c.bind_state_;
91 CallbackBaseCopyable& CallbackBaseCopyable::operator=(
92 const CallbackBaseCopyable& c) {
93 bind_state_ = c.bind_state_;
97 CallbackBaseCopyable& CallbackBaseCopyable::operator=(
98 CallbackBaseCopyable&& c) noexcept = default;
100 } // namespace internal