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/logging.h"
14 bool ReturnFalse(const BindStateBase*) {
20 void BindStateBaseRefCountTraits::Destruct(const BindStateBase* bind_state) {
21 bind_state->destructor_(bind_state);
24 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
25 void (*destructor)(const BindStateBase*))
26 : BindStateBase(polymorphic_invoke, destructor, &ReturnFalse) {
29 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
30 void (*destructor)(const BindStateBase*),
31 bool (*is_cancelled)(const BindStateBase*))
32 : polymorphic_invoke_(polymorphic_invoke),
33 destructor_(destructor),
34 is_cancelled_(is_cancelled) {}
36 CallbackBase& CallbackBase::operator=(CallbackBase&& c) noexcept = default;
37 CallbackBase::CallbackBase(const CallbackBaseCopyable& c)
38 : bind_state_(c.bind_state_) {}
40 CallbackBase& CallbackBase::operator=(const CallbackBaseCopyable& c) {
41 bind_state_ = c.bind_state_;
45 CallbackBase::CallbackBase(CallbackBaseCopyable&& c) noexcept
46 : bind_state_(std::move(c.bind_state_)) {}
48 CallbackBase& CallbackBase::operator=(CallbackBaseCopyable&& c) noexcept {
49 bind_state_ = std::move(c.bind_state_);
53 void CallbackBase::Reset() {
54 // NULL the bind_state_ last, since it may be holding the last ref to whatever
55 // object owns us, and we may be deleted after that.
56 bind_state_ = nullptr;
59 bool CallbackBase::IsCancelled() const {
61 return bind_state_->IsCancelled();
64 bool CallbackBase::EqualsInternal(const CallbackBase& other) const {
65 return bind_state_ == other.bind_state_;
68 CallbackBase::~CallbackBase() = default;
70 CallbackBaseCopyable::CallbackBaseCopyable(const CallbackBaseCopyable& c) {
71 bind_state_ = c.bind_state_;
74 CallbackBaseCopyable& CallbackBaseCopyable::operator=(
75 const CallbackBaseCopyable& c) {
76 bind_state_ = c.bind_state_;
80 CallbackBaseCopyable& CallbackBaseCopyable::operator=(
81 CallbackBaseCopyable&& c) noexcept = default;
83 } // namespace internal