Commit 101c5449 authored by K Moon's avatar K Moon Committed by Commit Bot

Replace LoadPageInfo()'s |reload| with a field

Use a new |document_loaded_| field to decide whether or not to call
FPDFAvail_IsPageAvail() in PDFiumEngine::LoadPageInfo(). This enables
calling LoadPageInfo() without precisely tracking the correct value for
the |reload| parameter.

The |reload| parameter is used to defer calls to FPDFAvail_IsPageAvail()
from LoadPageInfo() until after FinishLoadingDocument() is called, but
this requires the caller to track whether or not FinishLoadingDocument()
has been called. It's simpler just to have FinishLoadingDocument()
directly mark whether or not it has executed.

The |reload| parameter previously was used to decide how to create
PDFiumPage instances as well, but this usage was eliminated in
crrev.com/702636. This incidentally made the DCHECK added in that change
superfluous, so it has been removed in this change.

Bug: 885110
Change-Id: I33a2d437c2f8abbea655b054c2259d85441d0752
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857545
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Auto-Submit: K Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708178}
parent d6297f27
...@@ -606,8 +606,10 @@ void PDFiumEngine::AppendPage(PDFEngine* engine, int index) { ...@@ -606,8 +606,10 @@ void PDFiumEngine::AppendPage(PDFEngine* engine, int index) {
FPDF_ImportPages(doc(), static_cast<PDFiumEngine*>(engine)->doc(), "1", FPDF_ImportPages(doc(), static_cast<PDFiumEngine*>(engine)->doc(), "1",
index); index);
pp::Size new_page_size = GetPageSize(index); pp::Size new_page_size = GetPageSize(index);
if (curr_page_size != new_page_size) if (curr_page_size != new_page_size) {
LoadPageInfo(true); DCHECK(document_loaded_);
LoadPageInfo();
}
client_->Invalidate(GetPageScreenRect(index)); client_->Invalidate(GetPageScreenRect(index));
} }
...@@ -668,8 +670,10 @@ void PDFiumEngine::OnPendingRequestComplete() { ...@@ -668,8 +670,10 @@ void PDFiumEngine::OnPendingRequestComplete() {
} }
} }
pending_pages_.swap(still_pending); pending_pages_.swap(still_pending);
if (update_pages) if (update_pages) {
LoadPageInfo(true); DCHECK(document_loaded_);
LoadPageInfo();
}
} }
void PDFiumEngine::OnNewDataReceived() { void PDFiumEngine::OnNewDataReceived() {
...@@ -716,8 +720,15 @@ void PDFiumEngine::FinishLoadingDocument() { ...@@ -716,8 +720,15 @@ void PDFiumEngine::FinishLoadingDocument() {
if (IsPageVisible(i)) if (IsPageVisible(i))
client_->Invalidate(GetPageScreenRect(i)); client_->Invalidate(GetPageScreenRect(i));
} }
// Transition |document_loaded_| to true after finishing any calls to
// FPDFAvail_IsPageAvail(), since we no longer need to defer calls to this
// function from LoadPageInfo(). Note that LoadBody() calls LoadPageInfo()
// indirectly, so we cannot make this transition earlier.
document_loaded_ = true;
if (need_update) if (need_update)
LoadPageInfo(true); LoadPageInfo();
if (called_do_document_action_) if (called_do_document_action_)
return; return;
...@@ -1917,7 +1928,8 @@ void PDFiumEngine::RotateCounterclockwise() { ...@@ -1917,7 +1928,8 @@ void PDFiumEngine::RotateCounterclockwise() {
void PDFiumEngine::InvalidateAllPages() { void PDFiumEngine::InvalidateAllPages() {
CancelPaints(); CancelPaints();
StopFind(); StopFind();
LoadPageInfo(true); DCHECK(document_loaded_);
LoadPageInfo();
client_->Invalidate(pp::Rect(plugin_size_)); client_->Invalidate(pp::Rect(plugin_size_));
} }
...@@ -2372,7 +2384,8 @@ void PDFiumEngine::AppendBlankPages(size_t num_pages) { ...@@ -2372,7 +2384,8 @@ void PDFiumEngine::AppendBlankPages(size_t num_pages) {
pages_.push_back(std::move(page)); pages_.push_back(std::move(page));
} }
LoadPageInfo(true); DCHECK(document_loaded_);
LoadPageInfo();
} }
void PDFiumEngine::LoadDocument() { void PDFiumEngine::LoadDocument() {
...@@ -2474,8 +2487,8 @@ void PDFiumEngine::ContinueLoadingDocument(const std::string& password) { ...@@ -2474,8 +2487,8 @@ void PDFiumEngine::ContinueLoadingDocument(const std::string& password) {
FinishLoadingDocument(); FinishLoadingDocument();
} }
void PDFiumEngine::LoadPageInfo(bool reload) { void PDFiumEngine::LoadPageInfo() {
std::vector<pp::Size> page_sizes = LoadPageSizes(reload); std::vector<pp::Size> page_sizes = LoadPageSizes();
if (page_sizes.empty()) if (page_sizes.empty())
return; return;
...@@ -2498,13 +2511,12 @@ void PDFiumEngine::LoadPageInfo(bool reload) { ...@@ -2498,13 +2511,12 @@ void PDFiumEngine::LoadPageInfo(bool reload) {
} }
} }
std::vector<pp::Size> PDFiumEngine::LoadPageSizes(bool reload) { std::vector<pp::Size> PDFiumEngine::LoadPageSizes() {
std::vector<pp::Size> page_sizes; std::vector<pp::Size> page_sizes;
if (!doc_loader_) if (!doc_loader_)
return page_sizes; return page_sizes;
if (pages_.empty() && reload) if (pages_.empty() && document_loaded_)
return page_sizes; return page_sizes;
DCHECK(reload || pages_.empty()) << "!reload expects no existing pages";
pending_pages_.clear(); pending_pages_.clear();
size_t new_page_count = FPDF_GetPageCount(doc()); size_t new_page_count = FPDF_GetPageCount(doc());
...@@ -2513,13 +2525,12 @@ std::vector<pp::Size> PDFiumEngine::LoadPageSizes(bool reload) { ...@@ -2513,13 +2525,12 @@ std::vector<pp::Size> PDFiumEngine::LoadPageSizes(bool reload) {
bool is_linear = bool is_linear =
FPDFAvail_IsLinearized(fpdf_availability()) == PDF_LINEARIZED; FPDFAvail_IsLinearized(fpdf_availability()) == PDF_LINEARIZED;
for (size_t i = 0; i < new_page_count; ++i) { for (size_t i = 0; i < new_page_count; ++i) {
// Get page availability. If |reload| == true and the page is not new, // Get page availability. If |document_loaded_| == true and the page is not
// then the page has been constructed already. Get page availability flag // new, then the page has been constructed already. Get page availability
// from already existing PDFiumPage object. // flag from already existing PDFiumPage object. If |document_loaded_| ==
// If |reload| == false or the page is new, then the page may not be fully // false or the page is new, then the page may not be fully loaded yet.
// loaded yet.
bool page_available; bool page_available;
if (reload && i < pages_.size()) { if (document_loaded_ && i < pages_.size()) {
page_available = pages_[i]->available(); page_available = pages_[i]->available();
} else if (is_linear) { } else if (is_linear) {
FX_DOWNLOADHINTS& download_hints = document_->download_hints(); FX_DOWNLOADHINTS& download_hints = document_->download_hints();
...@@ -2535,12 +2546,14 @@ std::vector<pp::Size> PDFiumEngine::LoadPageSizes(bool reload) { ...@@ -2535,12 +2546,14 @@ std::vector<pp::Size> PDFiumEngine::LoadPageSizes(bool reload) {
page_sizes.push_back(size); page_sizes.push_back(size);
} }
// Add new pages. If !reload, do not mark page as available even if // Add new pages. If |document_loaded_| == false, do not mark page as
// |doc_complete| is true because FPDFAvail_IsPageAvail() still has to be // available even if |doc_complete| is true because FPDFAvail_IsPageAvail()
// called for this page, which will be done in FinishLoadingDocument(). // still has to be called for this page, which will be done in
// FinishLoadingDocument().
for (size_t i = pages_.size(); i < new_page_count; ++i) { for (size_t i = pages_.size(); i < new_page_count; ++i) {
auto page = std::make_unique<PDFiumPage>(this, i); auto page = std::make_unique<PDFiumPage>(this, i);
if (reload && FPDFAvail_IsPageAvail(fpdf_availability(), i, nullptr)) if (document_loaded_ &&
FPDFAvail_IsPageAvail(fpdf_availability(), i, nullptr))
page->MarkAvailable(); page->MarkAvailable();
pages_.push_back(std::move(page)); pages_.push_back(std::move(page));
} }
...@@ -2581,7 +2594,8 @@ void PDFiumEngine::LoadPages() { ...@@ -2581,7 +2594,8 @@ void PDFiumEngine::LoadPages() {
// the document is available, the first page is available as well. // the document is available, the first page is available as well.
CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc()), &pending_pages_); CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc()), &pending_pages_);
} }
LoadPageInfo(false); DCHECK(!document_loaded_);
LoadPageInfo();
} }
} }
......
...@@ -246,7 +246,7 @@ class PDFiumEngine : public PDFEngine, ...@@ -246,7 +246,7 @@ class PDFiumEngine : public PDFEngine,
void FinishLoadingDocument(); void FinishLoadingDocument();
// Loads information about the pages in the document and performs layout. // Loads information about the pages in the document and performs layout.
void LoadPageInfo(bool reload); void LoadPageInfo();
// Loads information about the pages in the document, calculating and // Loads information about the pages in the document, calculating and
// returning the individual page sizes. // returning the individual page sizes.
...@@ -256,7 +256,7 @@ class PDFiumEngine : public PDFEngine, ...@@ -256,7 +256,7 @@ class PDFiumEngine : public PDFEngine,
// //
// TODO(kmoon): LoadPageSizes() is a bit misnomer, but LoadPageInfo() is // TODO(kmoon): LoadPageSizes() is a bit misnomer, but LoadPageInfo() is
// taken right now... // taken right now...
std::vector<pp::Size> LoadPageSizes(bool reload); std::vector<pp::Size> LoadPageSizes();
void LoadBody(); void LoadBody();
...@@ -574,6 +574,7 @@ class PDFiumEngine : public PDFEngine, ...@@ -574,6 +574,7 @@ class PDFiumEngine : public PDFEngine,
PDFiumFormFiller form_filler_; PDFiumFormFiller form_filler_;
std::unique_ptr<PDFiumDocument> document_; std::unique_ptr<PDFiumDocument> document_;
bool document_loaded_ = false;
// The page(s) of the document. // The page(s) of the document.
std::vector<std::unique_ptr<PDFiumPage>> pages_; std::vector<std::unique_ptr<PDFiumPage>> pages_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment