| OLD | NEW |
| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "chrome/browser/engagement/site_engagement_service.h" | 13 #include "chrome/browser/engagement/site_engagement_service.h" |
| 14 #include "chrome/browser/prerender/prerender_contents.h" | 14 #include "chrome/browser/prerender/prerender_contents.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/public/browser/navigation_handle.h" | 16 #include "content/public/browser/navigation_handle.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/associated_interface_provider.h" | 19 #include "content/public/common/associated_interface_provider.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 #include "url/origin.h" | 21 #include "url/origin.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 int g_seconds_to_pause_engagement_detection = 10; | 25 int g_seconds_to_pause_engagement_detection = 10; |
| 26 int g_seconds_delay_after_navigation = 10; |
| 26 int g_seconds_delay_after_media_starts = 10; | 27 int g_seconds_delay_after_media_starts = 10; |
| 27 int g_seconds_delay_after_show = 5; | 28 int g_seconds_delay_after_show = 5; |
| 28 | 29 |
| 29 } // anonymous namespace | 30 } // anonymous namespace |
| 30 | 31 |
| 31 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SiteEngagementService::Helper); | 32 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SiteEngagementService::Helper); |
| 32 | 33 |
| 33 // static | 34 // static |
| 34 void SiteEngagementService::Helper::SetSecondsBetweenUserInputCheck( | 35 void SiteEngagementService::Helper::SetSecondsBetweenUserInputCheck( |
| 35 int seconds) { | 36 int seconds) { |
| 36 g_seconds_to_pause_engagement_detection = seconds; | 37 g_seconds_to_pause_engagement_detection = seconds; |
| 37 } | 38 } |
| 38 | 39 |
| 39 // static | 40 // static |
| 41 void SiteEngagementService::Helper::SetSecondsTrackingDelayAfterNavigation( |
| 42 int seconds) { |
| 43 g_seconds_delay_after_navigation = seconds; |
| 44 } |
| 45 |
| 46 // static |
| 40 void SiteEngagementService::Helper::SetSecondsTrackingDelayAfterShow( | 47 void SiteEngagementService::Helper::SetSecondsTrackingDelayAfterShow( |
| 41 int seconds) { | 48 int seconds) { |
| 42 g_seconds_delay_after_show = seconds; | 49 g_seconds_delay_after_show = seconds; |
| 43 } | 50 } |
| 44 | 51 |
| 45 SiteEngagementService::Helper::~Helper() { | 52 SiteEngagementService::Helper::~Helper() { |
| 46 service_->HelperDeleted(this); | 53 service_->HelperDeleted(this); |
| 47 if (web_contents()) { | 54 if (web_contents()) { |
| 48 input_tracker_.Stop(); | 55 input_tracker_.Stop(); |
| 49 media_tracker_.Stop(); | 56 media_tracker_.Stop(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // always assigned the LINK transition, which is ignored for navigation | 260 // always assigned the LINK transition, which is ignored for navigation |
| 254 // engagement. | 261 // engagement. |
| 255 // | 262 // |
| 256 // Prerenders trigger WasShown() when they are swapped in, so input engagement | 263 // Prerenders trigger WasShown() when they are swapped in, so input engagement |
| 257 // will activate even if navigation engagement is not scored. | 264 // will activate even if navigation engagement is not scored. |
| 258 if (prerender::PrerenderContents::FromWebContents(web_contents()) != nullptr) | 265 if (prerender::PrerenderContents::FromWebContents(web_contents()) != nullptr) |
| 259 return; | 266 return; |
| 260 | 267 |
| 261 service_->HandleNavigation(web_contents(), handle->GetPageTransition()); | 268 service_->HandleNavigation(web_contents(), handle->GetPageTransition()); |
| 262 | 269 |
| 263 input_tracker_.Start(base::TimeDelta::FromSeconds(0)); | 270 input_tracker_.Start( |
| 271 base::TimeDelta::FromSeconds(g_seconds_delay_after_navigation)); |
| 264 } | 272 } |
| 265 | 273 |
| 266 void SiteEngagementService::Helper::ReadyToCommitNavigation( | 274 void SiteEngagementService::Helper::ReadyToCommitNavigation( |
| 267 content::NavigationHandle* handle) { | 275 content::NavigationHandle* handle) { |
| 268 if (service_->ShouldRecordEngagement(handle->GetURL())) { | 276 if (service_->ShouldRecordEngagement(handle->GetURL())) { |
| 269 // Don't bother sending the engagement if we wouldn't have recorded any for | 277 // Don't bother sending the engagement if we wouldn't have recorded any for |
| 270 // the URL. These will have NONE engagement by default. | 278 // the URL. These will have NONE engagement by default. |
| 271 SendEngagementLevelToFrame(url::Origin(handle->GetURL()), | 279 SendEngagementLevelToFrame(url::Origin(handle->GetURL()), |
| 272 service_->GetEngagementLevel(handle->GetURL()), | 280 service_->GetEngagementLevel(handle->GetURL()), |
| 273 handle->GetRenderFrameHost()); | 281 handle->GetRenderFrameHost()); |
| 274 } | 282 } |
| 275 } | 283 } |
| 276 | 284 |
| 277 void SiteEngagementService::Helper::WasShown() { | 285 void SiteEngagementService::Helper::WasShown() { |
| 278 // Ensure that the input callbacks are registered when we come into view. | 286 // Ensure that the input callbacks are registered when we come into view. |
| 279 input_tracker_.Start( | 287 input_tracker_.Start( |
| 280 base::TimeDelta::FromSeconds(g_seconds_delay_after_show)); | 288 base::TimeDelta::FromSeconds(g_seconds_delay_after_show)); |
| 281 } | 289 } |
| 282 | 290 |
| 283 void SiteEngagementService::Helper::WasHidden() { | 291 void SiteEngagementService::Helper::WasHidden() { |
| 284 // Ensure that the input callbacks are not registered when hidden. | 292 // Ensure that the input callbacks are not registered when hidden. |
| 285 input_tracker_.Stop(); | 293 input_tracker_.Stop(); |
| 286 } | 294 } |
| OLD | NEW |