From cd5e12a9ea397b48056643a7b65126395eec3174 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 7 Dec 2016 13:45:41 -0800 Subject: Catch stray Retains() and Releases() outside of RetainPtr<>. The previous CLs made the code clean, so now we can mark more things private, and add friends as appropriate. Review-Url: https://codereview.chromium.org/2560783003 --- core/fxcrt/cfx_retain_ptr.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'core/fxcrt/cfx_retain_ptr.h') diff --git a/core/fxcrt/cfx_retain_ptr.h b/core/fxcrt/cfx_retain_ptr.h index 8c7bf289a7..bff1b9691c 100644 --- a/core/fxcrt/cfx_retain_ptr.h +++ b/core/fxcrt/cfx_retain_ptr.h @@ -60,15 +60,24 @@ class CFX_RetainPtr { // Trivial implementation - internal ref count with virtual destructor. class CFX_Retainable { public: + bool HasOneRef() const { return m_nRefCount == 1; } + + protected: + virtual ~CFX_Retainable() {} + + private: + template + friend struct ReleaseDeleter; + + template + friend class CFX_RetainPtr; + void Retain() { ++m_nRefCount; } void Release() { if (--m_nRefCount == 0) delete this; } - bool HasOneRef() const { return m_nRefCount == 1; } - protected: - virtual ~CFX_Retainable() {} intptr_t m_nRefCount = 0; }; @@ -76,6 +85,8 @@ namespace pdfium { // Helper to make a CFX_RetainPtr along the lines of std::make_unique<>(), // or pdfium::MakeUnique<>(). Arguments are forwarded to T's constructor. +// Classes managed by CFX_RetainPtr should have protected (or private) +// constructors, and should friend this function. template CFX_RetainPtr MakeRetain(Args&&... args) { return CFX_RetainPtr(new T(std::forward(args)...)); -- cgit v1.2.3