tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

callback_internal.cc (1992B)


      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 
     10 namespace base {
     11 namespace internal {
     12 
     13 namespace {
     14 
     15 bool QueryCancellationTraitsForNonCancellables(
     16    const BindStateBase*,
     17    BindStateBase::CancellationQueryMode mode) {
     18  switch (mode) {
     19    case BindStateBase::IS_CANCELLED:
     20      return false;
     21    case BindStateBase::MAYBE_VALID:
     22      return true;
     23  }
     24  NOTREACHED();
     25  return false;
     26 }
     27 
     28 }  // namespace
     29 
     30 void BindStateBaseRefCountTraits::Destruct(const BindStateBase* bind_state) {
     31  bind_state->destructor_(bind_state);
     32 }
     33 
     34 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
     35                             void (*destructor)(const BindStateBase*))
     36    : BindStateBase(polymorphic_invoke,
     37                    destructor,
     38                    &QueryCancellationTraitsForNonCancellables) {}
     39 
     40 BindStateBase::BindStateBase(
     41    InvokeFuncStorage polymorphic_invoke,
     42    void (*destructor)(const BindStateBase*),
     43    bool (*query_cancellation_traits)(const BindStateBase*,
     44                                      CancellationQueryMode))
     45    : polymorphic_invoke_(polymorphic_invoke),
     46      destructor_(destructor),
     47      query_cancellation_traits_(query_cancellation_traits) {}
     48 
     49 BindStateHolder& BindStateHolder::operator=(BindStateHolder&&) noexcept =
     50    default;
     51 
     52 BindStateHolder::BindStateHolder(const BindStateHolder&) = default;
     53 
     54 BindStateHolder& BindStateHolder::operator=(const BindStateHolder&) = default;
     55 
     56 BindStateHolder::~BindStateHolder() = default;
     57 
     58 void BindStateHolder::Reset() {
     59  bind_state_ = nullptr;
     60 }
     61 
     62 bool BindStateHolder::IsCancelled() const {
     63  DCHECK(bind_state_);
     64  return bind_state_->IsCancelled();
     65 }
     66 
     67 bool BindStateHolder::MaybeValid() const {
     68  DCHECK(bind_state_);
     69  return bind_state_->MaybeValid();
     70 }
     71 
     72 }  // namespace internal
     73 }  // namespace base