Rename 'subtle' namespace to fix duplicate symbol errors (see issue #3140)

This commit is contained in:
Marshall Greenblatt 2021-06-18 12:01:55 -04:00
parent 17fc2b3e3b
commit 6a1c641f75
3 changed files with 36 additions and 34 deletions

View File

@ -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<T> 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 T, typename Traits>
class RefCounted;
@ -347,17 +350,17 @@ struct DefaultRefCountedTraits {
};
template <class T, typename Traits = DefaultRefCountedTraits<T>>
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 T, typename Traits = DefaultRefCountedThreadSafeTraits<T>>
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<const T*>(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);

View File

@ -46,9 +46,9 @@
#include <type_traits>
#include <utility>
#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 T>
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 <typename T>
scoped_refptr<T> AdoptRef(T* obj) {
using Tag = std::decay_t<decltype(T::kRefCountPreference)>;
static_assert(std::is_same<subtle::StartRefCountFromOneTag, Tag>::value,
static_assert(std::is_same<cef_subtle::StartRefCountFromOneTag, Tag>::value,
"Use AdoptRef only if the reference count starts from one.");
DCHECK(obj);
DCHECK(obj->HasOneRef());
obj->Adopted();
return scoped_refptr<T>(obj, subtle::kAdoptRefTag);
return scoped_refptr<T>(obj, cef_subtle::kAdoptRefTag);
}
namespace subtle {
namespace cef_subtle {
template <typename T>
scoped_refptr<T> AdoptRefIfNeeded(T* obj, StartRefCountFromZeroTag) {
@ -125,14 +125,14 @@ scoped_refptr<T> 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<T>.
template <typename T, typename... Args>
scoped_refptr<T> MakeRefCounted(Args&&... args) {
T* obj = new T(std::forward<Args>(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<T*>(nullptr), static_cast<T*>(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 <typename U>

View File

@ -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