diff options
author | leviw <leviw@chromium.org> | 2016-03-25 18:19:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-26 01:21:11 +0000 |
commit | 03d23a6e89f3f1ff65575ad088858e2b219daa3c (patch) | |
tree | c575768fa546db9aa0db6df8bc9598661197dd31 | |
parent | ddcb01e6116caefe5b89c589455df887ba18b1cd (diff) | |
download | chromium_src-03d23a6e89f3f1ff65575ad088858e2b219daa3c.zip chromium_src-03d23a6e89f3f1ff65575ad088858e2b219daa3c.tar.gz chromium_src-03d23a6e89f3f1ff65575ad088858e2b219daa3c.tar.bz2 |
Add const support to wtf/RefCounted
This gets us to parity with base/ref_counted
Review URL: https://codereview.chromium.org/1836693002
Cr-Commit-Position: refs/heads/master@{#383434}
-rw-r--r-- | third_party/WebKit/Source/wtf/RefCounted.h | 16 | ||||
-rw-r--r-- | third_party/WebKit/Source/wtf/RefPtrTest.cpp | 12 |
2 files changed, 20 insertions, 8 deletions
diff --git a/third_party/WebKit/Source/wtf/RefCounted.h b/third_party/WebKit/Source/wtf/RefCounted.h index 299fb37..db9d082 100644 --- a/third_party/WebKit/Source/wtf/RefCounted.h +++ b/third_party/WebKit/Source/wtf/RefCounted.h @@ -41,7 +41,7 @@ namespace WTF { // generated by the compiler (technique called template hoisting). class WTF_EXPORT RefCountedBase { public: - void ref() + void ref() const { #if CHECK_REF_COUNTED_LIFECYCLE m_verifier.onRef(m_refCount); @@ -89,7 +89,7 @@ protected: } // Returns whether the pointer should be freed or not. - bool derefBase() + bool derefBase() const { ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); #if CHECK_REF_COUNTED_LIFECYCLE @@ -122,13 +122,13 @@ private: friend void adopted(RefCountedBase*); #endif - int m_refCount; + mutable int m_refCount; #if ENABLE(SECURITY_ASSERT) - bool m_deletionHasBegun; + mutable bool m_deletionHasBegun; #endif #if CHECK_REF_COUNTED_LIFECYCLE - bool m_adoptionIsRequired; - ThreadRestrictionVerifier m_verifier; + mutable bool m_adoptionIsRequired; + mutable ThreadRestrictionVerifier m_verifier; #endif }; @@ -153,10 +153,10 @@ template<typename T> class RefCounted : public RefCountedBase { USING_FAST_MALLOC(T); public: - void deref() + void deref() const { if (derefBase()) - delete static_cast<T*>(this); + delete static_cast<const T*>(this); } protected: diff --git a/third_party/WebKit/Source/wtf/RefPtrTest.cpp b/third_party/WebKit/Source/wtf/RefPtrTest.cpp index 7f37fc3..a21b4f7 100644 --- a/third_party/WebKit/Source/wtf/RefPtrTest.cpp +++ b/third_party/WebKit/Source/wtf/RefPtrTest.cpp @@ -5,6 +5,7 @@ #include "wtf/RefPtr.h" #include "testing/gtest/include/gtest/gtest.h" +#include "wtf/RefCounted.h" #include "wtf/text/StringImpl.h" namespace WTF { @@ -28,4 +29,15 @@ TEST(RefPtrTest, MoveAssignmentOperator) EXPECT_TRUE(!a); } +class RefCountedClass : public RefCounted<RefCountedClass> { +}; + +TEST(RefPtrTest, ConstObject) +{ + // This test is only to ensure we force the compilation of a const RefCounted + // object to ensure the generated code compiles. + RefPtr<const RefCountedClass> ptrToConst = adoptRef(new RefCountedClass()); +} + + } // namespace WTF |