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

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: Self review 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 506124a20286639e4b5c638a5326c42e15f10d81..26de146605ae6ca9e1db4483aaba28b0749eb629 100644
--- a/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
+++ b/chrome/browser/android/offline_pages/offline_page_tab_helper.cc
@@ -67,20 +67,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_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);
@@ -92,22 +93,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_preview_ = false;
+ }
// Ignore navigations that are forward or back transitions in the nav stack
// which are not at the head of the stack.
// TODO(dimich): Not sure this is needed. Clarify and remove. Bug 624216.
const content::NavigationController& controller =
web_contents()->GetController();
if (controller.GetEntryCount() > 0 &&
controller.GetCurrentEntryIndex() != -1 &&
controller.GetCurrentEntryIndex() < controller.GetEntryCount() - 1) {
return;
@@ -194,20 +197,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_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)) {
@@ -272,20 +276,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_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