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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_tab_helper.cc

Issue 1976163004: [Offline Pages] Adds Rappor metrics measuring what domains are saved & viewed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-store
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "chrome/browser/android/offline_pages/offline_page_utils.h" 11 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
12 #include "chrome/browser/browser_process.h"
13 #include "components/rappor/rappor_utils.h"
12 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/navigation_handle.h" 17 #include "content/public/browser/navigation_handle.h"
16 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
19 #include "net/base/network_change_notifier.h" 21 #include "net/base/network_change_notifier.h"
20 #include "ui/base/page_transition_types.h" 22 #include "ui/base/page_transition_types.h"
21 23
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 error_code != net::ERR_PROXY_CONNECTION_FAILED) { 102 error_code != net::ERR_PROXY_CONNECTION_FAILED) {
101 return; 103 return;
102 } 104 }
103 105
104 // On a forward or back transition, don't affect the order of the nav stack. 106 // On a forward or back transition, don't affect the order of the nav stack.
105 if (navigation_handle->GetPageTransition() == 107 if (navigation_handle->GetPageTransition() ==
106 ui::PAGE_TRANSITION_FORWARD_BACK) { 108 ui::PAGE_TRANSITION_FORWARD_BACK) {
107 return; 109 return;
108 } 110 }
109 111
112 GURL online_url = navigation_handle->GetURL();
113
110 // When the navigation starts, we redirect immediately from online page to 114 // When the navigation starts, we redirect immediately from online page to
111 // offline version on the case that there is no network connection. If there 115 // offline version on the case that there is no network connection. If there
112 // is still network connection but with no or poor network connectivity, the 116 // is still network connection but with no or poor network connectivity, the
113 // navigation will eventually fail and we want to redirect to offline copy 117 // navigation will eventually fail and we want to redirect to offline copy
114 // in this case. 118 // in this case.
115 GURL offline_url = offline_pages::OfflinePageUtils::GetOfflineURLForOnlineURL( 119 GURL offline_url = offline_pages::OfflinePageUtils::GetOfflineURLForOnlineURL(
116 web_contents()->GetBrowserContext(), navigation_handle->GetURL()); 120 web_contents()->GetBrowserContext(), online_url);
117 if (!offline_url.is_valid()) 121 if (!offline_url.is_valid())
118 return; 122 return;
119 123
124 rappor::SampleDomainAndRegistryFromGURL(
125 g_browser_process->rappor_service(),
126 "OfflinePages.OfflineVersionWasViewedWhileOffline", online_url);
127
120 base::ThreadTaskRunnerHandle::Get()->PostTask( 128 base::ThreadTaskRunnerHandle::Get()->PostTask(
121 FROM_HERE, 129 FROM_HERE,
122 base::Bind(&OfflinePageTabHelper::Redirect, 130 base::Bind(&OfflinePageTabHelper::Redirect,
123 weak_ptr_factory_.GetWeakPtr(), 131 weak_ptr_factory_.GetWeakPtr(),
124 navigation_handle->GetURL(), offline_url)); 132 navigation_handle->GetURL(), offline_url));
125 } 133 }
126 134
127 void OfflinePageTabHelper::Redirect( 135 void OfflinePageTabHelper::Redirect(
128 const GURL& from_url, const GURL& to_url) { 136 const GURL& from_url, const GURL& to_url) {
129 if (to_url.SchemeIsFile()) { 137 if (to_url.SchemeIsFile()) {
130 UMA_HISTOGRAM_COUNTS("OfflinePages.RedirectToOfflineCount", 1); 138 UMA_HISTOGRAM_COUNTS("OfflinePages.RedirectToOfflineCount", 1);
131 } else { 139 } else {
132 UMA_HISTOGRAM_COUNTS("OfflinePages.RedirectToOnlineCount", 1); 140 UMA_HISTOGRAM_COUNTS("OfflinePages.RedirectToOnlineCount", 1);
133 } 141 }
134 142
135 content::NavigationController::LoadURLParams load_params(to_url); 143 content::NavigationController::LoadURLParams load_params(to_url);
136 load_params.transition_type = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 144 load_params.transition_type = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
137 load_params.redirect_chain.push_back(from_url); 145 load_params.redirect_chain.push_back(from_url);
138 web_contents()->GetController().LoadURLWithParams(load_params); 146 web_contents()->GetController().LoadURLWithParams(load_params);
139 } 147 }
140 148
141 } // namespace offline_pages 149 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698