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 "components/ntp_snippets/user_classifier.h" | 5 #include "components/ntp_snippets/user_classifier.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cfloat> | 8 #include <cfloat> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 } | 260 } |
261 | 261 |
262 double UserClassifier::GetEstimatedAvgTime(Metric metric) const { | 262 double UserClassifier::GetEstimatedAvgTime(Metric metric) const { |
263 DCHECK_NE(metric, Metric::COUNT); | 263 DCHECK_NE(metric, Metric::COUNT); |
264 double metric_value = GetUpToDateMetricValue(metric); | 264 double metric_value = GetUpToDateMetricValue(metric); |
265 return GetEstimateHoursBetweenEvents(metric_value, discount_rate_per_hour_, | 265 return GetEstimateHoursBetweenEvents(metric_value, discount_rate_per_hour_, |
266 min_hours_, max_hours_); | 266 min_hours_, max_hours_); |
267 } | 267 } |
268 | 268 |
269 UserClassifier::UserClass UserClassifier::GetUserClass() const { | 269 UserClassifier::UserClass UserClassifier::GetUserClass() const { |
270 // The pref_service_ can be null in tests. | |
271 if (!pref_service_) | |
Marc Treib
2016/10/06 14:54:37
Is this necessary? All things being equal, I prefe
jkrcal
2016/10/06 15:18:41
If the pref_service is null, we anyway get some de
Marc Treib
2016/10/06 15:27:26
Ah, I just noticed that there's lots of other null
jkrcal
2016/10/06 18:25:38
Makes sense...
| |
272 return UserClass::ACTIVE_NTP_USER; | |
273 | |
270 if (GetEstimatedAvgTime(Metric::NTP_OPENED) >= | 274 if (GetEstimatedAvgTime(Metric::NTP_OPENED) >= |
271 rare_user_opens_ntp_at_most_once_per_hours_) { | 275 rare_user_opens_ntp_at_most_once_per_hours_) { |
272 return UserClass::RARE_NTP_USER; | 276 return UserClass::RARE_NTP_USER; |
273 } | 277 } |
274 | 278 |
275 if (GetEstimatedAvgTime(Metric::SUGGESTIONS_SHOWN) <= | 279 if (GetEstimatedAvgTime(Metric::SUGGESTIONS_SHOWN) <= |
276 active_consumer_scrolls_at_least_once_per_hours_) { | 280 active_consumer_scrolls_at_least_once_per_hours_) { |
277 return UserClass::ACTIVE_SUGGESTIONS_CONSUMER; | 281 return UserClass::ACTIVE_SUGGESTIONS_CONSUMER; |
278 } | 282 } |
279 | 283 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 | 368 |
365 void UserClassifier::SetMetricValue(Metric metric, double metric_value) { | 369 void UserClassifier::SetMetricValue(Metric metric, double metric_value) { |
366 pref_service_->SetDouble(kMetricKeys[static_cast<int>(metric)], metric_value); | 370 pref_service_->SetDouble(kMetricKeys[static_cast<int>(metric)], metric_value); |
367 } | 371 } |
368 | 372 |
369 void UserClassifier::ClearMetricValue(Metric metric) { | 373 void UserClassifier::ClearMetricValue(Metric metric) { |
370 pref_service_->ClearPref(kMetricKeys[static_cast<int>(metric)]); | 374 pref_service_->ClearPref(kMetricKeys[static_cast<int>(metric)]); |
371 } | 375 } |
372 | 376 |
373 } // namespace ntp_snippets | 377 } // namespace ntp_snippets |
OLD | NEW |