diff --git a/include/base/cef_ref_counted.h b/include/base/cef_ref_counted.h index a0ca7813e..f0433bd77 100644 --- a/include/base/cef_ref_counted.h +++ b/include/base/cef_ref_counted.h @@ -55,7 +55,7 @@ #include "include/base/cef_thread_checker.h" namespace base { -namespace subtle { +namespace cef_subtle { class RefCountedBase { public: @@ -263,8 +263,6 @@ class RefCountedThreadSafeBase { DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafeBase); }; -} // namespace subtle - // ScopedAllowCrossThreadRefCountAccess disables the check documented on // RefCounted below for rare pre-existing use cases where thread-safety was // guaranteed through other means (e.g. explicit sequencing of calls across @@ -286,6 +284,11 @@ class ScopedAllowCrossThreadRefCountAccess final { #endif }; +} // namespace cef_subtle + +using ScopedAllowCrossThreadRefCountAccess = + cef_subtle::ScopedAllowCrossThreadRefCountAccess; + // // A base class for reference counted classes. Otherwise, known as a cheap // knock-off of WebKit's RefCounted class. To use this, just extend your @@ -332,9 +335,9 @@ class ScopedAllowCrossThreadRefCountAccess final { // And start-from-one ref count is a step to merge WTF::RefCounted into // base::RefCounted. // -#define REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE() \ - static constexpr ::base::subtle::StartRefCountFromOneTag \ - kRefCountPreference = ::base::subtle::kStartRefCountFromOneTag +#define REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE() \ + static constexpr ::base::cef_subtle::StartRefCountFromOneTag \ + kRefCountPreference = ::base::cef_subtle::kStartRefCountFromOneTag template class RefCounted; @@ -347,17 +350,17 @@ struct DefaultRefCountedTraits { }; template > -class RefCounted : public subtle::RefCountedBase { +class RefCounted : public cef_subtle::RefCountedBase { public: - static constexpr subtle::StartRefCountFromZeroTag kRefCountPreference = - subtle::kStartRefCountFromZeroTag; + static constexpr cef_subtle::StartRefCountFromZeroTag kRefCountPreference = + cef_subtle::kStartRefCountFromZeroTag; - RefCounted() : subtle::RefCountedBase(T::kRefCountPreference) {} + RefCounted() : cef_subtle::RefCountedBase(T::kRefCountPreference) {} - void AddRef() const { subtle::RefCountedBase::AddRef(); } + void AddRef() const { cef_subtle::RefCountedBase::AddRef(); } void Release() const { - if (subtle::RefCountedBase::Release()) { + if (cef_subtle::RefCountedBase::Release()) { // Prune the code paths which the static analyzer may take to simulate // object destruction. Use-after-free errors aren't possible given the // lifetime guarantees of the refcounting system. @@ -413,18 +416,18 @@ struct DefaultRefCountedThreadSafeTraits { // We can use REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE() with RefCountedThreadSafe // too. See the comment above the RefCounted definition for details. template > -class RefCountedThreadSafe : public subtle::RefCountedThreadSafeBase { +class RefCountedThreadSafe : public cef_subtle::RefCountedThreadSafeBase { public: - static constexpr subtle::StartRefCountFromZeroTag kRefCountPreference = - subtle::kStartRefCountFromZeroTag; + static constexpr cef_subtle::StartRefCountFromZeroTag kRefCountPreference = + cef_subtle::kStartRefCountFromZeroTag; explicit RefCountedThreadSafe() - : subtle::RefCountedThreadSafeBase(T::kRefCountPreference) {} + : cef_subtle::RefCountedThreadSafeBase(T::kRefCountPreference) {} void AddRef() const { AddRefImpl(T::kRefCountPreference); } void Release() const { - if (subtle::RefCountedThreadSafeBase::Release()) { + if (cef_subtle::RefCountedThreadSafeBase::Release()) { ANALYZER_SKIP_THIS_PATH(); Traits::Destruct(static_cast(this)); } @@ -440,12 +443,12 @@ class RefCountedThreadSafe : public subtle::RefCountedThreadSafeBase { delete x; } - void AddRefImpl(subtle::StartRefCountFromZeroTag) const { - subtle::RefCountedThreadSafeBase::AddRef(); + void AddRefImpl(cef_subtle::StartRefCountFromZeroTag) const { + cef_subtle::RefCountedThreadSafeBase::AddRef(); } - void AddRefImpl(subtle::StartRefCountFromOneTag) const { - subtle::RefCountedThreadSafeBase::AddRefWithCheck(); + void AddRefImpl(cef_subtle::StartRefCountFromOneTag) const { + cef_subtle::RefCountedThreadSafeBase::AddRefWithCheck(); } DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafe); diff --git a/include/base/cef_scoped_refptr.h b/include/base/cef_scoped_refptr.h index 8a093311f..4f88942f5 100644 --- a/include/base/cef_scoped_refptr.h +++ b/include/base/cef_scoped_refptr.h @@ -46,9 +46,9 @@ #include #include +#include "include/base/cef_compiler_specific.h" #include "include/base/cef_logging.h" #include "include/base/cef_macros.h" -#include "include/base/cef_compiler_specific.h" template class scoped_refptr; @@ -71,7 +71,7 @@ class BasePromise; } // namespace internal -namespace subtle { +namespace cef_subtle { enum AdoptRefTag { kAdoptRefTag }; enum StartRefCountFromZeroTag { kStartRefCountFromZeroTag }; @@ -96,7 +96,7 @@ constexpr bool IsRefCountPreferenceOverridden(...) { return false; } -} // namespace subtle +} // namespace cef_subtle // Creates a scoped_refptr from a raw pointer without incrementing the reference // count. Use this only for a newly created object whose reference count starts @@ -104,16 +104,16 @@ constexpr bool IsRefCountPreferenceOverridden(...) { template scoped_refptr AdoptRef(T* obj) { using Tag = std::decay_t; - static_assert(std::is_same::value, + static_assert(std::is_same::value, "Use AdoptRef only if the reference count starts from one."); DCHECK(obj); DCHECK(obj->HasOneRef()); obj->Adopted(); - return scoped_refptr(obj, subtle::kAdoptRefTag); + return scoped_refptr(obj, cef_subtle::kAdoptRefTag); } -namespace subtle { +namespace cef_subtle { template scoped_refptr AdoptRefIfNeeded(T* obj, StartRefCountFromZeroTag) { @@ -125,14 +125,14 @@ scoped_refptr AdoptRefIfNeeded(T* obj, StartRefCountFromOneTag) { return AdoptRef(obj); } -} // namespace subtle +} // namespace cef_subtle // Constructs an instance of T, which is a ref counted type, and wraps the // object into a scoped_refptr. template scoped_refptr MakeRefCounted(Args&&... args) { T* obj = new T(std::forward(args)...); - return subtle::AdoptRefIfNeeded(obj, T::kRefCountPreference); + return cef_subtle::AdoptRefIfNeeded(obj, T::kRefCountPreference); } // Takes an instance of T, which is a ref counted type, and wraps the object @@ -250,7 +250,7 @@ class TRIVIAL_ABI scoped_refptr { } ~scoped_refptr() { - static_assert(!base::subtle::IsRefCountPreferenceOverridden( + static_assert(!base::cef_subtle::IsRefCountPreferenceOverridden( static_cast(nullptr), static_cast(nullptr)), "It's unsafe to override the ref count preference." " Please remove REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE" @@ -324,7 +324,7 @@ class TRIVIAL_ABI scoped_refptr { friend class ::base::internal::BasePromise; friend class ::base::WrappedPromise; - scoped_refptr(T* p, base::subtle::AdoptRefTag) : ptr_(p) {} + scoped_refptr(T* p, base::cef_subtle::AdoptRefTag) : ptr_(p) {} // Friend required for move constructors that set r.ptr_ to null. template diff --git a/libcef_dll/base/cef_ref_counted.cc b/libcef_dll/base/cef_ref_counted.cc index 847473456..cb3ef8513 100644 --- a/libcef_dll/base/cef_ref_counted.cc +++ b/libcef_dll/base/cef_ref_counted.cc @@ -16,7 +16,7 @@ std::atomic_int g_cross_thread_ref_count_access_allow_count(0); } // namespace -namespace subtle { +namespace cef_subtle { bool RefCountedThreadSafeBase::HasOneRef() const { return ref_count_.IsOne(); @@ -84,8 +84,6 @@ bool RefCountedBase::CalledOnValidThread() const { } #endif -} // namespace subtle - #if DCHECK_IS_ON() ScopedAllowCrossThreadRefCountAccess::ScopedAllowCrossThreadRefCountAccess() { ++g_cross_thread_ref_count_access_allow_count; @@ -96,4 +94,5 @@ ScopedAllowCrossThreadRefCountAccess::~ScopedAllowCrossThreadRefCountAccess() { } #endif +} // namespace cef_subtle } // namespace base