diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2018-06-28 00:03:03 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-28 00:03:03 +0000 |
commit | 774c90d5ec92d2c58d821c445230d8cb71928dcb (patch) | |
tree | ed3d6bf9ebb646326c9d3729149957b4f33eaa0c | |
parent | b8f24bb50582436c7fb261b5021f7af6813f3968 (diff) | |
download | pdfium-774c90d5ec92d2c58d821c445230d8cb71928dcb.tar.xz |
Use UnownedPtr for document within CPDF_XXXAvail.
Change-Id: I9ded1664564c330132f43047293e18696d77fc7d
Reviewed-on: https://pdfium-review.googlesource.com/36310
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 38 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_object_avail.h | 3 |
3 files changed, 34 insertions, 11 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 95db3d81c0..89b576bdea 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -70,6 +70,17 @@ class HintsScope { UnownedPtr<CPDF_ReadValidator> validator_; }; +class CPDF_DocumentForAvail : public CPDF_Document { + public: + explicit CPDF_DocumentForAvail(CPDF_DataAvail* avail) : m_pAvail(avail) { + DCHECK(avail); + } + ~CPDF_DocumentForAvail() override { m_pAvail->BeforeDocumentDestroyed(); } + + private: + UnownedPtr<CPDF_DataAvail> m_pAvail; +}; + } // namespace CPDF_DataAvail::FileAvail::~FileAvail() {} @@ -89,6 +100,14 @@ CPDF_DataAvail::~CPDF_DataAvail() { m_pHintTables.reset(); } +void CPDF_DataAvail::BeforeDocumentDestroyed() { + m_pDocument = nullptr; + m_pFormAvail.reset(); + m_PagesArray.clear(); + m_PagesObjAvail.clear(); + m_PagesResourcesAvail.clear(); +} + CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( DownloadHints* pHints) { if (!m_dwFileLen) @@ -816,7 +835,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( auto page_num_obj = std::make_pair( dwPage, pdfium::MakeUnique<CPDF_PageObjectAvail>( - GetValidator().Get(), m_pDocument, pPageDict)); + GetValidator().Get(), m_pDocument.Get(), pPageDict)); CPDF_PageObjectAvail* page_obj_avail = m_PagesObjAvail.insert(std::move(page_num_obj)).first->second.get(); @@ -868,7 +887,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( { auto page_num_obj = std::make_pair( dwPage, pdfium::MakeUnique<CPDF_PageObjectAvail>( - GetValidator().Get(), m_pDocument, pPageDict)); + GetValidator().Get(), m_pDocument.Get(), pPageDict)); CPDF_PageObjectAvail* page_obj_avail = m_PagesObjAvail.insert(std::move(page_num_obj)).first->second.get(); const DocAvailStatus status = page_obj_avail->CheckAvail(); @@ -900,8 +919,9 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckResources( CPDF_PageObjectAvail* resource_avail = m_PagesResourcesAvail .insert(std::make_pair( - resources, pdfium::MakeUnique<CPDF_PageObjectAvail>( - GetValidator().Get(), m_pDocument, resources))) + resources, + pdfium::MakeUnique<CPDF_PageObjectAvail>( + GetValidator().Get(), m_pDocument.Get(), resources))) .first->second.get(); return resource_avail->CheckAvail(); } @@ -944,7 +964,8 @@ CPDF_Dictionary* CPDF_DataAvail::GetPageDictionary(int index) const { // Page object already can be parsed in document. if (!m_pDocument->GetIndirectObject(dwObjNum)) { m_pDocument->ReplaceIndirectObjectIfHigherGeneration( - dwObjNum, ParseIndirectObjectAt(szPageStartPos, dwObjNum, m_pDocument)); + dwObjNum, + ParseIndirectObjectAt(szPageStartPos, dwObjNum, m_pDocument.Get())); } if (!ValidatePage(index)) return nullptr; @@ -979,7 +1000,7 @@ CPDF_DataAvail::DocFormStatus CPDF_DataAvail::CheckAcroForm() { return FormNotExist; m_pFormAvail = pdfium::MakeUnique<CPDF_PageObjectAvail>( - GetValidator().Get(), m_pDocument, pAcroForm); + GetValidator().Get(), m_pDocument.Get(), pAcroForm); } switch (m_pFormAvail->CheckAvail()) { case DocAvailStatus::DataError: @@ -999,7 +1020,8 @@ bool CPDF_DataAvail::ValidatePage(uint32_t dwPage) const { auto* pPageDict = m_pDocument->GetPageDictionary(safePage.ValueOrDie()); if (!pPageDict) return false; - CPDF_PageObjectAvail obj_avail(GetValidator().Get(), m_pDocument, pPageDict); + CPDF_PageObjectAvail obj_avail(GetValidator().Get(), m_pDocument.Get(), + pPageDict); return obj_avail.CheckAvail() == DocAvailStatus::DataAvailable; } @@ -1009,7 +1031,7 @@ CPDF_DataAvail::ParseDocument(const char* password) { // We already returned parsed document. return std::make_pair(CPDF_Parser::HANDLER_ERROR, nullptr); } - auto document = pdfium::MakeUnique<CPDF_Document>(); + auto document = pdfium::MakeUnique<CPDF_DocumentForAvail>(this); CPDF_ReadValidator::Session read_session(GetValidator().Get()); CPDF_Parser::Error error = diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index b6396bf82a..3c45116088 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -97,6 +97,8 @@ class CPDF_DataAvail final { bool bSupportHintTable); ~CPDF_DataAvail(); + void BeforeDocumentDestroyed(); + DocAvailStatus IsDocAvail(DownloadHints* pHints); DocAvailStatus IsPageAvail(uint32_t dwPage, DownloadHints* pHints); DocFormStatus IsFormAvail(DownloadHints* pHints); @@ -172,7 +174,7 @@ class CPDF_DataAvail final { std::unique_ptr<CPDF_CrossRefAvail> m_pCrossRefAvail; PDF_DATAAVAIL_STATUS m_docStatus = PDF_DATAAVAIL_HEADER; const FX_FILESIZE m_dwFileLen; - CPDF_Document* m_pDocument = nullptr; + UnownedPtr<CPDF_Document> m_pDocument; std::vector<uint32_t> m_PageObjList; uint32_t m_PagesObjNum = 0; bool m_bLinearedDataOK = false; diff --git a/core/fpdfapi/parser/cpdf_object_avail.h b/core/fpdfapi/parser/cpdf_object_avail.h index f593ea2159..040cec7252 100644 --- a/core/fpdfapi/parser/cpdf_object_avail.h +++ b/core/fpdfapi/parser/cpdf_object_avail.h @@ -43,8 +43,7 @@ class CPDF_ObjectAvail { bool HasObjectParsed(uint32_t obj_num) const; UnownedPtr<CPDF_ReadValidator> validator_; - // TODO(art-snake): Make it UnownedPtr<, after fix document owning issue. - CPDF_IndirectObjectHolder* holder_; + UnownedPtr<CPDF_IndirectObjectHolder> holder_; MaybeOwned<const CPDF_Object> root_; std::set<uint32_t> parsed_objnums_; std::stack<uint32_t> non_parsed_objects_; |