Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Unified Diff: chrome/browser/engagement/site_engagement_score.cc

Issue 2788413003: Add SiteEngagementService::GetAllDetails(), to return detailed scores. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/engagement/site_engagement_score.cc
diff --git a/chrome/browser/engagement/site_engagement_score.cc b/chrome/browser/engagement/site_engagement_score.cc
index 10fe452045ed6ec5b34dee916337b8735971a19e..fd89a301812b7584a99416893fdab25e097edad1 100644
--- a/chrome/browser/engagement/site_engagement_score.cc
+++ b/chrome/browser/engagement/site_engagement_score.cc
@@ -271,7 +271,20 @@ void SiteEngagementScore::AddPoints(double points) {
}
double SiteEngagementScore::GetScore() const {
- return std::min(DecayedScore() + BonusScore(), kMaxPoints);
+ return GetDetails().score;
+}
+
+mojom::SiteEngagementDetails SiteEngagementScore::GetDetails() const {
+ mojom::SiteEngagementDetails engagement;
+ engagement.origin = origin_;
+ engagement.base_score = DecayedScore();
+ engagement.installed_bonus = BonusIfShortcutLaunched();
+ engagement.notifications_bonus = BonusIfHasNotifications();
+ engagement.score =
+ std::min(engagement.base_score + engagement.installed_bonus +
+ engagement.notifications_bonus,
+ kMaxPoints);
+ return engagement;
}
void SiteEngagementScore::Commit() {
@@ -400,20 +413,22 @@ double SiteEngagementScore::DecayedScore() const {
periods * GetDecayPoints());
}
-double SiteEngagementScore::BonusScore() const {
- double bonus = 0;
+double SiteEngagementScore::BonusIfShortcutLaunched() const {
int days_since_shortcut_launch =
(clock_->Now() - last_shortcut_launch_time_).InDays();
if (days_since_shortcut_launch <= kMaxDaysSinceShortcutLaunch)
- bonus += GetWebAppInstalledPoints();
+ return GetWebAppInstalledPoints();
+ return 0;
+}
+double SiteEngagementScore::BonusIfHasNotifications() const {
// TODO(dominickn, raymes): call PermissionManager::GetPermissionStatus when
// the PermissionManager is thread-safe.
if (settings_map_ && settings_map_->GetContentSetting(
origin_, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
std::string()) == CONTENT_SETTING_ALLOW) {
- bonus += GetNotificationPermissionPoints();
+ return GetNotificationPermissionPoints();
}
- return bonus;
+ return 0;
}

Powered by Google App Engine
This is Rietveld 408576698