Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: components/ntp_snippets/user_classifier.cc

Issue 2395123002: Connecting UserClassifier to NtpSnippetsFetcher (Closed)
Patch Set: Unit-test fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_)
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698