summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-07 15:28:14 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-07 15:28:14 -0800
commita9d29df6a774737a661d0f37f6b8aa5cba179c06 (patch)
tree0bd11a3575f9459163247de93db3fa375a44e98a
parentcd5e12a9ea397b48056643a7b65126395eec3174 (diff)
downloadpdfium-a9d29df6a774737a661d0f37f6b8aa5cba179c06.tar.xz
Properly ref count IFX_FileAccess.
Review-Url: https://codereview.chromium.org/2562563002
-rw-r--r--core/fxcrt/fx_extension.cpp28
-rw-r--r--core/fxcrt/fx_stream.h8
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp23
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.h2
4 files changed, 23 insertions, 38 deletions
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 630d4da2aa..ba82b9b7f0 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -25,36 +25,26 @@ namespace {
class CFX_CRTFileAccess : public IFX_FileAccess {
public:
- CFX_CRTFileAccess();
- ~CFX_CRTFileAccess() override;
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
// IFX_FileAccess
- void Release() override;
- IFX_FileAccess* Retain() override;
void GetPath(CFX_WideString& wsPath) override;
CFX_RetainPtr<IFX_SeekableStream> CreateFileStream(uint32_t dwModes) override;
bool Init(const CFX_WideStringC& wsPath);
private:
+ CFX_CRTFileAccess();
+ ~CFX_CRTFileAccess() override;
+
CFX_WideString m_path;
- uint32_t m_RefCount;
};
-CFX_CRTFileAccess::CFX_CRTFileAccess() : m_RefCount(0) {}
+CFX_CRTFileAccess::CFX_CRTFileAccess() {}
CFX_CRTFileAccess::~CFX_CRTFileAccess() {}
-void CFX_CRTFileAccess::Release() {
- if (--m_RefCount == 0)
- delete this;
-}
-
-IFX_FileAccess* CFX_CRTFileAccess::Retain() {
- m_RefCount++;
- return (IFX_FileAccess*)this;
-}
-
void CFX_CRTFileAccess::GetPath(CFX_WideString& wsPath) {
wsPath = m_path;
}
@@ -66,7 +56,6 @@ CFX_RetainPtr<IFX_SeekableStream> CFX_CRTFileAccess::CreateFileStream(
bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) {
m_path = wsPath;
- m_RefCount = 1;
return true;
}
@@ -385,11 +374,12 @@ bool CFX_MemoryStream::ExpandBlocks(size_t size) {
} // namespace
#ifdef PDF_ENABLE_XFA
-IFX_FileAccess* IFX_FileAccess::CreateDefault(const CFX_WideStringC& wsPath) {
+CFX_RetainPtr<IFX_FileAccess> IFX_FileAccess::CreateDefault(
+ const CFX_WideStringC& wsPath) {
if (wsPath.GetLength() == 0)
return nullptr;
- CFX_CRTFileAccess* pFA = new CFX_CRTFileAccess;
+ auto pFA = pdfium::MakeRetain<CFX_CRTFileAccess>();
pFA->Init(wsPath);
return pFA;
}
diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h
index b998761742..2f4b5ad280 100644
--- a/core/fxcrt/fx_stream.h
+++ b/core/fxcrt/fx_stream.h
@@ -143,13 +143,11 @@ class IFX_BufferedReadStream : public IFX_ReadStream {
};
#ifdef PDF_ENABLE_XFA
-class IFX_FileAccess {
+class IFX_FileAccess : public CFX_Retainable {
public:
- static IFX_FileAccess* CreateDefault(const CFX_WideStringC& wsPath);
+ static CFX_RetainPtr<IFX_FileAccess> CreateDefault(
+ const CFX_WideStringC& wsPath);
- virtual ~IFX_FileAccess() {}
- virtual void Release() = 0;
- virtual IFX_FileAccess* Retain() = 0;
virtual void GetPath(CFX_WideString& wsPath) = 0;
virtual CFX_RetainPtr<IFX_SeekableStream> CreateFileStream(
uint32_t dwModes) = 0;
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 060dd95b48..d7e7e8ed84 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -566,10 +566,12 @@ FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() {
return (FX_POSITION)-1;
}
-IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) {
- IFX_FileAccess* pAccess = IFX_FileAccess::CreateDefault(m_wsNext.AsStringC());
+CFX_RetainPtr<IFX_FileAccess> CFX_FontSourceEnum_File::GetNext(
+ FX_POSITION& pos) {
+ CFX_RetainPtr<IFX_FileAccess> pAccess =
+ IFX_FileAccess::CreateDefault(m_wsNext.AsStringC());
m_wsNext = GetNextFile().UTF8Decode();
- pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr;
+ pos = m_wsNext.GetLength() != 0 ? pAccess.Get() : nullptr;
return pAccess;
}
@@ -636,17 +638,12 @@ bool CFGAS_FontMgr::EnumFontsFromFontMapper() {
bool CFGAS_FontMgr::EnumFontsFromFiles() {
CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary();
FX_POSITION pos = m_pFontSource->GetStartPosition();
- IFX_FileAccess* pFontSource = nullptr;
- CFX_RetainPtr<IFX_SeekableReadStream> pFontStream;
while (pos) {
- pFontSource = m_pFontSource->GetNext(pos);
- pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly);
- if (!pFontStream) {
- pFontSource->Release();
- continue;
- }
- RegisterFaces(pFontStream, nullptr);
- pFontSource->Release();
+ CFX_RetainPtr<IFX_FileAccess> pFontSource = m_pFontSource->GetNext(pos);
+ CFX_RetainPtr<IFX_SeekableReadStream> pFontStream =
+ pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly);
+ if (pFontStream)
+ RegisterFaces(pFontStream, nullptr);
}
return m_InstalledFonts.GetSize() != 0;
}
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 28a8bb528a..d3eb8f1a85 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -179,7 +179,7 @@ class CFX_FontSourceEnum_File {
~CFX_FontSourceEnum_File();
FX_POSITION GetStartPosition();
- IFX_FileAccess* GetNext(FX_POSITION& pos);
+ CFX_RetainPtr<IFX_FileAccess> GetNext(FX_POSITION& pos);
private:
CFX_ByteString GetNextFile();