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 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ | 5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ |
6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ | 6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 | 56 |
57 // The number of points that the engagement service must accumulate to be | 57 // The number of points that the engagement service must accumulate to be |
58 // considered 'useful'. | 58 // considered 'useful'. |
59 BOOTSTRAP_POINTS, | 59 BOOTSTRAP_POINTS, |
60 | 60 |
61 // The boundaries between low/medium and medium/high engagement as returned | 61 // The boundaries between low/medium and medium/high engagement as returned |
62 // by GetEngagementLevel(). | 62 // by GetEngagementLevel(). |
63 MEDIUM_ENGAGEMENT_BOUNDARY, | 63 MEDIUM_ENGAGEMENT_BOUNDARY, |
64 HIGH_ENGAGEMENT_BOUNDARY, | 64 HIGH_ENGAGEMENT_BOUNDARY, |
65 | 65 |
66 // If this many hours passes with no engagement of any kind, the next | |
67 // points-adding event (or browser startup) will reset each score's last | |
68 // engagement time to prevent decay when Chrome isn't in use. Times are set | |
69 // to (now - (overall_last_engagement_time - score_last_engagement_time)). | |
70 // This value MUST be at least one second greater than the decay period. | |
71 OBSOLETE_LAST_ENGAGEMENT_PERIOD_IN_HOURS, | |
calamity
2016/06/23 05:18:40
This name is weird. It makes it look like this is
dominickn
2016/06/27 02:53:34
Done.
| |
72 | |
66 MAX_VARIATION | 73 MAX_VARIATION |
67 }; | 74 }; |
68 | 75 |
69 // The maximum number of points that are allowed. | 76 // The maximum number of points that are allowed. |
70 static const double kMaxPoints; | 77 static const double kMaxPoints; |
71 | 78 |
72 static double GetMaxPointsPerDay(); | 79 static double GetMaxPointsPerDay(); |
73 static double GetDecayPeriodInDays(); | 80 static double GetDecayPeriodInDays(); |
74 static double GetDecayPoints(); | 81 static double GetDecayPoints(); |
75 static double GetNavigationPoints(); | 82 static double GetNavigationPoints(); |
76 static double GetUserInputPoints(); | 83 static double GetUserInputPoints(); |
77 static double GetVisibleMediaPoints(); | 84 static double GetVisibleMediaPoints(); |
78 static double GetHiddenMediaPoints(); | 85 static double GetHiddenMediaPoints(); |
79 static double GetWebAppInstalledPoints(); | 86 static double GetWebAppInstalledPoints(); |
80 static double GetFirstDailyEngagementPoints(); | 87 static double GetFirstDailyEngagementPoints(); |
81 static double GetBootstrapPoints(); | 88 static double GetBootstrapPoints(); |
82 static double GetMediumEngagementBoundary(); | 89 static double GetMediumEngagementBoundary(); |
83 static double GetHighEngagementBoundary(); | 90 static double GetHighEngagementBoundary(); |
91 static double GetObsoleteLastEngagementPeriodInHours(); | |
84 | 92 |
85 // Update the default engagement settings via variations. | 93 // Update the default engagement settings via variations. |
86 static void UpdateFromVariations(const char* param_name); | 94 static void UpdateFromVariations(const char* param_name); |
87 | 95 |
88 // The SiteEngagementScore does not take ownership of |clock|. It is the | 96 // The SiteEngagementScore does not take ownership of |clock|. It is the |
89 // responsibility of the caller to make sure |clock| outlives this | 97 // responsibility of the caller to make sure |clock| outlives this |
90 // SiteEngagementScore. | 98 // SiteEngagementScore. |
91 SiteEngagementScore(base::Clock* clock, | 99 SiteEngagementScore(base::Clock* clock, |
92 const GURL& origin, | 100 const GURL& origin, |
93 HostContentSettingsMap* settings_map); | 101 HostContentSettingsMap* settings_map); |
94 SiteEngagementScore(SiteEngagementScore&& other); | 102 SiteEngagementScore(SiteEngagementScore&& other); |
95 ~SiteEngagementScore(); | 103 ~SiteEngagementScore(); |
96 | 104 |
97 SiteEngagementScore& operator=(SiteEngagementScore&& other); | 105 SiteEngagementScore& operator=(SiteEngagementScore&& other); |
98 | 106 |
99 // Adds |points| to this score, respecting daily limits and the maximum | 107 // Adds |points| to this score, respecting daily limits and the maximum |
100 // possible score. Decays the score if it has not been updated recently | 108 // possible score. Decays the score if it has not been updated recently |
101 // enough. | 109 // enough. |
102 void AddPoints(double points); | 110 void AddPoints(double points); |
103 double GetScore() const; | 111 double GetScore() const; |
104 | 112 |
105 // Writes the values in this score into |settings_map_|. | 113 // Writes the values in this score into |settings_map_|. |
106 void Commit(); | 114 void Commit(); |
107 | 115 |
108 // Returns true if the maximum number of points today has been added. | 116 // Returns true if the maximum number of points today has been added. |
109 bool MaxPointsPerDayAdded() const; | 117 bool MaxPointsPerDayAdded() const; |
110 | 118 |
111 // Resets the score to |points| and resets the daily point limit. If | 119 // Resets the score to |points| and resets the daily point limit. If |
112 // |updated_time| is non-null, sets the last engagement time and last | 120 // |updated_time| is non-null, sets the last engagement time to that value. |
113 // shortcut launch time (if it is non-null) to |updated_time|. Otherwise, last | |
114 // engagement time is set to the current time and last shortcut launch time is | |
115 // left unchanged. | |
116 void Reset(double points, const base::Time updated_time); | 121 void Reset(double points, const base::Time updated_time); |
117 | 122 |
118 // Get/set the last time this origin was launched from an installed shortcut. | 123 // Get/set the last time this origin was launched from an installed shortcut. |
119 base::Time last_shortcut_launch_time() const { | 124 base::Time last_shortcut_launch_time() const { |
120 return last_shortcut_launch_time_; | 125 return last_shortcut_launch_time_; |
121 } | 126 } |
122 void set_last_shortcut_launch_time(const base::Time& time) { | 127 void set_last_shortcut_launch_time(const base::Time& time) { |
123 last_shortcut_launch_time_ = time; | 128 last_shortcut_launch_time_ = time; |
124 } | 129 } |
125 | 130 |
131 // Get/set the last time this origin recorded an engagement change. | |
132 base::Time last_engagement_time() const { | |
133 return last_engagement_time_; | |
134 } | |
135 void set_last_engagement_time(const base::Time& time) { | |
136 last_engagement_time_ = time; | |
137 } | |
138 | |
126 private: | 139 private: |
127 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PartiallyEmptyDictionary); | 140 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PartiallyEmptyDictionary); |
128 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary); | 141 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary); |
129 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset); | 142 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset); |
130 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, FirstDailyEngagementBonus); | 143 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, FirstDailyEngagementBonus); |
131 friend class ImportantSitesUtilTest; | 144 friend class ImportantSitesUtilTest; |
132 friend class SiteEngagementHelperTest; | 145 friend class SiteEngagementHelperTest; |
133 friend class SiteEngagementScoreTest; | 146 friend class SiteEngagementScoreTest; |
134 friend class SiteEngagementServiceTest; | 147 friend class SiteEngagementServiceTest; |
135 | 148 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 // The origin this score represents. | 199 // The origin this score represents. |
187 GURL origin_; | 200 GURL origin_; |
188 | 201 |
189 // The settings map to write this score to when Commit() is called. | 202 // The settings map to write this score to when Commit() is called. |
190 HostContentSettingsMap* settings_map_; | 203 HostContentSettingsMap* settings_map_; |
191 | 204 |
192 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); | 205 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); |
193 }; | 206 }; |
194 | 207 |
195 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ | 208 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ |
OLD | NEW |