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

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

Issue 2352263002: Allow incomplete params for site engagement configs. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 double SiteEngagementScore::GetMaxDecaysPerScore() { 150 double SiteEngagementScore::GetMaxDecaysPerScore() {
151 return GetParamValues()[MAX_DECAYS_PER_SCORE].second; 151 return GetParamValues()[MAX_DECAYS_PER_SCORE].second;
152 } 152 }
153 153
154 double SiteEngagementScore::GetLastEngagementGracePeriodInHours() { 154 double SiteEngagementScore::GetLastEngagementGracePeriodInHours() {
155 return GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second; 155 return GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second;
156 } 156 }
157 157
158 // static 158 // static
159 void SiteEngagementScore::UpdateFromVariations(const char* param_name) { 159 void SiteEngagementScore::UpdateFromVariations(const char* param_name) {
160 double param_vals[MAX_VARIATION];
161
162 for (int i = 0; i < MAX_VARIATION; ++i) { 160 for (int i = 0; i < MAX_VARIATION; ++i) {
161 double param;
163 std::string param_string = variations::GetVariationParamValue( 162 std::string param_string = variations::GetVariationParamValue(
164 param_name, GetParamValues()[i].first); 163 param_name, GetParamValues()[i].first);
165 164
166 // Bail out if we didn't get a param string for the key, or if we couldn't 165 // Bail out if we didn't get a param string for the key, or if we couldn't
167 // convert the param string to a double, or if we get a negative value. 166 // convert the param string to a double, or if we get a negative value.
168 if (param_string.empty() || 167 if (param_string.empty() ||
169 !base::StringToDouble(param_string, &param_vals[i]) || 168 !base::StringToDouble(param_string, &param) ||
170 param_vals[i] < 0) { 169 param < 0) {
171 return; 170 continue;
172 } 171 }
172
173 SiteEngagementScore::GetParamValues()[i].second = param;
173 } 174 }
174
175 // Once we're sure everything is valid, assign the variation to the param
176 // values array.
177 for (int i = 0; i < MAX_VARIATION; ++i)
178 SiteEngagementScore::GetParamValues()[i].second = param_vals[i];
179 } 175 }
180 176
181 SiteEngagementScore::SiteEngagementScore( 177 SiteEngagementScore::SiteEngagementScore(
182 base::Clock* clock, 178 base::Clock* clock,
183 const GURL& origin, 179 const GURL& origin,
184 HostContentSettingsMap* settings) 180 HostContentSettingsMap* settings)
185 : SiteEngagementScore( 181 : SiteEngagementScore(
186 clock, 182 clock,
187 origin, 183 origin,
188 GetScoreDictForSettings(settings, origin)) { 184 GetScoreDictForSettings(settings, origin)) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 GetParamValues()[HIGH_ENGAGEMENT_BOUNDARY].second = 50; 359 GetParamValues()[HIGH_ENGAGEMENT_BOUNDARY].second = 50;
364 GetParamValues()[MAX_DECAYS_PER_SCORE].second = 1; 360 GetParamValues()[MAX_DECAYS_PER_SCORE].second = 1;
365 GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second = 72; 361 GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second = 72;
366 362
367 // This is set to values that avoid interference with tests and are set when 363 // This is set to values that avoid interference with tests and are set when
368 // testing these features. 364 // testing these features.
369 GetParamValues()[FIRST_DAILY_ENGAGEMENT].second = 0; 365 GetParamValues()[FIRST_DAILY_ENGAGEMENT].second = 0;
370 GetParamValues()[DECAY_PROPORTION].second = 1; 366 GetParamValues()[DECAY_PROPORTION].second = 1;
371 GetParamValues()[SCORE_CLEANUP_THRESHOLD].second = 0; 367 GetParamValues()[SCORE_CLEANUP_THRESHOLD].second = 0;
372 } 368 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698