Revert "Split off CPDF_ModuleMgr:Create() from CPDF_ModuleMgr::Get()"

This reverts commit acb6a240281b4bd9b27a39d7bab736ddebd540b9.

Reason for revert: Breaks Chromium component builds.

Original change's description:
> Split off CPDF_ModuleMgr:Create() from CPDF_ModuleMgr::Get()
> 
> Similarly, split off CFX_GEModule::Create() from CFX_GEModule::Get().
> We know the modules live for the lifetime of the pdfium library.
> 
> - Make some more members const.
> - Make CPDF_ModuleMgr create the GE module itself.
> - Need to initialize in tests.
> 
> Change-Id: I32395e16fccf5eac80cbd35edc3c15d7cb2ca0aa
> Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/54832
> Commit-Queue: Tom Sepez <tsepez@chromium.org>
> Reviewed-by: Lei Zhang <thestig@chromium.org>

TBR=thestig@chromium.org,tsepez@chromium.org

Change-Id: Ia8b88c2b327d1e539fc6fc2565f540ae1966f4c0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/54851
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/cpdf_modulemgr.cpp b/core/fpdfapi/cpdf_modulemgr.cpp
index 889e557..34fe049 100644
--- a/core/fpdfapi/cpdf_modulemgr.cpp
+++ b/core/fpdfapi/cpdf_modulemgr.cpp
@@ -37,32 +37,29 @@
 }  // namespace
 
 // static
