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 <float.h> | |
8 | |
9 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cfloat> |
10 #include <string> | 9 #include <string> |
11 | 10 |
12 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
14 #include "components/ntp_snippets/features.h" | 13 #include "components/ntp_snippets/features.h" |
15 #include "components/ntp_snippets/pref_names.h" | 14 #include "components/ntp_snippets/pref_names.h" |
16 #include "components/prefs/pref_registry_simple.h" | 15 #include "components/prefs/pref_registry_simple.h" |
17 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
18 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
19 | 18 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // differs from the previous value, rescale the metric values so that the | 207 // differs from the previous value, rescale the metric values so that the |
209 // expectation does not change abruptly! | 208 // expectation does not change abruptly! |
210 | 209 |
211 // Initialize the prefs storing the last time: the counter has just started! | 210 // Initialize the prefs storing the last time: the counter has just started! |
212 for (const Metric metric : kMetrics) { | 211 for (const Metric metric : kMetrics) { |
213 if (!HasLastTime(metric)) | 212 if (!HasLastTime(metric)) |
214 SetLastTimeToNow(metric); | 213 SetLastTimeToNow(metric); |
215 } | 214 } |
216 } | 215 } |
217 | 216 |
218 UserClassifier::~UserClassifier() {} | 217 UserClassifier::~UserClassifier() = default; |
219 | 218 |
220 // static | 219 // static |
221 void UserClassifier::RegisterProfilePrefs(PrefRegistrySimple* registry) { | 220 void UserClassifier::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
222 double discount_rate = GetDiscountRatePerHour(); | 221 double discount_rate = GetDiscountRatePerHour(); |
223 double min_hours = GetMinHours(); | 222 double min_hours = GetMinHours(); |
224 double max_hours = GetMaxHours(); | 223 double max_hours = GetMaxHours(); |
225 | 224 |
226 for (Metric metric : kMetrics) { | 225 for (Metric metric : kMetrics) { |
227 double default_metric_value = GetMetricValueForEstimateHoursBetweenEvents( | 226 double default_metric_value = GetMetricValueForEstimateHoursBetweenEvents( |
228 GetInitialHoursBetweenEvents(metric), discount_rate, min_hours, | 227 GetInitialHoursBetweenEvents(metric), discount_rate, min_hours, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 364 |
366 void UserClassifier::SetMetricValue(Metric metric, double metric_value) { | 365 void UserClassifier::SetMetricValue(Metric metric, double metric_value) { |
367 pref_service_->SetDouble(kMetricKeys[static_cast<int>(metric)], metric_value); | 366 pref_service_->SetDouble(kMetricKeys[static_cast<int>(metric)], metric_value); |
368 } | 367 } |
369 | 368 |
370 void UserClassifier::ClearMetricValue(Metric metric) { | 369 void UserClassifier::ClearMetricValue(Metric metric) { |
371 pref_service_->ClearPref(kMetricKeys[static_cast<int>(metric)]); | 370 pref_service_->ClearPref(kMetricKeys[static_cast<int>(metric)]); |
372 } | 371 } |
373 | 372 |
374 } // namespace ntp_snippets | 373 } // namespace ntp_snippets |
OLD | NEW |