summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_docpagedata.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-04 14:37:18 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 21:48:48 +0000
commitafd0d1f488ea55da545b3310fd8f22e45522a695 (patch)
tree89136eba4669421b6f828edb9f3d69ee558110d0 /core/fpdfapi/page/cpdf_docpagedata.cpp
parent4f8b044b95dc282959dfe41453e2a9c1ec7e9354 (diff)
downloadpdfium-afd0d1f488ea55da545b3310fd8f22e45522a695.tar.xz
RefCount CPDF_StreamAcc all the time.
Pass stream argument to constructor; it feels like a stream accessor should always be made from a stream rather than passing one in after the fact. Change-Id: Iaa46cb37677b81f0170f5d39bab76ad38ea4af44 Reviewed-on: https://pdfium-review.googlesource.com/3620 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/cpdf_docpagedata.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.cpp52
1 files changed, 14 insertions, 38 deletions
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index a57c42d3cd..5e13740c21 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -96,15 +96,8 @@ void CPDF_DocPageData::Clear(bool bForceRelease) {
for (auto it = m_FontFileMap.begin(); it != m_FontFileMap.end();) {
auto curr_it = it++;
- CPDF_CountedStreamAcc* pCountedFont = curr_it->second;
- if (!pCountedFont->get())
- continue;
-
- if (bForceRelease || pCountedFont->use_count() < 2) {
- delete pCountedFont->get();
- delete pCountedFont;
+ if (bForceRelease || curr_it->second->HasOneRef())
m_FontFileMap.erase(curr_it);
- }
}
m_ImageMap.clear();
@@ -408,11 +401,11 @@ CFX_RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
if (it != m_IccProfileMap.end())
return it->second;
- CPDF_StreamAcc accessor;
- accessor.LoadAllData(pProfileStream, false);
+ auto pAccessor = pdfium::MakeRetain<CPDF_StreamAcc>(pProfileStream);
+ pAccessor->LoadAllData(false);
uint8_t digest[20];
- CRYPT_SHA1Generate(accessor.GetData(), accessor.GetSize(), digest);
+ CRYPT_SHA1Generate(pAccessor->GetData(), pAccessor->GetSize(), digest);
CFX_ByteString bsDigest(digest, 20);
auto hash_it = m_HashProfileMap.find(bsDigest);
@@ -422,7 +415,7 @@ CFX_RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
return it_copied_stream->second;
}
auto pProfile = pdfium::MakeRetain<CPDF_IccProfile>(
- pProfileStream, accessor.GetData(), accessor.GetSize());
+ pProfileStream, pAccessor->GetData(), pAccessor->GetSize());
m_IccProfileMap[pProfileStream] = pProfile;
m_HashProfileMap[bsDigest] = pProfileStream;
return pProfile;
@@ -435,13 +428,12 @@ void CPDF_DocPageData::MaybePurgeIccProfile(CPDF_Stream* pProfileStream) {
m_IccProfileMap.erase(it);
}
-CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(
+CFX_RetainPtr<CPDF_StreamAcc> CPDF_DocPageData::GetFontFileStreamAcc(
CPDF_Stream* pFontStream) {
ASSERT(pFontStream);
-
auto it = m_FontFileMap.find(pFontStream);
if (it != m_FontFileMap.end())
- return it->second->AddRef();
+ return it->second;
CPDF_Dictionary* pFontDict = pFontStream->GetDict();
int32_t org_size = pFontDict->GetIntegerFor("Length1") +
@@ -449,36 +441,20 @@ CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(
pFontDict->GetIntegerFor("Length3");
org_size = std::max(org_size, 0);
- auto pFontAcc = pdfium::MakeUnique<CPDF_StreamAcc>();
- pFontAcc->LoadAllData(pFontStream, false, org_size);
-
- CPDF_CountedStreamAcc* pCountedFont =
- new CPDF_CountedStreamAcc(std::move(pFontAcc));
- m_FontFileMap[pFontStream] = pCountedFont;
- return pCountedFont->AddRef();
+ auto pFontAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pFontStream);
+ pFontAcc->LoadAllData(false, org_size);
+ m_FontFileMap[pFontStream] = pFontAcc;
+ return pFontAcc;
}
-void CPDF_DocPageData::ReleaseFontFileStreamAcc(
+void CPDF_DocPageData::MaybePurgeFontFileStreamAcc(
const CPDF_Stream* pFontStream) {
if (!pFontStream)
return;
auto it = m_FontFileMap.find(pFontStream);
- if (it == m_FontFileMap.end())
- return;
-
- CPDF_CountedStreamAcc* pCountedStream = it->second;
- if (!pCountedStream)
- return;
-
- pCountedStream->RemoveRef();
- if (pCountedStream->use_count() > 1)
- return;
-
- // We have item only in m_FontFileMap cache. Clean it.
- delete pCountedStream->get();
- delete pCountedStream;
- m_FontFileMap.erase(it);
+ if (it != m_FontFileMap.end() && it->second->HasOneRef())
+ m_FontFileMap.erase(it);
}
CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(