Chromium Code Reviews| 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_service.h" | 5 #include "chrome/browser/engagement/site_engagement_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/engagement/site_engagement_eviction_policy.h" | 23 #include "chrome/browser/engagement/site_engagement_eviction_policy.h" |
| 24 #include "chrome/browser/engagement/site_engagement_metrics.h" | 24 #include "chrome/browser/engagement/site_engagement_metrics.h" |
| 25 #include "chrome/browser/engagement/site_engagement_score.h" | 25 #include "chrome/browser/engagement/site_engagement_score.h" |
| 26 #include "chrome/browser/engagement/site_engagement_service_factory.h" | 26 #include "chrome/browser/engagement/site_engagement_service_factory.h" |
| 27 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "components/content_settings/core/browser/host_content_settings_map.h" | 29 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 30 #include "components/content_settings/core/common/content_settings_pattern.h" | 30 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 31 #include "components/history/core/browser/history_service.h" | 31 #include "components/history/core/browser/history_service.h" |
| 32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/web_contents.h" | |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 const int FOUR_WEEKS_IN_DAYS = 28; | 38 const int FOUR_WEEKS_IN_DAYS = 28; |
| 38 | 39 |
| 39 // Global bool to ensure we only update the parameters from variations once. | 40 // Global bool to ensure we only update the parameters from variations once. |
| 40 bool g_updated_from_variations = false; | 41 bool g_updated_from_variations = false; |
| 41 | 42 |
| 42 // Length of time between metrics logging. | 43 // Length of time between metrics logging. |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 // if there are an odd number of scores, or the average of the two middle | 313 // if there are an odd number of scores, or the average of the two middle |
| 313 // scores otherwise. | 314 // scores otherwise. |
| 314 std::sort(scores.begin(), scores.end()); | 315 std::sort(scores.begin(), scores.end()); |
| 315 size_t mid = scores.size() / 2; | 316 size_t mid = scores.size() / 2; |
| 316 if (scores.size() % 2 == 1) | 317 if (scores.size() % 2 == 1) |
| 317 return scores[mid]; | 318 return scores[mid]; |
| 318 else | 319 else |
| 319 return (scores[mid - 1] + scores[mid]) / 2; | 320 return (scores[mid - 1] + scores[mid]) / 2; |
| 320 } | 321 } |
| 321 | 322 |
| 322 void SiteEngagementService::HandleMediaPlaying(const GURL& url, | 323 void SiteEngagementService::HandleMediaPlaying( |
| 323 bool is_hidden) { | 324 content::WebContents* web_contents, bool is_hidden) { |
| 324 SiteEngagementMetrics::RecordEngagement( | 325 SiteEngagementMetrics::RecordEngagement( |
| 325 is_hidden ? SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN | 326 is_hidden ? SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN |
| 326 : SiteEngagementMetrics::ENGAGEMENT_MEDIA_VISIBLE); | 327 : SiteEngagementMetrics::ENGAGEMENT_MEDIA_VISIBLE); |
| 327 AddPoints(url, is_hidden ? SiteEngagementScore::GetHiddenMediaPoints() | 328 AddPoints(web_contents->GetVisibleURL(), |
| 328 : SiteEngagementScore::GetVisibleMediaPoints()); | 329 is_hidden ? SiteEngagementScore::GetHiddenMediaPoints() |
| 330 : SiteEngagementScore::GetVisibleMediaPoints()); | |
| 329 RecordMetrics(); | 331 RecordMetrics(); |
| 330 } | 332 } |
| 331 | 333 |
| 332 void SiteEngagementService::HandleNavigation(const GURL& url, | 334 void SiteEngagementService::HandleNavigation(content::WebContents* web_contents, |
| 333 ui::PageTransition transition) { | 335 ui::PageTransition transition) { |
| 334 if (IsEngagementNavigation(transition)) { | 336 if (IsEngagementNavigation(transition)) { |
| 335 SiteEngagementMetrics::RecordEngagement( | 337 SiteEngagementMetrics::RecordEngagement( |
| 336 SiteEngagementMetrics::ENGAGEMENT_NAVIGATION); | 338 SiteEngagementMetrics::ENGAGEMENT_NAVIGATION); |
| 337 AddPoints(url, SiteEngagementScore::GetNavigationPoints()); | 339 AddPoints(web_contents->GetLastCommittedURL(), |
|
calamity
2016/06/09 03:32:20
Why not visible here? Is this going to be the same
dominickn
2016/06/09 03:45:57
The existing behaviour has the helper sending the
calamity
2016/06/09 03:48:06
Acknowledged.
| |
| 340 SiteEngagementScore::GetNavigationPoints()); | |
| 338 RecordMetrics(); | 341 RecordMetrics(); |
| 339 } | 342 } |
| 340 } | 343 } |
| 341 | 344 |
| 342 void SiteEngagementService::HandleUserInput( | 345 void SiteEngagementService::HandleUserInput( |
| 343 const GURL& url, | 346 content::WebContents* web_contents, |
| 344 SiteEngagementMetrics::EngagementType type) { | 347 SiteEngagementMetrics::EngagementType type) { |
| 345 SiteEngagementMetrics::RecordEngagement(type); | 348 SiteEngagementMetrics::RecordEngagement(type); |
| 346 AddPoints(url, SiteEngagementScore::GetUserInputPoints()); | 349 AddPoints(web_contents->GetVisibleURL(), |
| 350 SiteEngagementScore::GetUserInputPoints()); | |
| 347 RecordMetrics(); | 351 RecordMetrics(); |
| 348 } | 352 } |
| 349 | 353 |
| 350 void SiteEngagementService::OnURLsDeleted( | 354 void SiteEngagementService::OnURLsDeleted( |
| 351 history::HistoryService* history_service, | 355 history::HistoryService* history_service, |
| 352 bool all_history, | 356 bool all_history, |
| 353 bool expired, | 357 bool expired, |
| 354 const history::URLRows& deleted_rows, | 358 const history::URLRows& deleted_rows, |
| 355 const std::set<GURL>& favicon_urls) { | 359 const std::set<GURL>& favicon_urls) { |
| 356 std::multiset<GURL> origins; | 360 std::multiset<GURL> origins; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 (proportion_remaining * engagement_score.GetScore()) + undecay); | 477 (proportion_remaining * engagement_score.GetScore()) + undecay); |
| 474 engagement_score.Reset(score, last_visit); | 478 engagement_score.Reset(score, last_visit); |
| 475 if (!engagement_score.last_shortcut_launch_time().is_null() | 479 if (!engagement_score.last_shortcut_launch_time().is_null() |
| 476 && engagement_score.last_shortcut_launch_time() > last_visit) { | 480 && engagement_score.last_shortcut_launch_time() > last_visit) { |
| 477 engagement_score.set_last_shortcut_launch_time(last_visit); | 481 engagement_score.set_last_shortcut_launch_time(last_visit); |
| 478 } | 482 } |
| 479 | 483 |
| 480 engagement_score.Commit(); | 484 engagement_score.Commit(); |
| 481 } | 485 } |
| 482 } | 486 } |
| OLD | NEW |