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

Side by Side Diff: chrome/browser/engagement/site_engagement_helper.cc

Issue 1967013002: Migrate the site engagement service to use DidFinishNavigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
« no previous file with comments | « chrome/browser/engagement/site_engagement_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/engagement/site_engagement_helper.h" 5 #include "chrome/browser/engagement/site_engagement_helper.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
11 #include "chrome/browser/engagement/site_engagement_service.h" 11 #include "chrome/browser/engagement/site_engagement_service.h"
12 #include "chrome/browser/engagement/site_engagement_service_factory.h" 12 #include "chrome/browser/engagement/site_engagement_service_factory.h"
13 #include "chrome/browser/prerender/prerender_contents.h" 13 #include "chrome/browser/prerender/prerender_contents.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "content/public/browser/navigation_details.h" 15 #include "content/public/browser/navigation_handle.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 17
18 namespace { 18 namespace {
19 19
20 int g_seconds_to_pause_engagement_detection = 10; 20 int g_seconds_to_pause_engagement_detection = 10;
21 int g_seconds_delay_after_navigation = 10; 21 int g_seconds_delay_after_navigation = 10;
22 int g_seconds_delay_after_media_starts = 10; 22 int g_seconds_delay_after_media_starts = 10;
23 int g_seconds_delay_after_show = 5; 23 int g_seconds_delay_after_show = 5;
24 24
25 } // anonymous namespace 25 } // anonymous namespace
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 void SiteEngagementHelper::MediaTracker::WasShown() { 150 void SiteEngagementHelper::MediaTracker::WasShown() {
151 is_hidden_ = false; 151 is_hidden_ = false;
152 } 152 }
153 153
154 void SiteEngagementHelper::MediaTracker::WasHidden() { 154 void SiteEngagementHelper::MediaTracker::WasHidden() {
155 is_hidden_ = true; 155 is_hidden_ = true;
156 } 156 }
157 157
158 SiteEngagementHelper::~SiteEngagementHelper() { 158 SiteEngagementHelper::~SiteEngagementHelper() {
159 content::WebContents* contents = web_contents(); 159 if (web_contents()) {
160 if (contents) {
161 input_tracker_.Stop(); 160 input_tracker_.Stop();
162 media_tracker_.Stop(); 161 media_tracker_.Stop();
163 } 162 }
164 } 163 }
165 164
166 SiteEngagementHelper::SiteEngagementHelper(content::WebContents* web_contents) 165 SiteEngagementHelper::SiteEngagementHelper(content::WebContents* web_contents)
167 : content::WebContentsObserver(web_contents), 166 : content::WebContentsObserver(web_contents),
168 input_tracker_(this, web_contents), 167 input_tracker_(this, web_contents),
169 media_tracker_(this, web_contents), 168 media_tracker_(this, web_contents),
170 record_engagement_(false) {} 169 record_engagement_(false) {}
(...skipping 20 matching lines...) Expand all
191 Profile* profile = 190 Profile* profile =
192 Profile::FromBrowserContext(contents->GetBrowserContext()); 191 Profile::FromBrowserContext(contents->GetBrowserContext());
193 SiteEngagementService* service = 192 SiteEngagementService* service =
194 SiteEngagementServiceFactory::GetForProfile(profile); 193 SiteEngagementServiceFactory::GetForProfile(profile);
195 194
196 if (service) 195 if (service)
197 service->HandleMediaPlaying(contents->GetVisibleURL(), is_hidden); 196 service->HandleMediaPlaying(contents->GetVisibleURL(), is_hidden);
198 } 197 }
199 } 198 }
200 199
201 void SiteEngagementHelper::DidNavigateMainFrame( 200 void SiteEngagementHelper::DidFinishNavigation(
202 const content::LoadCommittedDetails& details, 201 content::NavigationHandle* handle) {
203 const content::FrameNavigateParams& params) {
204 // Ignore in-page navigations. However, do not stop input or media detection.
205 if (details.is_in_page)
206 return;
207
208 input_tracker_.Stop(); 202 input_tracker_.Stop();
209 media_tracker_.Stop(); 203 media_tracker_.Stop();
210 record_engagement_ = params.url.SchemeIsHTTPOrHTTPS();
211 204
212 // Ignore all schemes except HTTP and HTTPS. 205 // Ignore all schemes except HTTP and HTTPS, as well as uncommitted, non
213 if (!record_engagement_) 206 // main-frame, same page, or error page navigations.
207 record_engagement_ = handle->GetURL().SchemeIsHTTPOrHTTPS();
208 if (!handle->HasCommitted() || !handle->IsInMainFrame() ||
209 handle->IsSamePage() || handle->IsErrorPage() || !record_engagement_) {
calamity 2016/05/12 07:58:14 What are considered to be same pages and error pag
dominickn 2016/05/12 08:03:06 - Same page navigations are things like fragment n
214 return; 210 return;
211 }
215 212
216 // Ignore prerender loads. This means that prerenders will not receive 213 // Ignore prerender loads. This means that prerenders will not receive
217 // navigation engagement. The implications are as follows: 214 // navigation engagement. The implications are as follows:
218 // 215 //
219 // - Instant search prerenders from the omnibox trigger DidNavigateMainFrame 216 // - Instant search prerenders from the omnibox trigger DidFinishNavigation
220 // twice: once for the prerender, and again when the page swaps in. The 217 // twice: once for the prerender, and again when the page swaps in. The
221 // second trigger has transition GENERATED and receives navigation 218 // second trigger has transition GENERATED and receives navigation
222 // engagement. 219 // engagement.
223 // - Prerenders initiated by <link rel="prerender"> (e.g. search results) are 220 // - Prerenders initiated by <link rel="prerender"> (e.g. search results) are
224 // always assigned the LINK transition, which is ignored for navigation 221 // always assigned the LINK transition, which is ignored for navigation
225 // engagement. 222 // engagement.
226 // 223 //
227 // Prerenders trigger WasShown() when they are swapped in, so input engagement 224 // Prerenders trigger WasShown() when they are swapped in, so input engagement
228 // will activate even if navigation engagement is not scored. 225 // will activate even if navigation engagement is not scored.
229 if (prerender::PrerenderContents::FromWebContents(web_contents()) != nullptr) 226 if (prerender::PrerenderContents::FromWebContents(web_contents()) != nullptr)
230 return; 227 return;
231 228
232 Profile* profile = 229 Profile* profile =
233 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 230 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
234 SiteEngagementService* service = 231 SiteEngagementService* service =
235 SiteEngagementServiceFactory::GetForProfile(profile); 232 SiteEngagementServiceFactory::GetForProfile(profile);
236 233
237 if (service) 234 if (service)
238 service->HandleNavigation(params.url, params.transition); 235 service->HandleNavigation(handle->GetURL(), handle->GetPageTransition());
239 236
240 input_tracker_.Start( 237 input_tracker_.Start(
241 base::TimeDelta::FromSeconds(g_seconds_delay_after_navigation)); 238 base::TimeDelta::FromSeconds(g_seconds_delay_after_navigation));
242 } 239 }
243 240
244 void SiteEngagementHelper::WasShown() { 241 void SiteEngagementHelper::WasShown() {
245 // Ensure that the input callbacks are registered when we come into view. 242 // Ensure that the input callbacks are registered when we come into view. This
243 // occurs when switching tabs, or when prerendered pages are swapped in.
246 if (record_engagement_) { 244 if (record_engagement_) {
247 input_tracker_.Start( 245 input_tracker_.Start(
248 base::TimeDelta::FromSeconds(g_seconds_delay_after_show)); 246 base::TimeDelta::FromSeconds(g_seconds_delay_after_show));
249 } 247 }
250 } 248 }
251 249
252 void SiteEngagementHelper::WasHidden() { 250 void SiteEngagementHelper::WasHidden() {
253 // Ensure that the input callbacks are not registered when hidden. 251 // Ensure that the input callbacks are not registered when hidden.
254 input_tracker_.Stop(); 252 input_tracker_.Stop();
255 } 253 }
256 254
257 // static 255 // static
258 void SiteEngagementHelper::SetSecondsBetweenUserInputCheck(int seconds) { 256 void SiteEngagementHelper::SetSecondsBetweenUserInputCheck(int seconds) {
259 g_seconds_to_pause_engagement_detection = seconds; 257 g_seconds_to_pause_engagement_detection = seconds;
260 } 258 }
261 259
262 // static 260 // static
263 void SiteEngagementHelper::SetSecondsTrackingDelayAfterNavigation(int seconds) { 261 void SiteEngagementHelper::SetSecondsTrackingDelayAfterNavigation(int seconds) {
264 g_seconds_delay_after_navigation = seconds; 262 g_seconds_delay_after_navigation = seconds;
265 } 263 }
266 264
267 // static 265 // static
268 void SiteEngagementHelper::SetSecondsTrackingDelayAfterShow(int seconds) { 266 void SiteEngagementHelper::SetSecondsTrackingDelayAfterShow(int seconds) {
269 g_seconds_delay_after_show = seconds; 267 g_seconds_delay_after_show = seconds;
270 } 268 }
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698