xref: /aosp_15_r20/external/cronet/base/functional/callback_internal.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/functional/callback_internal.h"
6 
7 #include "base/check.h"
8 #include "base/notreached.h"
9 #include "base/types/cxx23_to_underlying.h"
10 
11 namespace base {
12 namespace internal {
13 
14 namespace {
15 
QueryCancellationTraitsForNonCancellables(const BindStateBase *,BindStateBase::CancellationQueryMode mode)16 bool QueryCancellationTraitsForNonCancellables(
17     const BindStateBase*,
18     BindStateBase::CancellationQueryMode mode) {
19   // Non-cancellables are never cancelled and always valid, which means the
20   // response for each mode is the same as its underlying value.
21   return to_underlying(mode);
22 }
23 
24 }  // namespace
25 
Destruct(const BindStateBase * bind_state)26 void BindStateBaseRefCountTraits::Destruct(const BindStateBase* bind_state) {
27   bind_state->destructor_(bind_state);
28 }
29 
BindStateBase(InvokeFuncStorage polymorphic_invoke,DestructorPtr destructor)30 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
31                              DestructorPtr destructor)
32     : BindStateBase(polymorphic_invoke,
33                     destructor,
34                     &QueryCancellationTraitsForNonCancellables) {}
35 
BindStateBase(InvokeFuncStorage polymorphic_invoke,DestructorPtr destructor,QueryCancellationTraitsPtr query_cancellation_traits)36 BindStateBase::BindStateBase(
37     InvokeFuncStorage polymorphic_invoke,
38     DestructorPtr destructor,
39     QueryCancellationTraitsPtr query_cancellation_traits)
40     : polymorphic_invoke_(polymorphic_invoke),
41       destructor_(destructor),
42       query_cancellation_traits_(query_cancellation_traits) {}
43 
44 BindStateHolder& BindStateHolder::operator=(BindStateHolder&&) noexcept =
45     default;
46 
47 BindStateHolder::BindStateHolder(const BindStateHolder&) = default;
48 
49 BindStateHolder& BindStateHolder::operator=(const BindStateHolder&) = default;
50 
51 BindStateHolder::~BindStateHolder() = default;
52 
Reset()53 void BindStateHolder::Reset() {
54   bind_state_ = nullptr;
55 }
56 
IsCancelled() const57 bool BindStateHolder::IsCancelled() const {
58   DCHECK(bind_state_);
59   return bind_state_->IsCancelled();
60 }
61 
MaybeValid() const62 bool BindStateHolder::MaybeValid() const {
63   DCHECK(bind_state_);
64   return bind_state_->MaybeValid();
65 }
66 
67 }  // namespace internal
68 }  // namespace base
69