| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_service.h" | 5 #include "chrome/browser/engagement/site_engagement_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 const double SiteEngagementScore::kMaxPoints = 100; | 118 const double SiteEngagementScore::kMaxPoints = 100; |
| 119 double SiteEngagementScore::param_values[] = { | 119 double SiteEngagementScore::param_values[] = { |
| 120 5, // MAX_POINTS_PER_DAY | 120 5, // MAX_POINTS_PER_DAY |
| 121 7, // DECAY_PERIOD_IN_DAYS | 121 7, // DECAY_PERIOD_IN_DAYS |
| 122 5, // DECAY_POINTS | 122 5, // DECAY_POINTS |
| 123 0.5, // NAVIGATION_POINTS | 123 0.5, // NAVIGATION_POINTS |
| 124 0.05, // USER_INPUT_POINTS | 124 0.2, // USER_INPUT_POINTS |
| 125 0.02, // VISIBLE_MEDIA_POINTS | 125 0.02, // VISIBLE_MEDIA_POINTS |
| 126 0.01, // HIDDEN_MEDIA_POINTS | 126 0.01, // HIDDEN_MEDIA_POINTS |
| 127 5, // WEB_APP_INSTALLED_POINTS | 127 5, // WEB_APP_INSTALLED_POINTS |
| 128 0.5, // FIRST_DAILY_ENGAGEMENT | 128 0.5, // FIRST_DAILY_ENGAGEMENT |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; | 131 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; |
| 132 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; | 132 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; |
| 133 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; | 133 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; |
| 134 const char* SiteEngagementScore::kLastShortcutLaunchTimeKey = | 134 const char* SiteEngagementScore::kLastShortcutLaunchTimeKey = |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 318 |
| 319 double SiteEngagementScore::BonusScore() const { | 319 double SiteEngagementScore::BonusScore() const { |
| 320 int days_since_shortcut_launch = | 320 int days_since_shortcut_launch = |
| 321 (clock_->Now() - last_shortcut_launch_time_).InDays(); | 321 (clock_->Now() - last_shortcut_launch_time_).InDays(); |
| 322 if (days_since_shortcut_launch <= kMaxDaysSinceShortcutLaunch) | 322 if (days_since_shortcut_launch <= kMaxDaysSinceShortcutLaunch) |
| 323 return GetWebAppInstalledPoints(); | 323 return GetWebAppInstalledPoints(); |
| 324 | 324 |
| 325 return 0; | 325 return 0; |
| 326 } | 326 } |
| 327 | 327 |
| 328 void SiteEngagementScore::DisableFirstDailyEngagementBonusForTesting() { | 328 void SiteEngagementScore::SetParamValuesForTesting() { |
| 329 param_values[MAX_POINTS_PER_DAY] = 5; |
| 330 param_values[DECAY_PERIOD_IN_DAYS] = 7; |
| 331 param_values[DECAY_POINTS] = 5; |
| 332 param_values[NAVIGATION_POINTS] = 0.5; |
| 333 param_values[USER_INPUT_POINTS] = 0.05; |
| 334 param_values[VISIBLE_MEDIA_POINTS] = 0.02; |
| 335 param_values[HIDDEN_MEDIA_POINTS] = 0.01; |
| 336 param_values[WEB_APP_INSTALLED_POINTS] = 5; |
| 337 |
| 338 // This is set to zero to avoid interference with tests and is set when |
| 339 // testing this functionality. |
| 329 param_values[FIRST_DAILY_ENGAGEMENT] = 0; | 340 param_values[FIRST_DAILY_ENGAGEMENT] = 0; |
| 330 } | 341 } |
| 331 | 342 |
| 332 const char SiteEngagementService::kEngagementParams[] = "SiteEngagement"; | 343 const char SiteEngagementService::kEngagementParams[] = "SiteEngagement"; |
| 333 | 344 |
| 334 // static | 345 // static |
| 335 SiteEngagementService* SiteEngagementService::Get(Profile* profile) { | 346 SiteEngagementService* SiteEngagementService::Get(Profile* profile) { |
| 336 return SiteEngagementServiceFactory::GetForProfile(profile); | 347 return SiteEngagementServiceFactory::GetForProfile(profile); |
| 337 } | 348 } |
| 338 | 349 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 HostContentSettingsMapFactory::GetForProfile(profile_); | 666 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 656 for (const auto& origin_to_count : origin_counts) { | 667 for (const auto& origin_to_count : origin_counts) { |
| 657 if (origin_to_count.second != 0) | 668 if (origin_to_count.second != 0) |
| 658 continue; | 669 continue; |
| 659 | 670 |
| 660 settings_map->SetWebsiteSettingDefaultScope( | 671 settings_map->SetWebsiteSettingDefaultScope( |
| 661 origin_to_count.first, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 672 origin_to_count.first, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| 662 std::string(), nullptr); | 673 std::string(), nullptr); |
| 663 } | 674 } |
| 664 } | 675 } |
| OLD | NEW |