diff options
author | tsepez <tsepez@chromium.org> | 2016-12-07 13:45:41 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-07 13:45:41 -0800 |
commit | cd5e12a9ea397b48056643a7b65126395eec3174 (patch) | |
tree | d1b6b0c0e1b8f8d996aa987e6386338bca5ba92b /core/fxcrt/cfx_retain_ptr.h | |
parent | 7cda31ac2f2884166f044937619478a6103198cf (diff) | |
download | pdfium-cd5e12a9ea397b48056643a7b65126395eec3174.tar.xz |
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
Diffstat (limited to 'core/fxcrt/cfx_retain_ptr.h')
-rw-r--r-- | core/fxcrt/cfx_retain_ptr.h | 17 |
1 files changed, 14 insertions, 3 deletions
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 <typename U> + friend struct ReleaseDeleter; + + template <typename U> + 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 <typename T, typename... Args> CFX_RetainPtr<T> MakeRetain(Args&&... args) { return CFX_RetainPtr<T>(new T(std::forward<Args>(args)...)); |