-void CPDF_ModuleMgr::Create() {
-  ASSERT(!g_pDefaultMgr);
-  g_pDefaultMgr = new CPDF_ModuleMgr;
-  g_pDefaultMgr->InitCodecModule();
-  g_pDefaultMgr->InitPageModule();
-  g_pDefaultMgr->LoadEmbeddedMaps();
-  g_pDefaultMgr->LoadCodecModules();
+CPDF_ModuleMgr* CPDF_ModuleMgr::Get() {
+  if (!g_pDefaultMgr)
+    g_pDefaultMgr = new CPDF_ModuleMgr;
+  return g_pDefaultMgr;
 }
 
 // static
 void CPDF_ModuleMgr::Destroy() {
-  ASSERT(g_pDefaultMgr);
   delete g_pDefaultMgr;
   g_pDefaultMgr = nullptr;
 }
 
-// static
-CPDF_ModuleMgr* CPDF_ModuleMgr::Get() {
-  ASSERT(g_pDefaultMgr);
-  return g_pDefaultMgr;
+CPDF_ModuleMgr::CPDF_ModuleMgr() {}
+
+CPDF_ModuleMgr::~CPDF_ModuleMgr() {}
+
+void CPDF_ModuleMgr::Init() {
+  InitCodecModule();
+  InitPageModule();
+  LoadEmbeddedMaps();
+  LoadCodecModules();
 }
 
-CPDF_ModuleMgr::CPDF_ModuleMgr() = default;
-
-CPDF_ModuleMgr::~CPDF_ModuleMgr() = default;
-
 CCodec_FaxModule* CPDF_ModuleMgr::GetFaxModule() {
   return m_pCodecModule->GetFaxModule();
 }
diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h
index e916947..69b4833 100644
--- a/core/fpdfapi/cpdf_modulemgr.h
+++ b/core/fpdfapi/cpdf_modulemgr.h
@@ -35,11 +35,12 @@
 
 class CPDF_ModuleMgr {
  public:
-  static void Create();
-  static void Destroy();
   static CPDF_ModuleMgr* Get();
+  static void Destroy();
   static const int kFileBufSize = 512;
 
+  void Init();
+
   void SetUnsupportInfoAdapter(
       std::unique_ptr<fpdfapi::UnsupportedInfoAdapter> pAdapter) {
     m_pUnsupportInfoAdapter = std::move(pAdapter);
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 1ce21f4..975b3c9 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -25,8 +25,11 @@
 
 class CPDF_PageContentGeneratorTest : public testing::Test {
  protected:
-  void SetUp() override { CPDF_ModuleMgr::Create(); }
-  void TearDown() override { CPDF_ModuleMgr::Destroy(); }
+  void SetUp() override { CPDF_ModuleMgr::Get()->Init(); }
+
+  void TearDown() override {
+    CPDF_ModuleMgr::Destroy();
+  }
 
   void TestProcessPath(CPDF_PageContentGenerator* pGen,
                        std::ostringstream* buf,
diff --git a/core/fpdfapi/font/cpdf_cidfont_unittest.cpp b/core/fpdfapi/font/cpdf_cidfont_unittest.cpp
index fe10bc9..4166a93 100644
--- a/core/fpdfapi/font/cpdf_cidfont_unittest.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont_unittest.cpp
@@ -15,7 +15,8 @@
 
 class CPDF_CIDFontTest : public testing::Test {
  protected:
-  void SetUp() override { CPDF_ModuleMgr::Create(); }
+  void SetUp() override { CPDF_ModuleMgr::Get()->Init(); }
+
   void TearDown() override { CPDF_ModuleMgr::Destroy(); }
 };
 
diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp
index 682ac95..5078bf4 100644
--- a/core/fpdfapi/parser/cpdf_document_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp
@@ -151,7 +151,7 @@
 
 class cpdf_document_test : public testing::Test {
  public:
-  void SetUp() override { CPDF_ModuleMgr::Create(); }
+  void SetUp() override { CPDF_ModuleMgr::Get()->Init(); }
   void TearDown() override { CPDF_ModuleMgr::Destroy(); }
 };
 
diff --git a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
index fda209f..85db7d3 100644
--- a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
@@ -63,7 +63,7 @@
  public:
   CPDF_HintTablesTest() {
     // Needs for encoding Hint table stream.
-    CPDF_ModuleMgr::Create();
+    CPDF_ModuleMgr::Get()->Init();
   }
 
   ~CPDF_HintTablesTest() override { CPDF_ModuleMgr::Destroy(); }
diff --git a/core/fxge/cfx_gemodule.cpp b/core/fxge/cfx_gemodule.cpp
index ea6b4ac..b9b232d 100644
--- a/core/fxge/cfx_gemodule.cpp
+++ b/core/fxge/cfx_gemodule.cpp
@@ -17,19 +17,17 @@
 
 }  // namespace
 
-CFX_GEModule::CFX_GEModule(const char** pUserFontPaths)
-    : m_pFontCache(pdfium::MakeUnique<CFX_FontCache>()),
-      m_pFontMgr(pdfium::MakeUnique<CFX_FontMgr>()),
-      m_pPlatform(PlatformIface::Create()),
-      m_pUserFontPaths(pUserFontPaths) {}
+CFX_GEModule::CFX_GEModule()
+    : m_pFontMgr(pdfium::MakeUnique<CFX_FontMgr>()),
+      m_pPlatform(PlatformIface::Create()) {}
 
 CFX_GEModule::~CFX_GEModule() = default;
 
 // static
-void CFX_GEModule::Create(const char** pUserFontPaths) {
-  ASSERT(!g_pGEModule);
-  g_pGEModule = new CFX_GEModule(pUserFontPaths);
-  g_pGEModule->m_pPlatform->Init();
+CFX_GEModule* CFX_GEModule::Get() {
+  if (!g_pGEModule)
+    g_pGEModule = new CFX_GEModule();
+  return g_pGEModule;
 }
 
 // static
@@ -39,8 +37,14 @@
   g_pGEModule = nullptr;
 }
 
-// static
-CFX_GEModule* CFX_GEModule::Get() {
+void CFX_GEModule::Init(const char** userFontPaths) {
   ASSERT(g_pGEModule);
-  return g_pGEModule;
+  m_pUserFontPaths = userFontPaths;
+  m_pPlatform->Init();
+}
+
+CFX_FontCache* CFX_GEModule::GetFontCache() {
+  if (!m_pFontCache)
+    m_pFontCache = pdfium::MakeUnique<CFX_FontCache>();
+  return m_pFontCache.get();
 }
diff --git a/core/fxge/cfx_gemodule.h b/core/fxge/cfx_gemodule.h
index 59eddb7..afcbff4 100644
--- a/core/fxge/cfx_gemodule.h
+++ b/core/fxge/cfx_gemodule.h
@@ -22,23 +22,23 @@
     virtual void Init() = 0;
   };
 
-  static void Create(const char** pUserFontPaths);
-  static void Destroy();
   static CFX_GEModule* Get();
+  static void Destroy();
 
-  CFX_FontCache* GetFontCache() const { return m_pFontCache.get(); }
+  void Init(const char** pUserFontPaths);
+  CFX_FontCache* GetFontCache();
   CFX_FontMgr* GetFontMgr() const { return m_pFontMgr.get(); }
   PlatformIface* GetPlatform() const { return m_pPlatform.get(); }
   const char** GetUserFontPaths() const { return m_pUserFontPaths; }
 
  private:
-  explicit CFX_GEModule(const char** pUserFontPaths);
+  CFX_GEModule();
   ~CFX_GEModule();
 
-  std::unique_ptr<CFX_FontCache> const m_pFontCache;
-  std::unique_ptr<CFX_FontMgr> const m_pFontMgr;
-  std::unique_ptr<PlatformIface> const m_pPlatform;
-  const char** const m_pUserFontPaths;
+  std::unique_ptr<CFX_FontCache> m_pFontCache;
+  std::unique_ptr<CFX_FontMgr> m_pFontMgr;
+  std::unique_ptr<PlatformIface> m_pPlatform;
+  const char** m_pUserFontPaths = nullptr;
 };
 
 #endif  // CORE_FXGE_CFX_GEMODULE_H_
diff --git a/fpdfsdk/fpdf_catalog_unittest.cpp b/fpdfsdk/fpdf_catalog_unittest.cpp
index ff3adcf..180fb79 100644
--- a/fpdfsdk/fpdf_catalog_unittest.cpp
+++ b/fpdfsdk/fpdf_catalog_unittest.cpp
@@ -27,7 +27,7 @@
 class PDFCatalogTest : public testing::Test {
  public:
   void SetUp() override {
-    CPDF_ModuleMgr::Create();
+    CPDF_ModuleMgr::Get()->Init();
     auto pTestDoc = pdfium::MakeUnique<CPDF_TestDocument>();
     m_pDoc.reset(FPDFDocumentFromCPDFDocument(pTestDoc.release()));
     m_pRootObj = pdfium::MakeRetain<CPDF_Dictionary>();
diff --git a/fpdfsdk/fpdf_doc_unittest.cpp b/fpdfsdk/fpdf_doc_unittest.cpp
index 08517d7..b0337e8 100644
--- a/fpdfsdk/fpdf_doc_unittest.cpp
+++ b/fpdfsdk/fpdf_doc_unittest.cpp
@@ -40,7 +40,7 @@
   };
 
   void SetUp() override {
-    CPDF_ModuleMgr::Create();
+    CPDF_ModuleMgr::Get()->Init();
     auto pTestDoc = pdfium::MakeUnique<CPDF_TestDocument>();
     m_pIndirectObjs = pTestDoc->GetHolder();
     m_pRootObj.Reset(m_pIndirectObjs->NewIndirect<CPDF_Dictionary>());
diff --git a/fpdfsdk/fpdf_edit_unittest.cpp b/fpdfsdk/fpdf_edit_unittest.cpp
index 1fcd93d..499a655 100644
--- a/fpdfsdk/fpdf_edit_unittest.cpp
+++ b/fpdfsdk/fpdf_edit_unittest.cpp
@@ -8,7 +8,8 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 class PDFEditTest : public testing::Test {
-  void SetUp() override { CPDF_ModuleMgr::Create(); }
+  void SetUp() override { CPDF_ModuleMgr::Get()->Init(); }
+
   void TearDown() override { CPDF_ModuleMgr::Destroy(); }
 };
 
diff --git a/fpdfsdk/fpdf_editimg_unittest.cpp b/fpdfsdk/fpdf_editimg_unittest.cpp
index 81a4877..fa04758 100644
--- a/fpdfsdk/fpdf_editimg_unittest.cpp
+++ b/fpdfsdk/fpdf_editimg_unittest.cpp
@@ -9,7 +9,8 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 class PDFEditImgTest : public testing::Test {
-  void SetUp() override { CPDF_ModuleMgr::Create(); }
+  void SetUp() override { CPDF_ModuleMgr::Get()->Init(); }
+
   void TearDown() override { CPDF_ModuleMgr::Destroy(); }
 };
 
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 3712697..f9bc6c0 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -158,8 +158,12 @@
     return;
 
   FXMEM_InitializePartitionAlloc();
-  CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr);
-  CPDF_ModuleMgr::Create();
+
+  CFX_GEModule* pModule = CFX_GEModule::Get();
+  pModule->Init(cfg ? cfg->m_pUserFontPaths : nullptr);
+
+  CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get();
+  pModuleMgr->Init();
 
 #ifdef PDF_ENABLE_XFA
   BC_Library_Init();
@@ -180,6 +184,7 @@
 
   CPDF_ModuleMgr::Destroy();
   CFX_GEModule::Destroy();
+
   IJS_Runtime::Destroy();
 
   g_bLibraryInitialized = false;
diff --git a/testing/BUILD.gn b/testing/BUILD.gn
index 9eee51c..d2a0411 100644
--- a/testing/BUILD.gn
+++ b/testing/BUILD.gn
@@ -17,7 +17,6 @@
     "string_write_stream.h",
     "test_loader.cpp",
     "test_loader.h",
-    "test_support.cpp",
     "test_support.h",
     "utils/bitmap_saver.cpp",
     "utils/bitmap_saver.h",
@@ -35,7 +34,6 @@
     "../:pdfium_public_headers",
     "../core/fdrm",
     "../core/fxcrt",
-    "../core/fxge",
     "image_diff",
   ]
   configs += [ "../:pdfium_core_config" ]
diff --git a/testing/test_support.cpp b/testing/test_support.cpp
deleted file mode 100644
index 94ce528..0000000
--- a/testing/test_support.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2019 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "testing/test_support.h"
-
-#include "core/fxge/cfx_gemodule.h"
-
-void InitializePDFTestEnvironment() {
-  CFX_GEModule::Create(nullptr);
-}
-
-void DestroyPDFTestEnvironment() {
-  CFX_GEModule::Destroy();
-}
diff --git a/testing/test_support.h b/testing/test_support.h
index f237ea5..f257787 100644
--- a/testing/test_support.h
+++ b/testing/test_support.h
@@ -5,8 +5,6 @@
 #ifndef TESTING_TEST_SUPPORT_H_
 #define TESTING_TEST_SUPPORT_H_
 
-#include <stdint.h>
-
 namespace pdfium {
 
 #define STR_IN_TEST_CASE(input_literal, ...)               \
@@ -46,7 +44,4 @@
 
 }  // namespace pdfium
 
-void InitializePDFTestEnvironment();
-void DestroyPDFTestEnvironment();
-
 #endif  // TESTING_TEST_SUPPORT_H_
diff --git a/testing/unit_test_main.cpp b/testing/unit_test_main.cpp
index 35c4939..44918fc 100644
--- a/testing/unit_test_main.cpp
+++ b/testing/unit_test_main.cpp
@@ -8,7 +8,6 @@
 #include "core/fxcrt/fx_memory.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
-#include "testing/test_support.h"
 
 #ifdef PDF_ENABLE_V8
 #include "testing/v8_initializer.h"
@@ -37,7 +36,6 @@
 #endif  // V8_USE_EXTERNAL_STARTUP_DATA
 #endif  // PDF_ENABLE_V8
 
-  InitializePDFTestEnvironment();
 #ifdef PDF_ENABLE_XFA
   InitializeXFATestEnvironment();
 #endif  // PDF_ENABLE_XFA
@@ -47,9 +45,6 @@
 
   int ret_val = RUN_ALL_TESTS();
 
-  DestroyPDFTestEnvironment();
-  // NOTE: XFA test environment, if present, destroyed by gtest.
-
 #ifdef PDF_ENABLE_V8
   v8::V8::ShutdownPlatform();
 #endif  // PDF_ENABLE_V8
diff --git a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
index f9bd450..e06e04c 100644
--- a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
+++ b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
@@ -21,10 +21,10 @@
  public:
   CFGAS_StringFormatterTest() {
     SetTZ("UTC");
-    CPDF_ModuleMgr::Create();
+    CPDF_ModuleMgr::Get()->Init();
   }
 
-  ~CFGAS_StringFormatterTest() override { CPDF_ModuleMgr::Destroy(); }
+  ~CFGAS_StringFormatterTest() override { CPDF_ModuleMgr::Get()->Destroy(); }
 
   void TearDown() override {
     fmt_.reset();