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

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

Issue 2245213002: Add PageLoad.* metrics for Offline Previews (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: csharrison comments 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
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 2e1715be706a4b5f5594e146cb664df4352bf17f..4503194bb679084e831ea8f6747fdc85ca8cbf49 100644
--- a/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
+++ b/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
@@ -68,20 +68,21 @@ class DefaultDelegate : public OfflinePageTabHelper::Delegate {
int* tab_id) const override {
return OfflinePageUtils::GetTabId(web_contents, tab_id);
}
base::Time Now() const override { return base::Time::Now(); }
};
} // namespace
OfflinePageTabHelper::OfflinePageTabHelper(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
delegate_(new DefaultDelegate()),
+ is_offline_preview_(false),
weak_ptr_factory_(this) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
}
OfflinePageTabHelper::~OfflinePageTabHelper() {}
void OfflinePageTabHelper::SetDelegateForTesting(
std::unique_ptr<OfflinePageTabHelper::Delegate> delegate) {
DCHECK(delegate);
delegate_ = std::move(delegate);
@@ -93,22 +94,24 @@ void OfflinePageTabHelper::DidStartNavigation(
if (!navigation_handle->IsInMainFrame())
return;
// This is a new navigation so we can invalidate any previously scheduled
// operations.
weak_ptr_factory_.InvalidateWeakPtrs();
// Since this is a new navigation, we will reset the cached offline page,
// unless we are currently looking at an offline page.
GURL navigated_url = navigation_handle->GetURL();
- if (offline_page_ && navigated_url != offline_page_->GetOfflineURL())
+ if (offline_page_ && navigated_url != offline_page_->GetOfflineURL()) {
offline_page_ = nullptr;
+ is_offline_preview_ = false;
+ }
// If an offline download file is opened, don't do redirect per network
// conditions. Also store a cached copy here such that Tab knows that
// the offline page is opened.
if (OfflinePageUtils::MightBeOfflineURL(navigated_url)) {
OfflinePageModel* offline_page_model =
OfflinePageModelFactory::GetForBrowserContext(
web_contents()->GetBrowserContext());
if (offline_page_model) {
const OfflinePageItem* offline_page =
@@ -213,20 +216,21 @@ void OfflinePageTabHelper::RedirectToOnline(
GURL redirect_url = offline_page->url;
if (IsInRedirectLoop(redirect_url)) {
ReportRedirectResultUMA(RedirectResult::REDIRECT_LOOP_ONLINE);
return;
}
Redirect(navigated_url, redirect_url);
// Clear the offline page since we are redirecting to online.
offline_page_ = nullptr;
+ is_offline_preview_ = false;
ReportRedirectResultUMA(RedirectResult::REDIRECTED_ON_CONNECTED_NETWORK);
}
void OfflinePageTabHelper::GetBestPageForRedirectToOffline(
RedirectResult result, const GURL& online_url) {
// When there is no valid tab android there is nowhere to show the offline
// page, so we can leave.
int tab_id;
if (!delegate_->GetTabId(web_contents(), &tab_id)) {
@@ -291,20 +295,22 @@ void OfflinePageTabHelper::TryRedirectToOffline(
if (!redirect_url.is_valid())
return;
if (IsInRedirectLoop(redirect_url)) {
ReportRedirectResultUMA(RedirectResult::REDIRECT_LOOP_OFFLINE);
return;
}
Redirect(from_url, redirect_url);
offline_page_ = base::MakeUnique<OfflinePageItem>(offline_page);
+ is_offline_preview_ =
+ (result == RedirectResult::REDIRECTED_ON_PROHIBITIVELY_SLOW_NETWORK);
ReportRedirectResultUMA(result);
}
void OfflinePageTabHelper::Redirect(const GURL& from_url, const GURL& to_url) {
content::NavigationController::LoadURLParams load_params(to_url);
load_params.transition_type = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
load_params.redirect_chain.push_back(from_url);
web_contents()->GetController().LoadURLWithParams(load_params);
}

Powered by Google App Engine
This is Rietveld 408576698