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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 1550193002: Simplify PDFiumEngine::CheckPageAvailable(). Base URL: https://chromium.googlesource.com/chromium/src.git@pdfload
Patch Set: more Created 5 years 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 | « no previous file | pdf/pdfium/pdfium_page.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/pdfium/pdfium_engine.cc
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index 9bf10fb7c515dbe0390117372f5955b2f79ff83e..713d95f2690d1f0181ff711bce1c41221bb1e169 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -1167,10 +1167,13 @@ void PDFiumEngine::FinishLoadingDocument() {
if (pages_[i]->available())
continue;
- pages_[i]->set_available(true);
+ pages_[i]->set_as_available();
// We still need to call IsPageAvail() even if the whole document is
// already downloaded.
- FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_);
+ // Page should be available because the whole document is available.
+ int avail = FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_);
+ DCHECK_EQ(PDF_DATA_AVAIL, avail);
+
need_update = true;
if (IsPageVisible(i))
client_->Invalidate(GetPageScreenRect(i));
@@ -2748,26 +2751,26 @@ bool PDFiumEngine::IsPageVisible(int index) const {
}
bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) {
- if (!doc_ || !form_)
+ if (!doc_ || !form_ || index < 0)
return false;
- if (static_cast<int>(pages_.size()) > index && pages_[index]->available())
+ const size_t index_size_t = static_cast<size_t>(index);
+ if (index_size_t < pages_.size() && pages_[index]->available())
return true;
- if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) {
- size_t j;
- for (j = 0; j < pending->size(); ++j) {
- if ((*pending)[j] == index)
- break;
- }
+ int avail =
+ FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_);
+ if (avail == PDF_DATA_ERROR)
+ return false;
- if (j == pending->size())
+ if (avail == PDF_DATA_NOTAVAIL) {
+ if (!ContainsValue(*pending, index))
pending->push_back(index);
return false;
}
- if (static_cast<int>(pages_.size()) > index)
- pages_[index]->set_available(true);
+ if (index_size_t < pages_.size())
+ pages_[index]->set_as_available();
if (!default_page_size_.GetArea())
default_page_size_ = GetPageSize(index);
return true;
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698