Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 95 |
| 96 return make_scoped_ptr(static_cast<base::DictionaryValue*>(value.release())); | 96 return make_scoped_ptr(static_cast<base::DictionaryValue*>(value.release())); |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 | 100 |
| 101 const double SiteEngagementScore::kMaxPoints = 100; | 101 const double SiteEngagementScore::kMaxPoints = 100; |
| 102 double SiteEngagementScore::g_max_points_per_day = 5; | 102 double SiteEngagementScore::g_max_points_per_day = 5; |
| 103 double SiteEngagementScore::g_navigation_points = 0.5; | 103 double SiteEngagementScore::g_navigation_points = 0.5; |
| 104 double SiteEngagementScore::g_user_input_points = 0.05; | 104 double SiteEngagementScore::g_user_input_points = 0.05; |
| 105 double SiteEngagementScore::g_visible_media_playing_points = 0.02; | |
| 106 double SiteEngagementScore::g_hidden_media_playing_points = 0.01; | |
| 105 int SiteEngagementScore::g_decay_period_in_days = 7; | 107 int SiteEngagementScore::g_decay_period_in_days = 7; |
| 106 double SiteEngagementScore::g_decay_points = 5; | 108 double SiteEngagementScore::g_decay_points = 5; |
| 107 | 109 |
| 108 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; | 110 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; |
| 109 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; | 111 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; |
| 110 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; | 112 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; |
| 111 | 113 |
| 112 void SiteEngagementScore::UpdateFromVariations() { | 114 void SiteEngagementScore::UpdateFromVariations() { |
| 113 std::string max_points_per_day_param = variations::GetVariationParamValue( | 115 std::string max_points_per_day_param = variations::GetVariationParamValue( |
| 114 kEngagementParams, kMaxPointsPerDayParam); | 116 kEngagementParams, kMaxPointsPerDayParam); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 136 base::StringToInt(decay_period_in_days_param, &decay_period_in_days) && | 138 base::StringToInt(decay_period_in_days_param, &decay_period_in_days) && |
| 137 base::StringToDouble(decay_points_param, &decay_points) && | 139 base::StringToDouble(decay_points_param, &decay_points) && |
| 138 max_points_per_day >= navigation_points && | 140 max_points_per_day >= navigation_points && |
| 139 max_points_per_day >= user_input_points && navigation_points >= 0 && | 141 max_points_per_day >= user_input_points && navigation_points >= 0 && |
| 140 user_input_points >= 0 && decay_period_in_days > 0 && | 142 user_input_points >= 0 && decay_period_in_days > 0 && |
| 141 decay_points >= 0) { | 143 decay_points >= 0) { |
| 142 g_max_points_per_day = max_points_per_day; | 144 g_max_points_per_day = max_points_per_day; |
| 143 g_navigation_points = navigation_points; | 145 g_navigation_points = navigation_points; |
| 144 g_user_input_points = user_input_points; | 146 g_user_input_points = user_input_points; |
| 145 g_decay_period_in_days = decay_period_in_days; | 147 g_decay_period_in_days = decay_period_in_days; |
| 146 g_decay_points = decay_points; | 148 g_decay_points = decay_points; |
|
calamity
2015/11/03 04:49:46
Need to add controls for the points here (either n
dominickn
2015/11/03 07:03:54
Done. Don't know how I missed this.
| |
| 147 } | 149 } |
| 148 } | 150 } |
| 149 } | 151 } |
| 150 | 152 |
| 151 SiteEngagementScore::SiteEngagementScore( | 153 SiteEngagementScore::SiteEngagementScore( |
| 152 base::Clock* clock, | 154 base::Clock* clock, |
| 153 const base::DictionaryValue& score_dict) | 155 const base::DictionaryValue& score_dict) |
| 154 : SiteEngagementScore(clock) { | 156 : SiteEngagementScore(clock) { |
| 155 score_dict.GetDouble(kRawScoreKey, &raw_score_); | 157 score_dict.GetDouble(kRawScoreKey, &raw_score_); |
| 156 score_dict.GetDouble(kPointsAddedTodayKey, &points_added_today_); | 158 score_dict.GetDouble(kPointsAddedTodayKey, &points_added_today_); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 } | 313 } |
| 312 | 314 |
| 313 void SiteEngagementService::HandleUserInput( | 315 void SiteEngagementService::HandleUserInput( |
| 314 const GURL& url, | 316 const GURL& url, |
| 315 SiteEngagementMetrics::EngagementType type) { | 317 SiteEngagementMetrics::EngagementType type) { |
| 316 SiteEngagementMetrics::RecordEngagement(type); | 318 SiteEngagementMetrics::RecordEngagement(type); |
| 317 AddPoints(url, SiteEngagementScore::g_user_input_points); | 319 AddPoints(url, SiteEngagementScore::g_user_input_points); |
| 318 RecordMetrics(); | 320 RecordMetrics(); |
| 319 } | 321 } |
| 320 | 322 |
| 323 void SiteEngagementService::HandleMediaPlaying(const GURL& url, | |
| 324 bool is_hidden) { | |
| 325 SiteEngagementMetrics::RecordEngagement( | |
| 326 is_hidden ? SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN | |
| 327 : SiteEngagementMetrics::ENGAGEMENT_MEDIA_VISIBLE); | |
| 328 AddPoints(url, is_hidden | |
| 329 ? SiteEngagementScore::g_hidden_media_playing_points | |
| 330 : SiteEngagementScore::g_visible_media_playing_points); | |
| 331 RecordMetrics(); | |
| 332 } | |
| 333 | |
| 321 double SiteEngagementService::GetScore(const GURL& url) { | 334 double SiteEngagementService::GetScore(const GURL& url) { |
| 322 HostContentSettingsMap* settings_map = | 335 HostContentSettingsMap* settings_map = |
| 323 HostContentSettingsMapFactory::GetForProfile(profile_); | 336 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 324 scoped_ptr<base::DictionaryValue> score_dict = | 337 scoped_ptr<base::DictionaryValue> score_dict = |
| 325 GetScoreDictForOrigin(settings_map, url); | 338 GetScoreDictForOrigin(settings_map, url); |
| 326 SiteEngagementScore score(clock_.get(), *score_dict); | 339 SiteEngagementScore score(clock_.get(), *score_dict); |
| 327 | 340 |
| 328 return score.Score(); | 341 return score.Score(); |
| 329 } | 342 } |
| 330 | 343 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 int SiteEngagementService::OriginsWithMaxEngagement( | 504 int SiteEngagementService::OriginsWithMaxEngagement( |
| 492 std::map<GURL, double>& score_map) { | 505 std::map<GURL, double>& score_map) { |
| 493 int total_origins = 0; | 506 int total_origins = 0; |
| 494 | 507 |
| 495 for (const auto& value : score_map) | 508 for (const auto& value : score_map) |
| 496 if (value.second == SiteEngagementScore::kMaxPoints) | 509 if (value.second == SiteEngagementScore::kMaxPoints) |
| 497 ++total_origins; | 510 ++total_origins; |
| 498 | 511 |
| 499 return total_origins; | 512 return total_origins; |
| 500 } | 513 } |
| OLD | NEW |