Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: core/fxcrt/fx_extension.cpp

Issue 2562563002: Properly ref count IFX_FileAccess. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | core/fxcrt/fx_stream.h » ('j') | xfa/fgas/font/cfgas_fontmgr.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_extension.cpp
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 630d4da2aae960c829b32a17cc426ad8666c10d8..ba82b9b7f0009700946b3995843f74fdb17bc07d 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);
dsinclair 2016/12/07 23:05:03 Does this need to be public?
Tom Sepez 2016/12/07 23:26:55 In C++, the placement of the friend statement does
// 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;
}
« no previous file with comments | « no previous file | core/fxcrt/fx_stream.h » ('j') | xfa/fgas/font/cfgas_fontmgr.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698