| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 param_values[WEB_APP_INSTALLED_POINTS] = {"web_app_installed_points", 5}; | 85 param_values[WEB_APP_INSTALLED_POINTS] = {"web_app_installed_points", 5}; |
| 86 param_values[FIRST_DAILY_ENGAGEMENT] = {"first_daily_engagement_points", 1.5}; | 86 param_values[FIRST_DAILY_ENGAGEMENT] = {"first_daily_engagement_points", 1.5}; |
| 87 param_values[BOOTSTRAP_POINTS] = {"bootstrap_points", 24}; | 87 param_values[BOOTSTRAP_POINTS] = {"bootstrap_points", 24}; |
| 88 param_values[MEDIUM_ENGAGEMENT_BOUNDARY] = {"medium_engagement_boundary", 15}; | 88 param_values[MEDIUM_ENGAGEMENT_BOUNDARY] = {"medium_engagement_boundary", 15}; |
| 89 param_values[HIGH_ENGAGEMENT_BOUNDARY] = {"high_engagement_boundary", 50}; | 89 param_values[HIGH_ENGAGEMENT_BOUNDARY] = {"high_engagement_boundary", 50}; |
| 90 param_values[MAX_DECAYS_PER_SCORE] = {"max_decays_per_score", 4}; | 90 param_values[MAX_DECAYS_PER_SCORE] = {"max_decays_per_score", 4}; |
| 91 param_values[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS] = { | 91 param_values[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS] = { |
| 92 "last_engagement_grace_period_in_hours", 1}; | 92 "last_engagement_grace_period_in_hours", 1}; |
| 93 param_values[NOTIFICATION_PERMISSION_POINTS] = { | 93 param_values[NOTIFICATION_PERMISSION_POINTS] = { |
| 94 "notification_permission_points", 5}; | 94 "notification_permission_points", 5}; |
| 95 param_values[NOTIFICATION_INTERACTION_POINTS] = { |
| 96 "notification_permission_points", 1}; |
| 95 return param_values; | 97 return param_values; |
| 96 } | 98 } |
| 97 | 99 |
| 98 double SiteEngagementScore::GetMaxPointsPerDay() { | 100 double SiteEngagementScore::GetMaxPointsPerDay() { |
| 99 return GetParamValues()[MAX_POINTS_PER_DAY].second; | 101 return GetParamValues()[MAX_POINTS_PER_DAY].second; |
| 100 } | 102 } |
| 101 | 103 |
| 102 double SiteEngagementScore::GetDecayPeriodInHours() { | 104 double SiteEngagementScore::GetDecayPeriodInHours() { |
| 103 return GetParamValues()[DECAY_PERIOD_IN_HOURS].second; | 105 return GetParamValues()[DECAY_PERIOD_IN_HOURS].second; |
| 104 } | 106 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 158 } |
| 157 | 159 |
| 158 double SiteEngagementScore::GetLastEngagementGracePeriodInHours() { | 160 double SiteEngagementScore::GetLastEngagementGracePeriodInHours() { |
| 159 return GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second; | 161 return GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second; |
| 160 } | 162 } |
| 161 | 163 |
| 162 double SiteEngagementScore::GetNotificationPermissionPoints() { | 164 double SiteEngagementScore::GetNotificationPermissionPoints() { |
| 163 return GetParamValues()[NOTIFICATION_PERMISSION_POINTS].second; | 165 return GetParamValues()[NOTIFICATION_PERMISSION_POINTS].second; |
| 164 } | 166 } |
| 165 | 167 |
| 168 double SiteEngagementScore::GetNotificationInteractionPoints() { |
| 169 return GetParamValues()[NOTIFICATION_INTERACTION_POINTS].second; |
| 170 } |
| 171 |
| 172 void SiteEngagementScore::SetParamValuesForTesting() { |
| 173 GetParamValues()[MAX_POINTS_PER_DAY].second = 5; |
| 174 GetParamValues()[DECAY_PERIOD_IN_HOURS].second = 7 * 24; |
| 175 GetParamValues()[DECAY_POINTS].second = 5; |
| 176 GetParamValues()[NAVIGATION_POINTS].second = 0.5; |
| 177 GetParamValues()[USER_INPUT_POINTS].second = 0.05; |
| 178 GetParamValues()[VISIBLE_MEDIA_POINTS].second = 0.02; |
| 179 GetParamValues()[HIDDEN_MEDIA_POINTS].second = 0.01; |
| 180 GetParamValues()[WEB_APP_INSTALLED_POINTS].second = 5; |
| 181 GetParamValues()[BOOTSTRAP_POINTS].second = 8; |
| 182 GetParamValues()[MEDIUM_ENGAGEMENT_BOUNDARY].second = 5; |
| 183 GetParamValues()[HIGH_ENGAGEMENT_BOUNDARY].second = 50; |
| 184 GetParamValues()[MAX_DECAYS_PER_SCORE].second = 1; |
| 185 GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second = 72; |
| 186 GetParamValues()[NOTIFICATION_PERMISSION_POINTS].second = 5; |
| 187 GetParamValues()[NOTIFICATION_INTERACTION_POINTS].second = 1; |
| 188 |
| 189 // This is set to values that avoid interference with tests and are set when |
| 190 // testing these features. |
| 191 GetParamValues()[FIRST_DAILY_ENGAGEMENT].second = 0; |
| 192 GetParamValues()[DECAY_PROPORTION].second = 1; |
| 193 GetParamValues()[SCORE_CLEANUP_THRESHOLD].second = 0; |
| 194 } |
| 166 // static | 195 // static |
| 167 void SiteEngagementScore::UpdateFromVariations(const char* param_name) { | 196 void SiteEngagementScore::UpdateFromVariations(const char* param_name) { |
| 168 double param_vals[MAX_VARIATION]; | 197 double param_vals[MAX_VARIATION]; |
| 169 | 198 |
| 170 for (int i = 0; i < MAX_VARIATION; ++i) { | 199 for (int i = 0; i < MAX_VARIATION; ++i) { |
| 171 std::string param_string = variations::GetVariationParamValue( | 200 std::string param_string = variations::GetVariationParamValue( |
| 172 param_name, GetParamValues()[i].first); | 201 param_name, GetParamValues()[i].first); |
| 173 | 202 |
| 174 // Bail out if we didn't get a param string for the key, or if we couldn't | 203 // Bail out if we didn't get a param string for the key, or if we couldn't |
| 175 // convert the param string to a double, or if we get a negative value. | 204 // convert the param string to a double, or if we get a negative value. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 // TODO(dominickn, raymes): call PermissionManager::GetPermissionStatus when | 410 // TODO(dominickn, raymes): call PermissionManager::GetPermissionStatus when |
| 382 // the PermissionManager is thread-safe. | 411 // the PermissionManager is thread-safe. |
| 383 if (settings_map_ && settings_map_->GetContentSetting( | 412 if (settings_map_ && settings_map_->GetContentSetting( |
| 384 origin_, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 413 origin_, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 385 std::string()) == CONTENT_SETTING_ALLOW) { | 414 std::string()) == CONTENT_SETTING_ALLOW) { |
| 386 bonus += GetNotificationPermissionPoints(); | 415 bonus += GetNotificationPermissionPoints(); |
| 387 } | 416 } |
| 388 | 417 |
| 389 return bonus; | 418 return bonus; |
| 390 } | 419 } |
| 391 | |
| 392 void SiteEngagementScore::SetParamValuesForTesting() { | |
| 393 GetParamValues()[MAX_POINTS_PER_DAY].second = 5; | |
| 394 GetParamValues()[DECAY_PERIOD_IN_HOURS].second = 7 * 24; | |
| 395 GetParamValues()[DECAY_POINTS].second = 5; | |
| 396 GetParamValues()[NAVIGATION_POINTS].second = 0.5; | |
| 397 GetParamValues()[USER_INPUT_POINTS].second = 0.05; | |
| 398 GetParamValues()[VISIBLE_MEDIA_POINTS].second = 0.02; | |
| 399 GetParamValues()[HIDDEN_MEDIA_POINTS].second = 0.01; | |
| 400 GetParamValues()[WEB_APP_INSTALLED_POINTS].second = 5; | |
| 401 GetParamValues()[BOOTSTRAP_POINTS].second = 8; | |
| 402 GetParamValues()[MEDIUM_ENGAGEMENT_BOUNDARY].second = 5; | |
| 403 GetParamValues()[HIGH_ENGAGEMENT_BOUNDARY].second = 50; | |
| 404 GetParamValues()[MAX_DECAYS_PER_SCORE].second = 1; | |
| 405 GetParamValues()[LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS].second = 72; | |
| 406 GetParamValues()[NOTIFICATION_PERMISSION_POINTS].second = 5; | |
| 407 | |
| 408 // This is set to values that avoid interference with tests and are set when | |
| 409 // testing these features. | |
| 410 GetParamValues()[FIRST_DAILY_ENGAGEMENT].second = 0; | |
| 411 GetParamValues()[DECAY_PROPORTION].second = 1; | |
| 412 GetParamValues()[SCORE_CLEANUP_THRESHOLD].second = 0; | |
| 413 } | |
| OLD | NEW |