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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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.2, // 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 30, // BOOTSTRAP_POINTS | |
dominickn
2016/02/04 03:11:24
Nit: as discussed offline wrt UMA stats, change th
calamity
2016/02/04 23:09:09
Done.
| |
129 }; | 130 }; |
130 | 131 |
131 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; | 132 const char* SiteEngagementScore::kRawScoreKey = "rawScore"; |
132 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; | 133 const char* SiteEngagementScore::kPointsAddedTodayKey = "pointsAddedToday"; |
133 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; | 134 const char* SiteEngagementScore::kLastEngagementTimeKey = "lastEngagementTime"; |
134 const char* SiteEngagementScore::kLastShortcutLaunchTimeKey = | 135 const char* SiteEngagementScore::kLastShortcutLaunchTimeKey = |
135 "lastShortcutLaunchTime"; | 136 "lastShortcutLaunchTime"; |
136 | 137 |
137 double SiteEngagementScore::GetMaxPointsPerDay() { | 138 double SiteEngagementScore::GetMaxPointsPerDay() { |
138 return param_values[MAX_POINTS_PER_DAY]; | 139 return param_values[MAX_POINTS_PER_DAY]; |
(...skipping 24 matching lines...) Expand all Loading... | |
163 } | 164 } |
164 | 165 |
165 double SiteEngagementScore::GetWebAppInstalledPoints() { | 166 double SiteEngagementScore::GetWebAppInstalledPoints() { |
166 return param_values[WEB_APP_INSTALLED_POINTS]; | 167 return param_values[WEB_APP_INSTALLED_POINTS]; |
167 } | 168 } |
168 | 169 |
169 double SiteEngagementScore::GetFirstDailyEngagementPoints() { | 170 double SiteEngagementScore::GetFirstDailyEngagementPoints() { |
170 return param_values[FIRST_DAILY_ENGAGEMENT]; | 171 return param_values[FIRST_DAILY_ENGAGEMENT]; |
171 } | 172 } |
172 | 173 |
174 double SiteEngagementScore::GetBootstrapPoints() { | |
175 return param_values[BOOTSTRAP_POINTS]; | |
176 } | |
177 | |
173 void SiteEngagementScore::UpdateFromVariations() { | 178 void SiteEngagementScore::UpdateFromVariations() { |
174 double param_vals[MAX_VARIATION]; | 179 double param_vals[MAX_VARIATION]; |
175 | 180 |
176 for (int i = 0; i < MAX_VARIATION; ++i) { | 181 for (int i = 0; i < MAX_VARIATION; ++i) { |
177 std::string param_string = variations::GetVariationParamValue( | 182 std::string param_string = variations::GetVariationParamValue( |
178 SiteEngagementService::kEngagementParams, kVariationNames[i]); | 183 SiteEngagementService::kEngagementParams, kVariationNames[i]); |
179 | 184 |
180 // Bail out if we didn't get a param string for the key, or if we couldn't | 185 // Bail out if we didn't get a param string for the key, or if we couldn't |
181 // convert the param string to a double, or if we get a negative value. | 186 // convert the param string to a double, or if we get a negative value. |
182 if (param_string.empty() || | 187 if (param_string.empty() || |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 | 332 |
328 void SiteEngagementScore::SetParamValuesForTesting() { | 333 void SiteEngagementScore::SetParamValuesForTesting() { |
329 param_values[MAX_POINTS_PER_DAY] = 5; | 334 param_values[MAX_POINTS_PER_DAY] = 5; |
330 param_values[DECAY_PERIOD_IN_DAYS] = 7; | 335 param_values[DECAY_PERIOD_IN_DAYS] = 7; |
331 param_values[DECAY_POINTS] = 5; | 336 param_values[DECAY_POINTS] = 5; |
332 param_values[NAVIGATION_POINTS] = 0.5; | 337 param_values[NAVIGATION_POINTS] = 0.5; |
333 param_values[USER_INPUT_POINTS] = 0.05; | 338 param_values[USER_INPUT_POINTS] = 0.05; |
334 param_values[VISIBLE_MEDIA_POINTS] = 0.02; | 339 param_values[VISIBLE_MEDIA_POINTS] = 0.02; |
335 param_values[HIDDEN_MEDIA_POINTS] = 0.01; | 340 param_values[HIDDEN_MEDIA_POINTS] = 0.01; |
336 param_values[WEB_APP_INSTALLED_POINTS] = 5; | 341 param_values[WEB_APP_INSTALLED_POINTS] = 5; |
342 param_values[BOOTSTRAP_POINTS] = 30; | |
337 | 343 |
338 // This is set to zero to avoid interference with tests and is set when | 344 // This is set to zero to avoid interference with tests and is set when |
339 // testing this functionality. | 345 // testing this functionality. |
340 param_values[FIRST_DAILY_ENGAGEMENT] = 0; | 346 param_values[FIRST_DAILY_ENGAGEMENT] = 0; |
341 } | 347 } |
342 | 348 |
343 const char SiteEngagementService::kEngagementParams[] = "SiteEngagement"; | 349 const char SiteEngagementService::kEngagementParams[] = "SiteEngagement"; |
344 | 350 |
345 // static | 351 // static |
346 SiteEngagementService* SiteEngagementService::Get(Profile* profile) { | 352 SiteEngagementService* SiteEngagementService::Get(Profile* profile) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 | 518 |
513 scoped_ptr<base::DictionaryValue> score_dict = | 519 scoped_ptr<base::DictionaryValue> score_dict = |
514 GetScoreDictForOrigin(settings_map, origin); | 520 GetScoreDictForOrigin(settings_map, origin); |
515 SiteEngagementScore score(clock_.get(), *score_dict); | 521 SiteEngagementScore score(clock_.get(), *score_dict); |
516 score_map[origin] = score.Score(); | 522 score_map[origin] = score.Score(); |
517 } | 523 } |
518 | 524 |
519 return score_map; | 525 return score_map; |
520 } | 526 } |
521 | 527 |
528 bool SiteEngagementService::IsBootstrapped() { | |
529 return GetTotalEngagementPoints() >= | |
530 SiteEngagementScore::GetBootstrapPoints(); | |
531 } | |
532 | |
522 SiteEngagementService::SiteEngagementService(Profile* profile, | 533 SiteEngagementService::SiteEngagementService(Profile* profile, |
523 scoped_ptr<base::Clock> clock) | 534 scoped_ptr<base::Clock> clock) |
524 : profile_(profile), clock_(std::move(clock)), weak_factory_(this) { | 535 : profile_(profile), clock_(std::move(clock)), weak_factory_(this) { |
525 // May be null in tests. | 536 // May be null in tests. |
526 history::HistoryService* history = HistoryServiceFactory::GetForProfile( | 537 history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
527 profile, ServiceAccessType::IMPLICIT_ACCESS); | 538 profile, ServiceAccessType::IMPLICIT_ACCESS); |
528 if (history) | 539 if (history) |
529 history->AddObserver(this); | 540 history->AddObserver(this); |
530 } | 541 } |
531 | 542 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 HostContentSettingsMapFactory::GetForProfile(profile_); | 677 HostContentSettingsMapFactory::GetForProfile(profile_); |
667 for (const auto& origin_to_count : origin_counts) { | 678 for (const auto& origin_to_count : origin_counts) { |
668 if (origin_to_count.second != 0) | 679 if (origin_to_count.second != 0) |
669 continue; | 680 continue; |
670 | 681 |
671 settings_map->SetWebsiteSettingDefaultScope( | 682 settings_map->SetWebsiteSettingDefaultScope( |
672 origin_to_count.first, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 683 origin_to_count.first, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
673 std::string(), nullptr); | 684 std::string(), nullptr); |
674 } | 685 } |
675 } | 686 } |
OLD | NEW |