summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-24 16:20:29 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-24 16:20:29 -0700
commitddffb57cf9763e2612e9f6f5730f334691adb692 (patch)
tree9f7798eb5eb71fb5cb40aadc1da940891c71aa0b
parent5aaa9bc9193d74bb188dd1f890140cf38fb06605 (diff)
downloadpdfium-ddffb57cf9763e2612e9f6f5730f334691adb692.tar.xz
Remove CFX_PrivateData from CPDF_ModuleMgr
Its only used to store one object, so replace it with a unique_ptr to a class with a virtual dtor. Rename the prototypical class with virtual dtor from CFX_DestructObject to CFX_Deletable. Rename the fx_basic_module.cpp to cfx_modulemgr.cpp to match the one class in it. Review-Url: https://codereview.chromium.org/2013483003
-rw-r--r--BUILD.gn2
-rw-r--r--core/fpdfapi/cpdf_modulemgr.cpp (renamed from core/fpdfapi/fpdf_basic_module.cpp)10
-rw-r--r--core/fpdfapi/include/cpdf_modulemgr.h19
-rw-r--r--core/fxcodec/codec/fx_codec_jbig.cpp8
-rw-r--r--core/fxcrt/fx_basic_util.cpp4
-rw-r--r--core/fxcrt/include/fx_basic.h2
-rw-r--r--core/fxcrt/include/fx_memory.h4
-rw-r--r--fpdfsdk/fpdf_ext.cpp21
-rw-r--r--pdfium.gyp12
9 files changed, 32 insertions, 50 deletions
diff --git a/BUILD.gn b/BUILD.gn
index ee5aad5fd9..c6c279e762 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -244,7 +244,7 @@ static_library("fpdfdoc") {
static_library("fpdfapi") {
sources = [
- "core/fpdfapi/fpdf_basic_module.cpp",
+ "core/fpdfapi/cpdf_modulemgr.cpp",
"core/fpdfapi/fpdf_cmaps/CNS1/Adobe-CNS1-UCS2_5.cpp",
"core/fpdfapi/fpdf_cmaps/CNS1/B5pc-H_0.cpp",
"core/fpdfapi/fpdf_cmaps/CNS1/B5pc-V_0.cpp",
diff --git a/core/fpdfapi/fpdf_basic_module.cpp b/core/fpdfapi/cpdf_modulemgr.cpp
index 75450bf975..fe5368d3f7 100644
--- a/core/fpdfapi/fpdf_basic_module.cpp
+++ b/core/fpdfapi/cpdf_modulemgr.cpp
@@ -36,16 +36,6 @@ CPDF_ModuleMgr::CPDF_ModuleMgr() : m_pCodecModule(nullptr) {}
CPDF_ModuleMgr::~CPDF_ModuleMgr() {}
-void CPDF_ModuleMgr::SetPrivateData(void* module_id,
- void* pData,
- PD_CALLBACK_FREEDATA callback) {
- m_privateData.SetPrivateData(module_id, pData, callback);
-}
-
-void* CPDF_ModuleMgr::GetPrivateData(void* module_id) {
- return m_privateData.GetPrivateData(module_id);
-}
-
CCodec_FaxModule* CPDF_ModuleMgr::GetFaxModule() {
return m_pCodecModule ? m_pCodecModule->GetFaxModule() : nullptr;
}
diff --git a/core/fpdfapi/include/cpdf_modulemgr.h b/core/fpdfapi/include/cpdf_modulemgr.h
index e54bd07a90..95c5385e64 100644
--- a/core/fpdfapi/include/cpdf_modulemgr.h
+++ b/core/fpdfapi/include/cpdf_modulemgr.h
@@ -11,14 +11,13 @@
#include "core/fxcrt/include/fx_basic.h"
-class CCodec_ModuleMgr;
class CCodec_FaxModule;
class CCodec_FlateModule;
class CCodec_IccModule;
class CCodec_Jbig2Module;
class CCodec_JpegModule;
class CCodec_JpxModule;
-
+class CCodec_ModuleMgr;
class CPDF_PageModule;
class CPDF_ModuleMgr {
@@ -32,9 +31,15 @@ class CPDF_ModuleMgr {
CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule; }
void InitPageModule();
-
CPDF_PageModule* GetPageModule() const { return m_pPageModule.get(); }
+ void SetUnsupportInfoAdapter(std::unique_ptr<CFX_Deletable> pAdapter) {
+ m_pUnsupportInfoAdapter = std::move(pAdapter);
+ }
+ CFX_Deletable* GetUnsupportInfoAdapter() const {
+ return m_pUnsupportInfoAdapter.get();
+ }
+
void LoadEmbeddedGB1CMaps();
void LoadEmbeddedCNS1CMaps();
void LoadEmbeddedJapan1CMaps();
@@ -47,19 +52,13 @@ class CPDF_ModuleMgr {
CCodec_IccModule* GetIccModule();
CCodec_FlateModule* GetFlateModule();
- void SetPrivateData(void* module_id,
- void* pData,
- PD_CALLBACK_FREEDATA callback);
-
- void* GetPrivateData(void* module_id);
-
private:
CPDF_ModuleMgr();
~CPDF_ModuleMgr();
CCodec_ModuleMgr* m_pCodecModule;
std::unique_ptr<CPDF_PageModule> m_pPageModule;
- CFX_PrivateData m_privateData;
+ std::unique_ptr<CFX_Deletable> m_pUnsupportInfoAdapter;
};
#endif // CORE_FPDFAPI_INCLUDE_CPDF_MODULEMGR_H_
diff --git a/core/fxcodec/codec/fx_codec_jbig.cpp b/core/fxcodec/codec/fx_codec_jbig.cpp
index b5e32f130d..99cf2ec82f 100644
--- a/core/fxcodec/codec/fx_codec_jbig.cpp
+++ b/core/fxcodec/codec/fx_codec_jbig.cpp
@@ -30,7 +30,7 @@ class CCodec_Jbig2Context {
} // namespace
// Holds per-document JBig2 related data.
-class JBig2DocumentContext : public CFX_DestructObject {
+class JBig2DocumentContext : public CFX_Deletable {
public:
std::list<CJBig2_CachePair>* GetSymbolDictCache() {
return &m_SymbolDictCache;
@@ -50,9 +50,9 @@ JBig2DocumentContext* GetJBig2DocumentContext(CCodec_Jbig2Module* pModule,
CFX_PrivateData* pPrivateData) {
void* pModulePrivateData = pPrivateData->GetPrivateData(pModule);
if (pModulePrivateData) {
- CFX_DestructObject* pDestructObject =
- reinterpret_cast<CFX_DestructObject*>(pModulePrivateData);
- return static_cast<JBig2DocumentContext*>(pDestructObject);
+ CFX_Deletable* pDeletable =
+ reinterpret_cast<CFX_Deletable*>(pModulePrivateData);
+ return static_cast<JBig2DocumentContext*>(pDeletable);
}
JBig2DocumentContext* pJBig2DocumentContext = new JBig2DocumentContext();
pPrivateData->SetPrivateObj(pModule, pJBig2DocumentContext);
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index 2d3483e9b3..b073ea8f17 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -27,7 +27,7 @@ void FX_PRIVATEDATA::FreeData() {
return;
}
if (m_bSelfDestruct) {
- delete (CFX_DestructObject*)m_pData;
+ delete static_cast<CFX_Deletable*>(m_pData);
} else if (m_pCallback) {
m_pCallback(m_pData);
}
@@ -57,7 +57,7 @@ void CFX_PrivateData::SetPrivateData(void* pModuleId,
PD_CALLBACK_FREEDATA callback) {
AddData(pModuleId, pData, callback, FALSE);
}
-void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj) {
+void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_Deletable* pObj) {
AddData(pModuleId, pObj, NULL, TRUE);
}
FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) {
diff --git a/core/fxcrt/include/fx_basic.h b/core/fxcrt/include/fx_basic.h
index 848429e8f3..0f517e7217 100644
--- a/core/fxcrt/include/fx_basic.h
+++ b/core/fxcrt/include/fx_basic.h
@@ -639,7 +639,7 @@ class CFX_PrivateData {
void SetPrivateData(void* module_id,
void* pData,
PD_CALLBACK_FREEDATA callback);
- void SetPrivateObj(void* module_id, CFX_DestructObject* pObj);
+ void SetPrivateObj(void* module_id, CFX_Deletable* pObj);
void* GetPrivateData(void* module_id);
FX_BOOL LookupPrivateData(void* module_id, void*& pData) const {
diff --git a/core/fxcrt/include/fx_memory.h b/core/fxcrt/include/fx_memory.h
index 2614016550..3048897d76 100644
--- a/core/fxcrt/include/fx_memory.h
+++ b/core/fxcrt/include/fx_memory.h
@@ -100,9 +100,9 @@ struct ReleaseDeleter {
inline void operator()(T* ptr) const { ptr->Release(); }
};
-class CFX_DestructObject {
+class CFX_Deletable {
public:
- virtual ~CFX_DestructObject() {}
+ virtual ~CFX_Deletable() {}
};
#endif // __cplusplus
diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp
index 350945e328..0a76a0d4be 100644
--- a/fpdfsdk/fpdf_ext.cpp
+++ b/fpdfsdk/fpdf_ext.cpp
@@ -11,6 +11,7 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
#include "core/fpdfapi/include/cpdf_modulemgr.h"
+#include "core/fxcrt/include/fx_basic.h"
#include "core/fxcrt/include/fx_xml.h"
#include "fpdfsdk/include/fsdk_define.h"
@@ -20,7 +21,7 @@
#define FPDFSDK_UNSUPPORT_CALL 100
-class CFSDK_UnsupportInfo_Adapter {
+class CFSDK_UnsupportInfo_Adapter : public CFX_Deletable {
public:
explicit CFSDK_UnsupportInfo_Adapter(UNSUPPORT_INFO* unsp_info)
: m_unsp_info(unsp_info) {}
@@ -37,18 +38,13 @@ void CFSDK_UnsupportInfo_Adapter::ReportError(int nErrorType) {
}
}
-void FreeUnsupportInfo(void* pData) {
- CFSDK_UnsupportInfo_Adapter* pAdapter = (CFSDK_UnsupportInfo_Adapter*)pData;
- delete pAdapter;
-}
-
FX_BOOL FPDF_UnSupportError(int nError) {
CFSDK_UnsupportInfo_Adapter* pAdapter =
- (CFSDK_UnsupportInfo_Adapter*)CPDF_ModuleMgr::Get()->GetPrivateData(
- (void*)FPDFSDK_UNSUPPORT_CALL);
-
+ static_cast<CFSDK_UnsupportInfo_Adapter*>(
+ CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter());
if (!pAdapter)
return FALSE;
+
pAdapter->ReportError(nError);
return TRUE;
}
@@ -57,12 +53,9 @@ DLLEXPORT FPDF_BOOL STDCALL
FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) {
if (!unsp_info || unsp_info->version != 1)
return FALSE;
- CFSDK_UnsupportInfo_Adapter* pAdapter =
- new CFSDK_UnsupportInfo_Adapter(unsp_info);
-
- CPDF_ModuleMgr::Get()->SetPrivateData((void*)FPDFSDK_UNSUPPORT_CALL, pAdapter,
- &FreeUnsupportInfo);
+ CPDF_ModuleMgr::Get()->SetUnsupportInfoAdapter(std::unique_ptr<CFX_Deletable>(
+ new CFSDK_UnsupportInfo_Adapter(unsp_info)));
return TRUE;
}
diff --git a/pdfium.gyp b/pdfium.gyp
index 3a3bf69f42..ae30a3c1e5 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -262,7 +262,7 @@
'target_name': 'fpdfapi',
'type': 'static_library',
'sources': [
- 'core/fpdfapi/fpdf_basic_module.cpp',
+ 'core/fpdfapi/cpdf_modulemgr.cpp',
'core/fpdfapi/fpdf_cmaps/cmap_int.h',
'core/fpdfapi/fpdf_cmaps/CNS1/Adobe-CNS1-UCS2_5.cpp',
'core/fpdfapi/fpdf_cmaps/CNS1/B5pc-H_0.cpp',
@@ -326,8 +326,8 @@
'core/fpdfapi/fpdf_cmaps/Korea1/UniKS-UCS2-H_1.cpp',
'core/fpdfapi/fpdf_cmaps/Korea1/UniKS-UCS2-V_1.cpp',
'core/fpdfapi/fpdf_cmaps/Korea1/UniKS-UTF16-H_0.cpp',
- 'core/fpdfapi/fpdf_edit/editint.h',
'core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp',
+ 'core/fpdfapi/fpdf_edit/editint.h',
'core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp',
'core/fpdfapi/fpdf_edit/include/cpdf_creator.h',
'core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h',
@@ -382,8 +382,8 @@
'core/fpdfapi/fpdf_page/cpdf_meshstream.cpp',
'core/fpdfapi/fpdf_page/cpdf_meshstream.h',
'core/fpdfapi/fpdf_page/cpdf_page.cpp',
- "core/fpdfapi/fpdf_page/cpdf_pagemodule.cpp",
- "core/fpdfapi/fpdf_page/cpdf_pagemodule.h",
+ 'core/fpdfapi/fpdf_page/cpdf_pagemodule.cpp',
+ 'core/fpdfapi/fpdf_page/cpdf_pagemodule.h',
'core/fpdfapi/fpdf_page/cpdf_pageobject.cpp',
'core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp',
'core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp',
@@ -476,9 +476,9 @@
'core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp',
'core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp',
'core/fpdfapi/fpdf_render/fpdf_render_text.cpp',
- 'core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h',
- 'core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h',
'core/fpdfapi/fpdf_render/include/cpdf_progressiverenderer.h',
+ 'core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h',
+ 'core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h',
'core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h',
'core/fpdfapi/fpdf_render/render_int.h',
'core/fpdfapi/include/cpdf_modulemgr.h',