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..12a9879123b851530a5a751d305e1a055cb77824 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()); |
calamity
2015/09/25 07:08:33
Hmm. It's kind of weird to log this each time a sc
dominickn
2015/09/28 03:34:50
I wanted to try and avoid the overhead of finding
calamity
2015/09/28 07:33:47
Ok, I'll defer to the histograms reviewer on this.
|
+ } |
+ |
+ // 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()); |
calamity
2015/09/25 07:08:33
Ditto.
dominickn
2015/09/28 03:34:50
Acknowledged.
|
+ } |
+} |
+ |
+int SiteEngagementService::OriginsWithMaxDailyEngagement() { |
+ HostContentSettingsMap* settings_map = |
+ HostContentSettingsMapFactory::GetForProfile(profile_); |
+ ContentSettingsForOneType engagement_settings; |
+ settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
+ std::string(), &engagement_settings); |
calamity
2015/09/25 07:08:33
Worth factoring out a GetSiteEngagementSettings at
dominickn
2015/09/28 03:34:50
I see you've done it in your cleanup CL: I'll wait
calamity
2015/09/28 07:33:47
But that's based on your time on site stuff! Ugh,
|
+ 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::RecordTotalCumulativeSiteEngagement(total_score); |
+ SiteEngagementMetrics::RecordEngagementPerOrigin(score_map); |
} |