diff options
author | tsepez <tsepez@chromium.org> | 2016-12-07 09:21:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-07 09:21:18 -0800 |
commit | 833619b4441915c7c55085d44b3221eaef0d9800 (patch) | |
tree | 68bf76e83078223ba03f490c2c13f484e40154d4 /fpdfsdk/fpdf_dataavail.cpp | |
parent | 8f875507a986d10335e40a5f7c1679aff9770d0a (diff) | |
download | pdfium-833619b4441915c7c55085d44b3221eaef0d9800.tar.xz |
Refcount all the IFX_ stream classes all the time.
We can remove a lot of "bOwnsStream" logic in the process.
Always pass these by const reference, in case the called method
wants to hang on to the stream (one exception is where we stick
a raw pointer into a void* slot in a context from another layer).
Review-Url: https://codereview.chromium.org/2451493002
Diffstat (limited to 'fpdfsdk/fpdf_dataavail.cpp')
-rw-r--r-- | fpdfsdk/fpdf_dataavail.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp index a3accba766..b1bc1e3bc0 100644 --- a/fpdfsdk/fpdf_dataavail.cpp +++ b/fpdfsdk/fpdf_dataavail.cpp @@ -11,6 +11,7 @@ #include "core/fpdfapi/parser/cpdf_data_avail.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fxcrt/cfx_retain_ptr.h" #include "fpdfsdk/fsdk_define.h" #include "public/fpdf_formfill.h" #include "third_party/base/ptr_util.h" @@ -43,7 +44,7 @@ namespace { class CFPDF_FileAvailWrap : public CPDF_DataAvail::FileAvail { public: - CFPDF_FileAvailWrap() { m_pfileAvail = nullptr; } + CFPDF_FileAvailWrap() : m_pfileAvail(nullptr) {} ~CFPDF_FileAvailWrap() override {} void Set(FX_FILEAVAIL* pfileAvail) { m_pfileAvail = pfileAvail; } @@ -59,7 +60,9 @@ class CFPDF_FileAvailWrap : public CPDF_DataAvail::FileAvail { class CFPDF_FileAccessWrap : public IFX_SeekableReadStream { public: - CFPDF_FileAccessWrap() { m_pFileAccess = nullptr; } + static CFX_RetainPtr<CFPDF_FileAccessWrap> Create() { + return CFX_RetainPtr<CFPDF_FileAccessWrap>(new CFPDF_FileAccessWrap()); + } ~CFPDF_FileAccessWrap() override {} void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } @@ -72,9 +75,9 @@ class CFPDF_FileAccessWrap : public IFX_SeekableReadStream { (uint8_t*)buffer, size); } - void Release() override {} - private: + CFPDF_FileAccessWrap() : m_pFileAccess(nullptr) {} + FPDF_FILEACCESS* m_pFileAccess; }; @@ -97,12 +100,14 @@ class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints { class CFPDF_DataAvail { public: - CFPDF_DataAvail() {} + CFPDF_DataAvail() + : m_FileAvail(new CFPDF_FileAvailWrap), + m_FileRead(CFPDF_FileAccessWrap::Create()) {} ~CFPDF_DataAvail() {} std::unique_ptr<CPDF_DataAvail> m_pDataAvail; - CFPDF_FileAvailWrap m_FileAvail; - CFPDF_FileAccessWrap m_FileRead; + std::unique_ptr<CFPDF_FileAvailWrap> m_FileAvail; + CFX_RetainPtr<CFPDF_FileAccessWrap> m_FileRead; }; CFPDF_DataAvail* CFPDFDataAvailFromFPDFAvail(FPDF_AVAIL avail) { @@ -114,10 +119,10 @@ CFPDF_DataAvail* CFPDFDataAvailFromFPDFAvail(FPDF_AVAIL avail) { DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, FPDF_FILEACCESS* file) { CFPDF_DataAvail* pAvail = new CFPDF_DataAvail; - pAvail->m_FileAvail.Set(file_avail); - pAvail->m_FileRead.Set(file); + pAvail->m_FileAvail->Set(file_avail); + pAvail->m_FileRead->Set(file); pAvail->m_pDataAvail = pdfium::MakeUnique<CPDF_DataAvail>( - &pAvail->m_FileAvail, &pAvail->m_FileRead, true); + pAvail->m_FileAvail.get(), pAvail->m_FileRead, true); return pAvail; } |