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

Unified Diff: testing/embedder_test.cpp

Issue 2258333002: Fix page leaks in an embedder test (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: new approach Created 4 years, 4 months 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 | « testing/embedder_test.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/embedder_test.cpp
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index b1207fba8267fe977b2234be9d9700b58cbda58b..e10e2a81e8d57dc7effbcc02cbdc5bacbf1ac650 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -242,21 +242,19 @@ int EmbedderTest::GetPageCount() {
}
FPDF_PAGE EmbedderTest::LoadPage(int page_number) {
+ // First check whether it is loaded already.
+ auto it = page_map_.find(page_number);
+ if (it != page_map_.end())
+ return it->second;
+
FPDF_PAGE page = FPDF_LoadPage(document_, page_number);
if (!page) {
return nullptr;
}
FORM_OnAfterLoadPage(page, form_handle_);
FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
- return page;
-}
-
-FPDF_PAGE EmbedderTest::LoadAndCachePage(int page_number) {
- FPDF_PAGE page = delegate_->GetPage(form_handle_, document_, page_number);
- if (!page) {
- return nullptr;
- }
- FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
+ // Cache the page.
+ page_map_[page_number] = page;
return page;
}
@@ -278,20 +276,12 @@ void EmbedderTest::UnloadPage(FPDF_PAGE page) {
FPDF_ClosePage(page);
}
-FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMHANDLE form_handle,
+FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMFILLINFO* info,
FPDF_DOCUMENT document,
int page_index) {
- auto it = m_pageMap.find(page_index);
- if (it != m_pageMap.end()) {
- return it->second;
- }
- FPDF_PAGE page = FPDF_LoadPage(document, page_index);
- if (!page) {
- return nullptr;
- }
- m_pageMap[page_index] = page;
- FORM_OnAfterLoadPage(page, form_handle);
- return page;
+ EmbedderTest* test = static_cast<EmbedderTest*>(info);
+ auto it = test->page_map_.find(page_index);
+ return it != test->page_map_.end() ? it->second : nullptr;
}
// static
@@ -329,8 +319,8 @@ void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) {
FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info,
FPDF_DOCUMENT document,
int page_index) {
- EmbedderTest* test = static_cast<EmbedderTest*>(info);
- return test->delegate_->GetPage(test->form_handle(), document, page_index);
+ return static_cast<EmbedderTest*>(info)->delegate_->GetPage(info, document,
+ page_index);
}
// Can't use gtest-provided main since we need to stash the path to the
« no previous file with comments | « testing/embedder_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698