| OLD | NEW |
| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 "decay_period_in_days", | 35 "decay_period_in_days", |
| 36 "decay_points", | 36 "decay_points", |
| 37 "navigation_points", | 37 "navigation_points", |
| 38 "user_input_points", | 38 "user_input_points", |
| 39 "visible_media_playing_points", | 39 "visible_media_playing_points", |
| 40 "hidden_media_playing_points", | 40 "hidden_media_playing_points", |
| 41 "web_app_installed_points", | 41 "web_app_installed_points", |
| 42 "first_daily_engagement_points", | 42 "first_daily_engagement_points", |
| 43 "medium_engagement_boundary", | 43 "medium_engagement_boundary", |
| 44 "high_engagement_boundary", | 44 "high_engagement_boundary", |
| 45 "max_decays_per_score", |
| 46 "last_engagement_grace_period_in_hours", |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 bool DoublesConsideredDifferent(double value1, double value2, double delta) { | 49 bool DoublesConsideredDifferent(double value1, double value2, double delta) { |
| 48 double abs_difference = fabs(value1 - value2); | 50 double abs_difference = fabs(value1 - value2); |
| 49 return abs_difference > delta; | 51 return abs_difference > delta; |
| 50 } | 52 } |
| 51 | 53 |
| 52 std::unique_ptr<base::DictionaryValue> GetScoreDictForOrigin( | 54 std::unique_ptr<base::DictionaryValue> GetScoreDictForOrigin( |
| 53 HostContentSettingsMap* settings, | 55 HostContentSettingsMap* settings, |
| 54 const GURL& origin_url) { | 56 const GURL& origin_url) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 76 5, // DECAY_POINTS | 78 5, // DECAY_POINTS |
| 77 0.5, // NAVIGATION_POINTS | 79 0.5, // NAVIGATION_POINTS |
| 78 0.2, // USER_INPUT_POINTS | 80 0.2, // USER_INPUT_POINTS |
| 79 0.02, // VISIBLE_MEDIA_POINTS | 81 0.02, // VISIBLE_MEDIA_POINTS |
| 80 0.01, // HIDDEN_MEDIA_POINTS | 82 0.01, // HIDDEN_MEDIA_POINTS |
| 81 5, // WEB_APP_INSTALLED_POINTS | 83 5, // WEB_APP_INSTALLED_POINTS |
| 82 0.5, // FIRST_DAILY_ENGAGEMENT | 84 0.5, // FIRST_DAILY_ENGAGEMENT |
| 83 8, // BOOTSTRAP_POINTS | 85 8, // BOOTSTRAP_POINTS |
| 84 5, // MEDIUM_ENGAGEMENT_BOUNDARY | 86 5, // MEDIUM_ENGAGEMENT_BOUNDARY |
| 85 50, // HIGH_ENGAGEMENT_BOUNDARY | 87 50, // HIGH_ENGAGEMENT_BOUNDARY |
| 88 1, // MAX_DECAYS_PER_SCORE |
| 89 72, // LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS |
| 86 }; | 90 }; |
| 87 | 91 |
| 88 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; | 92 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; |
| 89 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; | 93 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; |
| 90 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; | 94 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; |
| 91 const char* SiteEngagementScore::kLastShortcutLaunchTimeKey = | 95 const char* SiteEngagementScore::kLastShortcutLaunchTimeKey = |
| 92 "lastShortcutLaunchTime"; | 96 "lastShortcutLaunchTime"; |
| 93 | 97 |
| 94 double SiteEngagementScore::GetMaxPointsPerDay() { | 98 double SiteEngagementScore::GetMaxPointsPerDay() { |
| 95 return param_values[MAX_POINTS_PER_DAY]; | 99 return param_values[MAX_POINTS_PER_DAY]; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 136 } |
| 133 | 137 |
| 134 double SiteEngagementScore::GetMediumEngagementBoundary() { | 138 double SiteEngagementScore::GetMediumEngagementBoundary() { |
| 135 return param_values[MEDIUM_ENGAGEMENT_BOUNDARY]; | 139 return param_values[MEDIUM_ENGAGEMENT_BOUNDARY]; |
| 136 } | 140 } |
| 137 | 141 |
| 138 double SiteEngagementScore::GetHighEngagementBoundary() { | 142 double SiteEngagementScore::GetHighEngagementBoundary() { |
| 139 return param_values[HIGH_ENGAGEMENT_BOUNDARY]; | 143 return param_values[HIGH_ENGAGEMENT_BOUNDARY]; |
| 140 } | 144 } |
| 141 | 145 |
| 146 double SiteEngagementScore::GetMaxDecaysPerScore() { |
| 147 return param_values[MAX_DECAYS_PER_SCORE]; |
| 148 } |
| 149 |
| 150 double SiteEngagementScore::GetLastEngagementGracePeriodInHours() { |
| 151 return param_values[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS]; |
| 152 } |
| 153 |
| 142 // static | 154 // static |
| 143 void SiteEngagementScore::UpdateFromVariations(const char* param_name) { | 155 void SiteEngagementScore::UpdateFromVariations(const char* param_name) { |
| 144 double param_vals[MAX_VARIATION]; | 156 double param_vals[MAX_VARIATION]; |
| 145 | 157 |
| 146 for (int i = 0; i < MAX_VARIATION; ++i) { | 158 for (int i = 0; i < MAX_VARIATION; ++i) { |
| 147 std::string param_string = | 159 std::string param_string = |
| 148 variations::GetVariationParamValue(param_name, kVariationNames[i]); | 160 variations::GetVariationParamValue(param_name, kVariationNames[i]); |
| 149 | 161 |
| 150 // Bail out if we didn't get a param string for the key, or if we couldn't | 162 // Bail out if we didn't get a param string for the key, or if we couldn't |
| 151 // convert the param string to a double, or if we get a negative value. | 163 // convert the param string to a double, or if we get a negative value. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 param_values[DECAY_PERIOD_IN_DAYS] = 7; | 342 param_values[DECAY_PERIOD_IN_DAYS] = 7; |
| 331 param_values[DECAY_POINTS] = 5; | 343 param_values[DECAY_POINTS] = 5; |
| 332 param_values[NAVIGATION_POINTS] = 0.5; | 344 param_values[NAVIGATION_POINTS] = 0.5; |
| 333 param_values[USER_INPUT_POINTS] = 0.05; | 345 param_values[USER_INPUT_POINTS] = 0.05; |
| 334 param_values[VISIBLE_MEDIA_POINTS] = 0.02; | 346 param_values[VISIBLE_MEDIA_POINTS] = 0.02; |
| 335 param_values[HIDDEN_MEDIA_POINTS] = 0.01; | 347 param_values[HIDDEN_MEDIA_POINTS] = 0.01; |
| 336 param_values[WEB_APP_INSTALLED_POINTS] = 5; | 348 param_values[WEB_APP_INSTALLED_POINTS] = 5; |
| 337 param_values[BOOTSTRAP_POINTS] = 8; | 349 param_values[BOOTSTRAP_POINTS] = 8; |
| 338 param_values[MEDIUM_ENGAGEMENT_BOUNDARY] = 5; | 350 param_values[MEDIUM_ENGAGEMENT_BOUNDARY] = 5; |
| 339 param_values[HIGH_ENGAGEMENT_BOUNDARY] = 50; | 351 param_values[HIGH_ENGAGEMENT_BOUNDARY] = 50; |
| 352 param_values[MAX_DECAYS_PER_SCORE] = 1; |
| 353 param_values[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS] = 72; |
| 340 | 354 |
| 341 // This is set to zero to avoid interference with tests and is set when | 355 // This is set to zero to avoid interference with tests and is set when |
| 342 // testing this functionality. | 356 // testing this functionality. |
| 343 param_values[FIRST_DAILY_ENGAGEMENT] = 0; | 357 param_values[FIRST_DAILY_ENGAGEMENT] = 0; |
| 344 } | 358 } |
| OLD | NEW |