Chromium Code Reviews| Index: chrome/browser/engagement/site_engagement_service.cc |
| diff --git a/chrome/browser/engagement/site_engagement_service.cc b/chrome/browser/engagement/site_engagement_service.cc |
| index 5f0e2fc915717ca337c1793058497b30c62f07ed..3e8efce1907ce8d0fdcb6aa10d6cda1ebbc1fe9f 100644 |
| --- a/chrome/browser/engagement/site_engagement_service.cc |
| +++ b/chrome/browser/engagement/site_engagement_service.cc |
| @@ -102,6 +102,15 @@ void SiteEngagementScore::AddPoints(double points) { |
| last_engagement_time_ = now; |
| } |
| +bool SiteEngagementScore::MaxPointsPerDayAdded() { |
| + if (!last_engagement_time_.is_null() && |
| + clock_->Now().LocalMidnight() != last_engagement_time_.LocalMidnight()) { |
| + points_added_today_ = 0; |
| + } |
| + |
| + return points_added_today_ == kMaxPointsPerDay; |
| +} |
| + |
| bool SiteEngagementScore::UpdateScoreDict(base::DictionaryValue* score_dict) { |
| double raw_score_orig = 0; |
| double points_added_today_orig = 0; |
| @@ -163,6 +172,7 @@ bool SiteEngagementService::IsEnabled() { |
| SiteEngagementService::SiteEngagementService(Profile* profile) |
| : profile_(profile) { |
| + RecordStartupUmaStats(); |
| } |
| SiteEngagementService::~SiteEngagementService() { |
| @@ -170,10 +180,15 @@ SiteEngagementService::~SiteEngagementService() { |
| void SiteEngagementService::HandleNavigation(const GURL& url, |
| ui::PageTransition transition) { |
| + SiteEngagementMetrics::RecordEngagement( |
| + SiteEngagementMetrics::ENGAGEMENT_NAVIGATION); |
| AddPoints(url, SiteEngagementScore::kNavigationPoints); |
| } |
| -void SiteEngagementService::HandleUserInput(const GURL& url) { |
| +void SiteEngagementService::HandleUserInput( |
| + const GURL& url, |
| + SiteEngagementMetrics::EngagementType type) { |
| + SiteEngagementMetrics::RecordEngagement(type); |
| AddPoints(url, SiteEngagementScore::kUserInputPoints); |
| } |
| @@ -188,22 +203,12 @@ double SiteEngagementService::GetScore(const GURL& url) { |
| } |
| double SiteEngagementService::GetTotalEngagementPoints() { |
| - HostContentSettingsMap* settings_map = |
| - HostContentSettingsMapFactory::GetForProfile(profile_); |
| - ContentSettingsForOneType engagement_settings; |
| - settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| - std::string(), &engagement_settings); |
| + std::map<GURL, double> score_map = GetScoreMap(); |
| + |
| double total_score = 0; |
| - for (const auto& site : engagement_settings) { |
| - GURL origin(site.primary_pattern.ToString()); |
| - if (!origin.is_valid()) |
| - continue; |
| + for (const auto& value : score_map) |
| + total_score += value.second; |
| - scoped_ptr<base::DictionaryValue> score_dict = |
| - GetScoreDictForOrigin(settings_map, origin); |
| - SiteEngagementScore score(&clock_, *score_dict); |
| - total_score += score.Score(); |
| - } |
| return total_score; |
| } |
| @@ -234,6 +239,8 @@ void SiteEngagementService::AddPoints(const GURL& url, double points) { |
| GetScoreDictForOrigin(settings_map, url); |
| SiteEngagementScore score(&clock_, *score_dict); |
| + double old_score = score.Score(); |
| + |
| score.AddPoints(points); |
| if (score.UpdateScoreDict(score_dict.get())) { |
| ContentSettingsPattern pattern( |
| @@ -245,4 +252,66 @@ void SiteEngagementService::AddPoints(const GURL& url, double points) { |
| CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| std::string(), score_dict.release()); |
| } |
| + |
| + // If the origin has now received the maximum number of points it can today, |
| + // record a UMA statistic of all of the origins with maxed daily engagement. |
| + // As this is recorded each time an origin reaches the maximum, a client with |
| + // N maxed origins will have recorded a statistic for 1, 2, ..., N-1, N. |
| + if (score.MaxPointsPerDayAdded()) { |
|
calamity
2015/09/29 04:21:09
Re-record issue also exists here I believe.
dominickn
2015/09/29 07:06:19
Acknowledged.
|
| + SiteEngagementMetrics::RecordOriginsWithMaxDailyEngagement( |
| + OriginsWithMaxDailyEngagement()); |
| + } |
| + |
| + // If the origin has now received the maximum total number of points, |
| + // record a UMA statistic of all of the origins with maximum total points. |
| + double new_score = score.Score(); |
| + if (old_score != new_score && new_score == SiteEngagementScore::kMaxPoints) { |
| + SiteEngagementMetrics::RecordOriginsWithMaxEngagement( |
| + OriginsWithMaxEngagement()); |
| + } |
| +} |
| + |
| +int SiteEngagementService::OriginsWithMaxDailyEngagement() { |
| + HostContentSettingsMap* settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(profile_); |
| + ContentSettingsForOneType engagement_settings; |
| + settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| + std::string(), &engagement_settings); |
| + int total_origins = 0; |
| + for (const auto& site : engagement_settings) { |
| + GURL origin(site.primary_pattern.ToString()); |
| + if (!origin.is_valid()) |
| + continue; |
| + |
| + scoped_ptr<base::DictionaryValue> score_dict = |
| + GetScoreDictForOrigin(settings_map, origin); |
| + SiteEngagementScore score(&clock_, *score_dict); |
| + if (score.MaxPointsPerDayAdded()) |
| + total_origins += 1; |
| + } |
| + |
| + return total_origins; |
| +} |
| + |
| +int SiteEngagementService::OriginsWithMaxEngagement() { |
| + std::map<GURL, double> score_map = GetScoreMap(); |
| + int total_origins = 0; |
| + |
| + for (const auto& value : score_map) |
| + if (value.second == SiteEngagementScore::kMaxPoints) |
| + ++total_origins; |
| + |
| + return total_origins; |
| +} |
| + |
| +void SiteEngagementService::RecordStartupUmaStats() { |
| + std::map<GURL, double> score_map = GetScoreMap(); |
|
calamity
2015/09/29 04:21:09
Just NB that this should be run after the cleanup
dominickn
2015/09/29 07:06:19
Acknowledged.
|
| + |
| + double total_score = 0; |
| + for (const auto& value : score_map) |
| + total_score += value.second; |
| + |
| + SiteEngagementMetrics::RecordTotalOriginsEngaged(score_map.size()); |
| + SiteEngagementMetrics::RecordTotalSiteEngagement(total_score); |
| + SiteEngagementMetrics::RecordEngagementByOrigin(score_map); |
| } |