| 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..2bd3614fdd00c1fc78b4e904943d5f2ee97312f6 100644
|
| --- a/chrome/browser/engagement/site_engagement_service.cc
|
| +++ b/chrome/browser/engagement/site_engagement_service.cc
|
| @@ -12,6 +12,7 @@
|
| #include "base/values.h"
|
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
| #include "chrome/browser/engagement/site_engagement_helper.h"
|
| +#include "chrome/browser/engagement/site_engagement_metrics.h"
|
| #include "chrome/browser/engagement/site_engagement_service_factory.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "components/content_settings/core/browser/host_content_settings_map.h"
|
| @@ -102,6 +103,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 +173,7 @@ bool SiteEngagementService::IsEnabled() {
|
|
|
| SiteEngagementService::SiteEngagementService(Profile* profile)
|
| : profile_(profile) {
|
| + RecordStartupUmaStats();
|
| }
|
|
|
| SiteEngagementService::~SiteEngagementService() {
|
| @@ -188,22 +199,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;
|
| }
|
|
|
| @@ -245,4 +246,63 @@ 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.
|
| + if (score.MaxPointsPerDayAdded()) {
|
| + 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.
|
| + if (score.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();
|
| +
|
| + 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);
|
| }
|
|
|