Update include/base headers for C++11/14 (see issue #3140)

See the issue for update guidelines.
This commit is contained in:
Marshall Greenblatt
2021-06-17 15:40:57 -04:00
parent 6d80ec69d7
commit 43f9baa23a
57 changed files with 5466 additions and 11523 deletions

View File

@@ -7,35 +7,94 @@
#include "include/base/cef_logging.h"
namespace base {
namespace cef_internal {
namespace internal {
void BindStateBase::AddRef() {
AtomicRefCountInc(&ref_count_);
namespace {
bool QueryCancellationTraitsForNonCancellables(
const BindStateBase*,
BindStateBase::CancellationQueryMode mode) {
switch (mode) {
case BindStateBase::IS_CANCELLED:
return false;
case BindStateBase::MAYBE_VALID:
return true;
}
NOTREACHED();
}
void BindStateBase::Release() {
if (!AtomicRefCountDec(&ref_count_))
destructor_(this);
} // namespace
void BindStateBaseRefCountTraits::Destruct(const BindStateBase* bind_state) {
bind_state->destructor_(bind_state);
}
BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
void (*destructor)(const BindStateBase*))
: BindStateBase(polymorphic_invoke,
destructor,
&QueryCancellationTraitsForNonCancellables) {}
BindStateBase::BindStateBase(
InvokeFuncStorage polymorphic_invoke,
void (*destructor)(const BindStateBase*),
bool (*query_cancellation_traits)(const BindStateBase*,
CancellationQueryMode))
: polymorphic_invoke_(polymorphic_invoke),
destructor_(destructor),
query_cancellation_traits_(query_cancellation_traits) {}
CallbackBase& CallbackBase::operator=(CallbackBase&& c) noexcept = default;
CallbackBase::CallbackBase(const CallbackBaseCopyable& c)
: bind_state_(c.bind_state_) {}
CallbackBase& CallbackBase::operator=(const CallbackBaseCopyable& c) {
bind_state_ = c.bind_state_;
return *this;
}
CallbackBase::CallbackBase(CallbackBaseCopyable&& c) noexcept
: bind_state_(std::move(c.bind_state_)) {}
CallbackBase& CallbackBase::operator=(CallbackBaseCopyable&& c) noexcept {
bind_state_ = std::move(c.bind_state_);
return *this;
}
void CallbackBase::Reset() {
polymorphic_invoke_ = NULL;
// NULL the bind_state_ last, since it may be holding the last ref to whatever
// object owns us, and we may be deleted after that.
bind_state_ = NULL;
bind_state_ = nullptr;
}
bool CallbackBase::Equals(const CallbackBase& other) const {
return bind_state_.get() == other.bind_state_.get() &&
polymorphic_invoke_ == other.polymorphic_invoke_;
bool CallbackBase::IsCancelled() const {
DCHECK(bind_state_);
return bind_state_->IsCancelled();
}
CallbackBase::CallbackBase(BindStateBase* bind_state)
: bind_state_(bind_state), polymorphic_invoke_(NULL) {
DCHECK(!bind_state_.get() || bind_state_->ref_count_ == 1);
bool CallbackBase::MaybeValid() const {
DCHECK(bind_state_);
return bind_state_->MaybeValid();
}
CallbackBase::~CallbackBase() {}
bool CallbackBase::EqualsInternal(const CallbackBase& other) const {
return bind_state_ == other.bind_state_;
}
} // namespace cef_internal
CallbackBase::~CallbackBase() = default;
CallbackBaseCopyable::CallbackBaseCopyable(const CallbackBaseCopyable& c) {
bind_state_ = c.bind_state_;
}
CallbackBaseCopyable& CallbackBaseCopyable::operator=(
const CallbackBaseCopyable& c) {
bind_state_ = c.bind_state_;
return *this;
}
CallbackBaseCopyable& CallbackBaseCopyable::operator=(
CallbackBaseCopyable&& c) noexcept = default;
} // namespace internal
} // namespace base