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

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

Issue 2759423003: [UserClassifier] Inject a clock (Closed)
Patch Set: Created 3 years, 9 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 #ifndef COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_
6 #define COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ 6 #define COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_
7 7
8 #include <memory>
8 #include <string> 9 #include <string>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/time/time.h"
12 12
13 class PrefRegistrySimple; 13 class PrefRegistrySimple;
14 class PrefService; 14 class PrefService;
15 15
16 namespace base {
17 class Clock;
18 } // namespace base
19
16 namespace ntp_snippets { 20 namespace ntp_snippets {
17 21
18 // Collects data about user usage patterns of content suggestions, computes 22 // Collects data about user usage patterns of content suggestions, computes
19 // long-term user metrics locally using pref, and reports the metrics to UMA. 23 // long-term user metrics locally using pref, and reports the metrics to UMA.
20 // Based on these long-term user metrics, it classifies the user in a UserClass. 24 // Based on these long-term user metrics, it classifies the user in a UserClass.
21 class UserClassifier { 25 class UserClassifier {
22 public: 26 public:
23 // Enumeration listing user classes 27 // Enumeration listing user classes
24 enum class UserClass { 28 enum class UserClass {
25 RARE_NTP_USER, 29 RARE_NTP_USER,
(...skipping 19 matching lines...) Expand all
45 // Home, this coincides with NTP_OPENED. 49 // Home, this coincides with NTP_OPENED.
46 SUGGESTIONS_SHOWN, // When the content suggestions are shown to the user - 50 SUGGESTIONS_SHOWN, // When the content suggestions are shown to the user -
47 // in the current implementation when the user scrolls 51 // in the current implementation when the user scrolls
48 // below the fold. 52 // below the fold.
49 SUGGESTIONS_USED, // When the user clicks on some suggestions or on some 53 SUGGESTIONS_USED, // When the user clicks on some suggestions or on some
50 // "More" button. 54 // "More" button.
51 COUNT // Keep this as the last element. 55 COUNT // Keep this as the last element.
52 }; 56 };
53 57
54 // The provided |pref_service| may be nullptr in unit-tests. 58 // The provided |pref_service| may be nullptr in unit-tests.
55 explicit UserClassifier(PrefService* pref_service); 59 UserClassifier(PrefService* pref_service, std::unique_ptr<base::Clock> clock);
56 ~UserClassifier(); 60 ~UserClassifier();
57 61
58 // Registers profile prefs for all metrics. Called from browser_prefs.cc. 62 // Registers profile prefs for all metrics. Called from browser_prefs.cc.
59 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 63 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
60 64
61 // Informs the UserClassifier about a new event for |metric|. The 65 // Informs the UserClassifier about a new event for |metric|. The
62 // classification is based on these calls. 66 // classification is based on these calls.
63 void OnEvent(Metric metric); 67 void OnEvent(Metric metric);
64 68
65 // Get the estimate average length of the interval between two successive 69 // Get the estimate average length of the interval between two successive
(...skipping 20 matching lines...) Expand all
86 // return 0. 90 // return 0.
87 double GetHoursSinceLastTime(Metric metric) const; 91 double GetHoursSinceLastTime(Metric metric) const;
88 bool HasLastTime(Metric metric) const; 92 bool HasLastTime(Metric metric) const;
89 void SetLastTimeToNow(Metric metric); 93 void SetLastTimeToNow(Metric metric);
90 94
91 double GetMetricValue(Metric metric) const; 95 double GetMetricValue(Metric metric) const;
92 void SetMetricValue(Metric metric, double metric_value); 96 void SetMetricValue(Metric metric, double metric_value);
93 void ClearMetricValue(Metric metric); 97 void ClearMetricValue(Metric metric);
94 98
95 PrefService* pref_service_; 99 PrefService* pref_service_;
100 std::unique_ptr<base::Clock> clock_;
96 101
97 // Params of the metric. 102 // Params of the metric.
98 const double discount_rate_per_hour_; 103 const double discount_rate_per_hour_;
99 const double min_hours_; 104 const double min_hours_;
100 const double max_hours_; 105 const double max_hours_;
101 106
102 // Params of the classification. 107 // Params of the classification.
103 const double active_consumer_clicks_at_least_once_per_hours_; 108 const double active_consumer_clicks_at_least_once_per_hours_;
104 const double rare_user_opens_ntp_at_most_once_per_hours_; 109 const double rare_user_opens_ntp_at_most_once_per_hours_;
105 110
106 DISALLOW_COPY_AND_ASSIGN(UserClassifier); 111 DISALLOW_COPY_AND_ASSIGN(UserClassifier);
107 }; 112 };
108 113
109 } // namespace ntp_snippets 114 } // namespace ntp_snippets
110 115
111 #endif // COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ 116 #endif // COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698