Change CFPF_SkiaFontMgr::m_FontFaces to store unique_ptrs.

Instead of raw pointers.

Change-Id: Ie46af37bbe3fe287bdff25249afaeb90589c85b3
Reviewed-on: https://pdfium-review.googlesource.com/40552
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/android/cfpf_skiafont.cpp b/core/fxge/android/cfpf_skiafont.cpp
index 24984e8..0118f95 100644
--- a/core/fxge/android/cfpf_skiafont.cpp
+++ b/core/fxge/android/cfpf_skiafont.cpp
@@ -171,7 +171,7 @@
 }
 
 bool CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr* pFontMgr,
-                             CFPF_SkiaPathFont* pFont,
+                             const CFPF_SkiaPathFont* pFont,
                              const ByteStringView& bsFamily,
                              uint32_t dwStyle,
                              uint8_t uCharset) {
diff --git a/core/fxge/android/cfpf_skiafont.h b/core/fxge/android/cfpf_skiafont.h
index 260e422..d80378e 100644
--- a/core/fxge/android/cfpf_skiafont.h
+++ b/core/fxge/android/cfpf_skiafont.h
@@ -37,14 +37,14 @@
   uint32_t GetFontData(uint32_t dwTable, uint8_t* pBuffer, uint32_t dwSize);
 
   bool InitFont(CFPF_SkiaFontMgr* pFontMgr,
-                CFPF_SkiaPathFont* pFont,
+                const CFPF_SkiaPathFont* pFont,
                 const ByteStringView& bsFamily,
                 uint32_t dwStyle,
                 uint8_t uCharset);
 
  private:
   UnownedPtr<CFPF_SkiaFontMgr> m_pFontMgr;
-  UnownedPtr<CFPF_SkiaPathFont> m_pFont;
+  UnownedPtr<const CFPF_SkiaPathFont> m_pFont;
   FXFT_Face m_Face = nullptr;
   uint32_t m_dwStyle = 0;
   uint8_t m_uCharset = 0;
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index b091ae9..6edc334 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -21,6 +21,7 @@
 #include "core/fxge/android/cfpf_skiafont.h"
 #include "core/fxge/android/cfpf_skiapathfont.h"
 #include "core/fxge/fx_freetype.h"
+#include "third_party/base/ptr_util.h"
 
 namespace {
 
@@ -232,8 +233,6 @@
       pair.second->Release();
   }
   m_FamilyFonts.clear();
-  for (auto it = m_FontFaces.begin(); it != m_FontFaces.end(); ++it)
-    delete *it;
   m_FontFaces.clear();
   if (m_FTLibrary)
     FXFT_Done_FreeType(m_FTLibrary);
@@ -276,11 +275,11 @@
   }
   int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 +
                        FPF_SKIAMATCHWEIGHT_2 * 2;
-  CFPF_SkiaPathFont* pBestFont = nullptr;
+  const CFPF_SkiaPathFont* pBestFont = nullptr;
   int32_t nMax = -1;
   int32_t nGlyphNum = 0;
   for (auto it = m_FontFaces.rbegin(); it != m_FontFaces.rend(); ++it) {
-    CFPF_SkiaPathFont* pFont = *it;
+    const CFPF_SkiaPathFont* pFont = it->get();
     if (!(pFont->m_dwCharsets & FPF_SkiaGetCharset(uCharset)))
       continue;
     int32_t nFind = 0;
@@ -307,19 +306,19 @@
     if (uCharset == FX_CHARSET_Default || bMaybeSymbol) {
       if (nFind > nMax && bMatchedName) {
         nMax = nFind;
-        pBestFont = *it;
+        pBestFont = it->get();
       }
     } else if (FPF_SkiaIsCJK(uCharset)) {
       if (bMatchedName || pFont->m_iGlyphNum > nGlyphNum) {
-        pBestFont = *it;
+        pBestFont = it->get();
         nGlyphNum = pFont->m_iGlyphNum;
       }
     } else if (nFind > nMax) {
       nMax = nFind;
-      pBestFont = *it;
+      pBestFont = it->get();
     }
     if (nExpectVal <= nFind) {
-      pBestFont = *it;
+      pBestFont = it->get();
       break;
     }
   }
@@ -381,16 +380,16 @@
   FXFT_Face face = GetFontFace(file.AsStringView(), 0);
   if (!face)
     return;
-  CFPF_SkiaPathFont* pFont = new CFPF_SkiaPathFont;
-  pFont->SetPath(file.c_str());
-  ReportFace(face, pFont);
-  m_FontFaces.push_back(pFont);
+
+  m_FontFaces.push_back(ReportFace(face, file));
   FXFT_Done_Face(face);
 }
 
-void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, CFPF_SkiaPathFont* pFont) {
-  if (!face || !pFont)
-    return;
+std::unique_ptr<CFPF_SkiaPathFont> CFPF_SkiaFontMgr::ReportFace(
+    FXFT_Face face,
+    const ByteString& file) {
+  auto pFont = pdfium::MakeUnique<CFPF_SkiaPathFont>();
+  pFont->SetPath(file.c_str());
   pFont->SetFamily(FXFT_Get_Face_Family_Name(face));
   if (FXFT_Is_Face_Bold(face))
     pFont->m_dwStyle |= FXFONT_BOLD;
@@ -413,4 +412,5 @@
   pFont->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2);
   pFont->m_iFaceIndex = face->face_index;
   pFont->m_iGlyphNum = face->num_glyphs;
+  return pFont;
 }
diff --git a/core/fxge/android/cfpf_skiafontmgr.h b/core/fxge/android/cfpf_skiafontmgr.h
index af2d3ac..99aafd7 100644
--- a/core/fxge/android/cfpf_skiafontmgr.h
+++ b/core/fxge/android/cfpf_skiafontmgr.h
@@ -8,6 +8,7 @@
 #define CORE_FXGE_ANDROID_CFPF_SKIAFONTMGR_H_
 
 #include <map>
+#include <memory>
 #include <vector>
 
 #include "core/fxcrt/fx_string.h"
@@ -35,11 +36,12 @@
  private:
   void ScanPath(const ByteString& path);
   void ScanFile(const ByteString& file);
-  void ReportFace(FXFT_Face face, CFPF_SkiaPathFont* pFont);
+  std::unique_ptr<CFPF_SkiaPathFont> ReportFace(FXFT_Face face,
+                                                const ByteString& file);
 
   bool m_bLoaded = false;
   FXFT_Library m_FTLibrary = nullptr;
-  std::vector<CFPF_SkiaPathFont*> m_FontFaces;
+  std::vector<std::unique_ptr<CFPF_SkiaPathFont>> m_FontFaces;
   std::map<uint32_t, CFPF_SkiaFont*> m_FamilyFonts;
 };