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

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

Issue 1902443003: Redirect immediately to offline copy on no network (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 7 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
Index: chrome/browser/android/offline_pages/offline_page_tab_helper.cc
diff --git a/chrome/browser/android/offline_pages/offline_page_tab_helper.cc b/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
index 3497df1e9a355f9f9cf63f5e9a6a37e1653d75a0..bdd3a1b21dbddbd7f5a74bc1001dd753b5a9424f 100644
--- a/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
+++ b/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
@@ -37,11 +37,6 @@ void OfflinePageTabHelper::DidStartNavigation(
if (!navigation_handle->IsInMainFrame())
return;
- // Redirecting to online version will only take effect when there is network
- // connection.
- if (net::NetworkChangeNotifier::IsOffline())
- return;
-
// Ignore navigations that are forward or back transitions in the nav stack
// which are not at the head of the stack.
const content::NavigationController& controller =
@@ -52,16 +47,27 @@ void OfflinePageTabHelper::DidStartNavigation(
return;
}
- // Skips if not loading an offline copy of saved page.
- GURL online_url = offline_pages::OfflinePageUtils::GetOnlineURLForOfflineURL(
+ GURL redirect_url;
+ if (net::NetworkChangeNotifier::IsOffline()) {
+ // When the network is disconnected, loading online page will result in
+ // immediate redirection to offline copy.
+ redirect_url = offline_pages::OfflinePageUtils::GetOfflineURLForOnlineURL(
+ web_contents()->GetBrowserContext(), navigation_handle->GetURL());
+ } else {
+ // When the network is connected, loading offline copy will result in
+ // immediate redirection to online page.
+ redirect_url = offline_pages::OfflinePageUtils::GetOnlineURLForOfflineURL(
web_contents()->GetBrowserContext(), navigation_handle->GetURL());
- if (!online_url.is_valid())
+ }
+
+ // Bails out if no redirection is needed.
+ if (!redirect_url.is_valid())
return;
// Avoids looping between online and offline redirections.
content::NavigationEntry* entry = controller.GetPendingEntry();
if (entry && !entry->GetRedirectChain().empty() &&
- entry->GetRedirectChain().back() == online_url) {
+ entry->GetRedirectChain().back() == redirect_url) {
return;
}
@@ -69,7 +75,7 @@ void OfflinePageTabHelper::DidStartNavigation(
FROM_HERE,
base::Bind(&OfflinePageTabHelper::Redirect,
weak_ptr_factory_.GetWeakPtr(),
- navigation_handle->GetURL(), online_url));
+ navigation_handle->GetURL(), redirect_url));
}
void OfflinePageTabHelper::DidFinishNavigation(
@@ -108,10 +114,13 @@ void OfflinePageTabHelper::DidFinishNavigation(
void OfflinePageTabHelper::Redirect(
const GURL& from_url, const GURL& to_url) {
- if (to_url.SchemeIsFile())
+ if (to_url.SchemeIsFile()) {
UMA_HISTOGRAM_COUNTS("OfflinePages.RedirectToOfflineCount", 1);
- else
+ OfflinePageUtils::MarkPageAccessed(
fgorski 2016/05/04 21:45:12 should we mark page access when it is loaded witho
jianli 2016/05/05 00:23:13 Done.
+ web_contents()->GetBrowserContext(), to_url);
+ } else {
UMA_HISTOGRAM_COUNTS("OfflinePages.RedirectToOnlineCount", 1);
+ }
content::NavigationController::LoadURLParams load_params(to_url);
load_params.transition_type = ui::PAGE_TRANSITION_CLIENT_REDIRECT;

Powered by Google App Engine
This is Rietveld 408576698