Chromium Code Reviews| Index: components/ntp_snippets/user_classifier.h |
| diff --git a/components/ntp_snippets/user_classifier.h b/components/ntp_snippets/user_classifier.h |
| index 3314884606f42b125937584ed468d285b0c3ad1d..b0ebc39420c4d8c884743f9eb18fad5f8dfdb915 100644 |
| --- a/components/ntp_snippets/user_classifier.h |
| +++ b/components/ntp_snippets/user_classifier.h |
| @@ -5,7 +5,10 @@ |
| #ifndef COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ |
| #define COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ |
| +#include <string> |
| + |
| #include "base/macros.h" |
| +#include "base/time/time.h" |
| class PrefRegistrySimple; |
| class PrefService; |
| @@ -14,10 +17,16 @@ namespace ntp_snippets { |
| // Collects data about user usage patterns of content suggestions, computes |
| // long-term user metrics locally using pref, and reports the metrics to UMA. |
| -// TODO(jkrcal): Add classification of users based on the metrics and getters |
| -// for the classification as well as for the metrics. |
| +// Based on these lon-term user metrics, it classifies the user in a UserClass. |
| class UserClassifier { |
| public: |
| + // Enumeration listing user classes |
| + enum class UserClass { |
| + OCCASIONAL_NTP_USER, |
| + NORMAL_NTP_USER, |
| + FREQUENT_NTP_USER, |
| + }; |
| + |
| // The provided |pref_service| may be nullptr in unit-tests. |
| explicit UserClassifier(PrefService* pref_service); |
| ~UserClassifier(); |
| @@ -36,22 +45,35 @@ class UserClassifier { |
| // When the user clicks on some suggestions or on some "More" button. |
| void OnSuggestionsUsed(); |
| - private: |
| - // The event has happened, recompute and store the metric accordingly. |
| - void UpdateMetricOnEvent(const char* metric_pref_name, |
| - const char* last_time_pref_name); |
| + // Get the estimate frequencies of events that the classifier tracks. |
|
Marc Treib
2016/09/19 15:20:16
nit: these return intervals, not frequencies.
All
jkrcal
2016/09/19 18:45:25
Done.
|
| + double GetEstimatedAvgTimeToOpenNTP(); |
| + double GetEstimatedAvgTimeToShowSuggestions(); |
| + double GetEstimatedAvgTimeToUseSuggestions(); |
| - // Compute the number of hours between two events for the given metric value |
| - // assuming the events were equally distributed. |
| - double GetEstimateHoursBetweenEvents(const char* metric_pref_name); |
| + // Return the classification of the current user. |
| + UserClass GetUserClass(); |
| + std::string GetUserClassDescription(); |
|
Marc Treib
2016/09/19 15:20:16
Mark this "ForDebugging" or something like that? O
jkrcal
2016/09/19 18:45:25
Done.
|
| - // Returns the number of hours since the last event of the same type or |
| - // DBL_MAX if there is no last event of that type. |
| + // Resets the classification (emulates a fresh upgrade / install). |
| + void ClearClassificationForTesting(); |
|
Marc Treib
2016/09/19 15:20:16
s/ForTesting/ForDebugging/
"ForTesting" implies i
jkrcal
2016/09/19 18:45:25
Done.
|
| + |
| + private: |
| + // The event has happened, recompute the metric accordingly. Then store and |
| + // return the new value. |
| + double UpdateMetricOnEvent(const char* metric_pref_name, |
| + const char* last_time_pref_name); |
|
Marc Treib
2016/09/19 15:20:16
misaligned
jkrcal
2016/09/19 18:45:25
Done.
|
| + // No event has happened but we need to get up-to-date metric, recompute and |
| + // return the new value. This function does not store the recomputed metric. |
| + double GetUpToDateMetricValue(const char* metric_pref_name, |
| + const char* last_time_pref_name); |
| + |
| + // Returns the number of hours since the last event of the same type. |
| + // If there is no last event of that type, assume it happened just now (call |
| + // SetLastTimeToNow()), and return 0. |
| double GetHoursSinceLastTime(const char* last_time_pref_name); |
| void SetLastTimeToNow(const char* last_time_pref_name); |
| PrefService* pref_service_; |
| - double const discount_rate_per_hour_; |
| DISALLOW_COPY_AND_ASSIGN(UserClassifier); |
| }; |