Make Retaintable subclass's ctors/dtor non-public
These ref-counted subclasses should be constructed via MakeRetain(), and
not directly deleted.
Change-Id: I8ee4192efcc9f8151e24d0c0b724b6709ca9fef3
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/107491
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h
index a74cba9..e192a5c 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -68,8 +68,6 @@
static RetainPtr<CPDF_Font> GetStockFont(CPDF_Document* pDoc,
ByteStringView fontname);
- ~CPDF_Font() override;
-
virtual bool IsType1Font() const;
virtual bool IsTrueTypeFont() const;
virtual bool IsType3Font() const;
@@ -138,6 +136,7 @@
protected:
CPDF_Font(CPDF_Document* pDocument, RetainPtr<CPDF_Dictionary> pFontDict);
+ ~CPDF_Font() override;
static int TT2PDF(FT_Pos m, FXFT_FaceRec* face);
diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.h b/core/fpdfapi/page/cpdf_contentmarkitem.h
index f418aab..e3a041d 100644
--- a/core/fpdfapi/page/cpdf_contentmarkitem.h
+++ b/core/fpdfapi/page/cpdf_contentmarkitem.h
@@ -16,8 +16,7 @@
public:
enum ParamType { kNone, kPropertiesDict, kDirectDict };
- explicit CPDF_ContentMarkItem(ByteString name);
- ~CPDF_ContentMarkItem() override;
+ CONSTRUCT_VIA_MAKE_RETAIN;
const ByteString& GetName() const { return m_MarkName; }
ParamType GetParamType() const { return m_ParamType; }
@@ -30,6 +29,9 @@
const ByteString& property_name);
private:
+ explicit CPDF_ContentMarkItem(ByteString name);
+ ~CPDF_ContentMarkItem() override;
+
ParamType m_ParamType = kNone;
ByteString m_MarkName;
ByteString m_PropertyName;
diff --git a/core/fpdfapi/page/cpdf_contentmarks.h b/core/fpdfapi/page/cpdf_contentmarks.h
index 95eaeea..ef3ebd6 100644
--- a/core/fpdfapi/page/cpdf_contentmarks.h
+++ b/core/fpdfapi/page/cpdf_contentmarks.h
@@ -42,9 +42,7 @@
private:
class MarkData final : public Retainable {
public:
- MarkData();
- MarkData(const MarkData& src);
- ~MarkData() override;
+ CONSTRUCT_VIA_MAKE_RETAIN;
size_t CountItems() const;
bool ContainsItem(const CPDF_ContentMarkItem* pItem) const;
@@ -61,6 +59,10 @@
bool RemoveMark(CPDF_ContentMarkItem* pMarkItem);
private:
+ MarkData();
+ MarkData(const MarkData& src);
+ ~MarkData() override;
+
std::vector<RetainPtr<CPDF_ContentMarkItem>> m_Marks;
};
diff --git a/core/fpdfapi/page/cpdf_pattern.h b/core/fpdfapi/page/cpdf_pattern.h
index cd535b1..b773817 100644
--- a/core/fpdfapi/page/cpdf_pattern.h
+++ b/core/fpdfapi/page/cpdf_pattern.h
@@ -22,8 +22,6 @@
// Values used in PDFs. Do not change.
enum PatternType { kTiling = 1, kShading = 2 };
- ~CPDF_Pattern() override;
-
virtual CPDF_TilingPattern* AsTilingPattern();
virtual CPDF_ShadingPattern* AsShadingPattern();
@@ -33,6 +31,7 @@
CPDF_Pattern(CPDF_Document* pDoc,
RetainPtr<CPDF_Object> pObj,
const CFX_Matrix& parentMatrix);
+ ~CPDF_Pattern() override;
// All the getters that return pointers return non-NULL pointers.
CPDF_Document* document() const { return m_pDocument; }
diff --git a/core/fxcrt/shared_copy_on_write_unittest.cpp b/core/fxcrt/shared_copy_on_write_unittest.cpp
index 979058b..2e8c9e8 100644
--- a/core/fxcrt/shared_copy_on_write_unittest.cpp
+++ b/core/fxcrt/shared_copy_on_write_unittest.cpp
@@ -31,6 +31,11 @@
class Object final : public Retainable {
public:
+ CONSTRUCT_VIA_MAKE_RETAIN;
+
+ RetainPtr<Object> Clone() const { return pdfium::MakeRetain<Object>(*this); }
+
+ private:
Object(Observer* observer, const std::string& name)
: name_(name), observer_(observer) {
observer->OnConstruct(name_);
@@ -40,9 +45,6 @@
}
~Object() override { observer_->OnDestruct(name_); }
- RetainPtr<Object> Clone() const { return pdfium::MakeRetain<Object>(*this); }
-
- private:
std::string name_;
Observer* observer_;
};
diff --git a/core/fxge/cfx_fontmgr.h b/core/fxge/cfx_fontmgr.h
index 31539aa..7850166 100644
--- a/core/fxge/cfx_fontmgr.h
+++ b/core/fxge/cfx_fontmgr.h
@@ -29,7 +29,6 @@
class FontDesc final : public Retainable, public Observable {
public:
CONSTRUCT_VIA_MAKE_RETAIN;
- ~FontDesc() override;
pdfium::span<const uint8_t> FontData() const { return m_pFontData; }
void SetFace(size_t index, CFX_Face* face);
@@ -37,6 +36,7 @@
private:
explicit FontDesc(FixedUninitDataVector<uint8_t> data);
+ ~FontDesc() override;
const FixedUninitDataVector<uint8_t> m_pFontData;
ObservedPtr<CFX_Face> m_TTCFaces[16];
diff --git a/core/fxge/cfx_glyphcache.h b/core/fxge/cfx_glyphcache.h
index ff2e740..0871992 100644
--- a/core/fxge/cfx_glyphcache.h
+++ b/core/fxge/cfx_glyphcache.h
@@ -30,7 +30,6 @@
class CFX_GlyphCache final : public Retainable, public Observable {
public:
CONSTRUCT_VIA_MAKE_RETAIN;
- ~CFX_GlyphCache() override;
const CFX_GlyphBitmap* LoadGlyphBitmap(const CFX_Font* pFont,
uint32_t glyph_index,
@@ -56,6 +55,7 @@
private:
explicit CFX_GlyphCache(RetainPtr<CFX_Face> face);
+ ~CFX_GlyphCache() override;
using SizeGlyphCache = std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>>;
// <glyph_index, width, weight, angle, vertical>
diff --git a/core/fxge/dib/cfx_dibbase.h b/core/fxge/dib/cfx_dibbase.h
index 9f0deeb..1e507e6 100644
--- a/core/fxge/dib/cfx_dibbase.h
+++ b/core/fxge/dib/cfx_dibbase.h
@@ -32,8 +32,6 @@
static constexpr uint32_t kPaletteSize = 256;
- ~CFX_DIBBase() override;
-
virtual pdfium::span<uint8_t> GetBuffer() const;
virtual pdfium::span<const uint8_t> GetScanline(int line) const = 0;
virtual bool SkipToScanline(int line, PauseIndicatorIface* pPause) const;
@@ -89,6 +87,7 @@
protected:
CFX_DIBBase();
+ ~CFX_DIBBase() override;
static bool ConvertBuffer(FXDIB_Format dest_format,
pdfium::span<uint8_t> dest_buf,