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