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

Unified Diff: chrome/browser/android/offline_pages/recent_tab_helper.cc

Issue 2083273004: RecentTabHelper: Move URL checking logic into DidFinishNavigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup logic and var naming. Created 4 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/offline_pages/recent_tab_helper.cc
diff --git a/chrome/browser/android/offline_pages/recent_tab_helper.cc b/chrome/browser/android/offline_pages/recent_tab_helper.cc
index afb1eecc354579f32914e8f9d789d27efe58cdaa..a064587fb9cc7ca6121c862f4a333604ac8940d7 100644
--- a/chrome/browser/android/offline_pages/recent_tab_helper.cc
+++ b/chrome/browser/android/offline_pages/recent_tab_helper.cc
@@ -68,9 +68,26 @@ void RecentTabHelper::DidFinishNavigation(
navigation_handle->HasCommitted()) {
// Cancel tasks in flight that relate to the previous page.
weak_ptr_factory_.InvalidateWeakPtrs();
+
// New navigation, new snapshot session.
+ snapshot_url_ = GURL();
+ GURL last_committed_url = web_contents()->GetLastCommittedURL();
+
+ // Check for conditions that would cause us not to snapshot.
+ bool can_save = !navigation_handle->IsErrorPage() &&
+ OfflinePageModel::CanSaveURL(last_committed_url);
+
+ // We only want to record UMA if the page is not Off The Record.
+ if (!never_do_snapshots_)
+ UMA_HISTOGRAM_BOOLEAN("OfflinePages.CanSaveRecentPage", can_save);
+
+ // Always reset so that posted tasks get cancelled.
snapshot_controller_->Reset();
- snapshot_url_ = GURL::EmptyGURL();
+
+ if (never_do_snapshots_ || !can_save)
+ snapshot_controller_->Stop();
+ else
+ snapshot_url_ = last_committed_url;
}
}
@@ -89,23 +106,6 @@ void RecentTabHelper::DocumentOnLoadCompletedInMainFrame() {
// Along the chain, the original URL is passed and compared, to detect
// possible navigation and cancel snapshot in that case.
void RecentTabHelper::StartSnapshot() {
- if (never_do_snapshots_)
- return;
-
- // Ignores any non-normal pages, like error pages.
- content::NavigationEntry* entry =
- web_contents()->GetController().GetLastCommittedEntry();
- if (!entry || entry->GetPageType() != content::PAGE_TYPE_NORMAL)
- return;
-
- GURL url = web_contents()->GetLastCommittedURL();
- bool can_save = OfflinePageModel::CanSaveURL(url);
- UMA_HISTOGRAM_BOOLEAN("OfflinePages.CanSaveRecentPage", can_save);
- if (!can_save)
- return;
-
- snapshot_url_ = url;
-
// TODO(dimich): Implement automatic cleanup as per design doc, based on
// storage limits and page age.
// This algorithm (remove pages before making sure the save was successful)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698