diff options
author | weili <weili@chromium.org> | 2016-07-20 10:35:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-20 10:35:31 -0700 |
commit | 47228aceb86744f858ab8bfa98f3f8b62054dfae (patch) | |
tree | d5d8abbc5eaeb23b291cf604bf33c77cf648b0bb /core | |
parent | 31f8740fe51ceca8e973a2efe40d4d440d7a5cb7 (diff) | |
download | pdfium-47228aceb86744f858ab8bfa98f3f8b62054dfae.tar.xz |
Clean up singleton implementation
Move the singleton instances into their namespaces, and use
get()/getInstance() for uniform accesses.
Review-Url: https://codereview.chromium.org/2154843002
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/cpdf_modulemgr.cpp | 16 | ||||
-rw-r--r-- | core/fxge/ge/fx_ge.cpp | 34 | ||||
-rw-r--r-- | core/fxge/include/fx_ge.h | 7 |
3 files changed, 28 insertions, 29 deletions
diff --git a/core/fpdfapi/cpdf_modulemgr.cpp b/core/fpdfapi/cpdf_modulemgr.cpp index fe5368d3f7..454ffcd465 100644 --- a/core/fpdfapi/cpdf_modulemgr.cpp +++ b/core/fpdfapi/cpdf_modulemgr.cpp @@ -11,25 +11,21 @@ namespace { -CPDF_ModuleMgr* g_FPDFAPI_pDefaultMgr = nullptr; +CPDF_ModuleMgr* g_pDefaultMgr = nullptr; } // namespace // static CPDF_ModuleMgr* CPDF_ModuleMgr::Get() { - return g_FPDFAPI_pDefaultMgr; -} - -// static -void CPDF_ModuleMgr::Create() { - ASSERT(!g_FPDFAPI_pDefaultMgr); - g_FPDFAPI_pDefaultMgr = new CPDF_ModuleMgr; + if (!g_pDefaultMgr) + g_pDefaultMgr = new CPDF_ModuleMgr; + return g_pDefaultMgr; } // static void CPDF_ModuleMgr::Destroy() { - delete g_FPDFAPI_pDefaultMgr; - g_FPDFAPI_pDefaultMgr = nullptr; + delete g_pDefaultMgr; + g_pDefaultMgr = nullptr; } CPDF_ModuleMgr::CPDF_ModuleMgr() : m_pCodecModule(nullptr) {} diff --git a/core/fxge/ge/fx_ge.cpp b/core/fxge/ge/fx_ge.cpp index 4ebf812f12..fe0cc2c3eb 100644 --- a/core/fxge/ge/fx_ge.cpp +++ b/core/fxge/ge/fx_ge.cpp @@ -8,19 +8,19 @@ #include "core/fxge/ge/fx_text_int.h" -static CFX_GEModule* g_pGEModule = nullptr; +namespace { -CFX_GEModule::CFX_GEModule(const char** pUserFontPaths, - CCodec_ModuleMgr* pCodecModule) +CFX_GEModule* g_pGEModule = nullptr; + +} // namespace + +CFX_GEModule::CFX_GEModule() : m_FTLibrary(nullptr), m_pFontCache(nullptr), m_pFontMgr(new CFX_FontMgr), - m_pCodecModule(pCodecModule), + m_pCodecModule(nullptr), m_pPlatformData(nullptr), - m_pUserFontPaths(pUserFontPaths) { - InitPlatform(); - SetTextGamma(2.2f); -} + m_pUserFontPaths(nullptr) {} CFX_GEModule::~CFX_GEModule() { delete m_pFontCache; @@ -28,14 +28,9 @@ CFX_GEModule::~CFX_GEModule() { } // static -void CFX_GEModule::Create(const char** userFontPaths, - CCodec_ModuleMgr* pCodecModule) { - ASSERT(!g_pGEModule); - g_pGEModule = new CFX_GEModule(userFontPaths, pCodecModule); -} - -// static CFX_GEModule* CFX_GEModule::Get() { + if (!g_pGEModule) + g_pGEModule = new CFX_GEModule(); return g_pGEModule; } @@ -46,6 +41,15 @@ void CFX_GEModule::Destroy() { g_pGEModule = nullptr; } +void CFX_GEModule::Init(const char** userFontPaths, + CCodec_ModuleMgr* pCodecModule) { + ASSERT(g_pGEModule); + m_pCodecModule = pCodecModule; + m_pUserFontPaths = userFontPaths; + InitPlatform(); + SetTextGamma(2.2f); +} + CFX_FontCache* CFX_GEModule::GetFontCache() { if (!m_pFontCache) m_pFontCache = new CFX_FontCache(); diff --git a/core/fxge/include/fx_ge.h b/core/fxge/include/fx_ge.h index ea2adec1dc..dbc4fd0a43 100644 --- a/core/fxge/include/fx_ge.h +++ b/core/fxge/include/fx_ge.h @@ -23,11 +23,10 @@ class SkPictureRecorder; class CFX_GEModule { public: - static void Create(const char** pUserFontPaths, - CCodec_ModuleMgr* pCodecModule); static CFX_GEModule* Get(); static void Destroy(); + void Init(const char** pUserFontPaths, CCodec_ModuleMgr* pCodecModule); CFX_FontCache* GetFontCache(); CFX_FontMgr* GetFontMgr() { return m_pFontMgr.get(); } void SetTextGamma(FX_FLOAT gammaValue); @@ -39,7 +38,7 @@ class CFX_GEModule { FXFT_Library m_FTLibrary; private: - CFX_GEModule(const char** pUserFontPaths, CCodec_ModuleMgr* pCodecModule); + CFX_GEModule(); ~CFX_GEModule(); void InitPlatform(); @@ -48,7 +47,7 @@ class CFX_GEModule { uint8_t m_GammaValue[256]; CFX_FontCache* m_pFontCache; std::unique_ptr<CFX_FontMgr> m_pFontMgr; - CCodec_ModuleMgr* const m_pCodecModule; + CCodec_ModuleMgr* m_pCodecModule; void* m_pPlatformData; const char** m_pUserFontPaths; }; |