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

Side by Side Diff: chrome/browser/engagement/site_engagement_score.cc

Issue 1986033002: Implement an observer interface for the site engagement service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@site-engagement-refactor
Patch Set: Address comments Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_score.h" 5 #include "chrome/browser/engagement/site_engagement_score.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/time/clock.h" 10 #include "base/time/clock.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/engagement/site_engagement_metrics.h" 13 #include "chrome/browser/engagement/site_engagement_metrics.h"
14 #include "components/variations/variations_associated_data.h" 14 #include "components/variations/variations_associated_data.h"
15 15
16 namespace { 16 namespace {
17 17
18 // The smallest amount by which engagement is incremented. Updated if necessary
19 // in SiteEngagementScore::UpdateFromVariations.
20 double gMinimumEngagementIncrement = 0.01;
21
18 // Delta within which to consider scores equal. 22 // Delta within which to consider scores equal.
19 const double kScoreDelta = 0.001; 23 const double kScoreDelta = 0.001;
20 24
21 // Delta within which to consider internal time values equal. Internal time 25 // Delta within which to consider internal time values equal. Internal time
22 // values are in microseconds, so this delta comes out at one second. 26 // values are in microseconds, so this delta comes out at one second.
23 const double kTimeDelta = 1000000; 27 const double kTimeDelta = 1000000;
24 28
25 // Number of days after the last launch of an origin from an installed shortcut 29 // Number of days after the last launch of an origin from an installed shortcut
26 // for which WEB_APP_INSTALLED_POINTS will be added to the engagement score. 30 // for which WEB_APP_INSTALLED_POINTS will be added to the engagement score.
27 const int kMaxDaysSinceShortcutLaunch = 10; 31 const int kMaxDaysSinceShortcutLaunch = 10;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 116 }
113 117
114 double SiteEngagementScore::GetMediumEngagementBoundary() { 118 double SiteEngagementScore::GetMediumEngagementBoundary() {
115 return param_values[MEDIUM_ENGAGEMENT_BOUNDARY]; 119 return param_values[MEDIUM_ENGAGEMENT_BOUNDARY];
116 } 120 }
117 121
118 double SiteEngagementScore::GetHighEngagementBoundary() { 122 double SiteEngagementScore::GetHighEngagementBoundary() {
119 return param_values[HIGH_ENGAGEMENT_BOUNDARY]; 123 return param_values[HIGH_ENGAGEMENT_BOUNDARY];
120 } 124 }
121 125
126 double SiteEngagementScore::GetMinimumEngagementIncrement() {
127 return gMinimumEngagementIncrement;
128 }
129
122 // static 130 // static
123 void SiteEngagementScore::UpdateFromVariations(const char* param_name) { 131 void SiteEngagementScore::UpdateFromVariations(const char* param_name) {
124 double param_vals[MAX_VARIATION]; 132 double param_vals[MAX_VARIATION];
125 133
126 for (int i = 0; i < MAX_VARIATION; ++i) { 134 for (int i = 0; i < MAX_VARIATION; ++i) {
127 std::string param_string = 135 std::string param_string =
128 variations::GetVariationParamValue(param_name, kVariationNames[i]); 136 variations::GetVariationParamValue(param_name, kVariationNames[i]);
129 137
130 // Bail out if we didn't get a param string for the key, or if we couldn't 138 // Bail out if we didn't get a param string for the key, or if we couldn't
131 // convert the param string to a double, or if we get a negative value. 139 // convert the param string to a double, or if we get a negative value.
132 if (param_string.empty() || 140 if (param_string.empty() ||
133 !base::StringToDouble(param_string, &param_vals[i]) || 141 !base::StringToDouble(param_string, &param_vals[i]) ||
134 param_vals[i] < 0) { 142 param_vals[i] < 0) {
135 return; 143 return;
136 } 144 }
137 } 145 }
138 146
139 // Once we're sure everything is valid, assign the variation to the param 147 // Once we're sure everything is valid, assign the variation to the param
140 // values array. 148 // values array. Update the minimum engagement increment if it has changed.
141 for (int i = 0; i < MAX_VARIATION; ++i) 149 for (int i = 0; i < MAX_VARIATION; ++i) {
142 SiteEngagementScore::param_values[i] = param_vals[i]; 150 SiteEngagementScore::param_values[i] = param_vals[i];
151
152 // If the value is one used to increment the site engagement score, update
153 // the minimum engagement increment if necessary.
154 if (i >= POINTS_INCREMENT_FIRST && i <= POINTS_INCREMENT_LAST &&
155 param_vals[i] < gMinimumEngagementIncrement) {
156 gMinimumEngagementIncrement = param_vals[i];
157 }
158 }
143 } 159 }
144 160
145 SiteEngagementScore::SiteEngagementScore(base::Clock* clock, 161 SiteEngagementScore::SiteEngagementScore(base::Clock* clock,
146 const base::DictionaryValue& score_dict) 162 const base::DictionaryValue& score_dict)
147 : SiteEngagementScore(clock) { 163 : SiteEngagementScore(clock) {
148 score_dict.GetDouble(kRawScoreKey, &raw_score_); 164 score_dict.GetDouble(kRawScoreKey, &raw_score_);
149 score_dict.GetDouble(kPointsAddedTodayKey, &points_added_today_); 165 score_dict.GetDouble(kPointsAddedTodayKey, &points_added_today_);
150 166
151 double internal_time; 167 double internal_time;
152 if (score_dict.GetDouble(kLastEngagementTimeKey, &internal_time)) 168 if (score_dict.GetDouble(kLastEngagementTimeKey, &internal_time))
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 param_values[HIDDEN_MEDIA_POINTS] = 0.01; 312 param_values[HIDDEN_MEDIA_POINTS] = 0.01;
297 param_values[WEB_APP_INSTALLED_POINTS] = 5; 313 param_values[WEB_APP_INSTALLED_POINTS] = 5;
298 param_values[BOOTSTRAP_POINTS] = 8; 314 param_values[BOOTSTRAP_POINTS] = 8;
299 param_values[MEDIUM_ENGAGEMENT_BOUNDARY] = 5; 315 param_values[MEDIUM_ENGAGEMENT_BOUNDARY] = 5;
300 param_values[HIGH_ENGAGEMENT_BOUNDARY] = 50; 316 param_values[HIGH_ENGAGEMENT_BOUNDARY] = 50;
301 317
302 // This is set to zero to avoid interference with tests and is set when 318 // This is set to zero to avoid interference with tests and is set when
303 // testing this functionality. 319 // testing this functionality.
304 param_values[FIRST_DAILY_ENGAGEMENT] = 0; 320 param_values[FIRST_DAILY_ENGAGEMENT] = 0;
305 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698