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

Side by Side Diff: chrome/browser/engagement/site_engagement_score.h

Issue 1975723002: Reduce the site engagement service public interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Push messaging now uses engagement Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_
6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_
7
8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h"
10 #include "base/time/time.h"
11 #include "base/values.h"
12
13 namespace base {
14 class Clock;
15 }
16
17 class SiteEngagementScore {
18 public:
19 // The parameters which can be varied via field trial. All "points" values
20 // should be appended to the end of the enum prior to MAX_VARIATION.
21 enum Variation {
22 // The maximum number of points that can be accrued in one day.
23 MAX_POINTS_PER_DAY = 0,
24
25 // The period over which site engagement decays.
26 DECAY_PERIOD_IN_DAYS,
27
28 // The number of points to decay per period.
29 DECAY_POINTS,
30
31 // The number of points given for navigations.
32 NAVIGATION_POINTS,
33
34 // The number of points given for user input.
35 USER_INPUT_POINTS,
36
37 // The number of points given for media playing. Initially calibrated such
38 // that at least 30 minutes of foreground media would be required to allow a
39 // site to reach the daily engagement maximum.
40 VISIBLE_MEDIA_POINTS,
41 HIDDEN_MEDIA_POINTS,
42
43 // The number of points added to engagement when a site is launched from
44 // homescreen or added as a bookmark app. This bonus will apply for ten days
45 // following a launch; each new launch resets the ten days.
46 WEB_APP_INSTALLED_POINTS,
47
48 // The number of points given for the first engagement event of the day for
49 // each site.
50 FIRST_DAILY_ENGAGEMENT,
51
52 // The number of points that the engagement service must accumulate to be
53 // considered 'useful'.
54 BOOTSTRAP_POINTS,
55
56 // The boundaries between low/medium and medium/high engagement as returned
57 // by GetEngagementLevel().
58 MEDIUM_ENGAGEMENT_BOUNDARY,
59 HIGH_ENGAGEMENT_BOUNDARY,
60
61 MAX_VARIATION
62 };
63
64 // The maximum number of points that are allowed.
65 static const double kMaxPoints;
66
67 static double GetMaxPointsPerDay();
68 static double GetDecayPeriodInDays();
69 static double GetDecayPoints();
70 static double GetNavigationPoints();
71 static double GetUserInputPoints();
72 static double GetVisibleMediaPoints();
73 static double GetHiddenMediaPoints();
74 static double GetWebAppInstalledPoints();
75 static double GetFirstDailyEngagementPoints();
76 static double GetBootstrapPoints();
77 static double GetMediumEngagementBoundary();
78 static double GetHighEngagementBoundary();
79
80 // Update the default engagement settings via variations.
81 static void UpdateFromVariations(const char* param_name);
82
83 // The SiteEngagementScore does not take ownership of |clock|. It is the
84 // responsibility of the caller to make sure |clock| outlives this
85 // SiteEngagementScore.
86 SiteEngagementScore(base::Clock* clock,
87 const base::DictionaryValue& score_dict);
88 ~SiteEngagementScore();
89
90 // Adds |points| to this score, respecting daily limits and the maximum
91 // possible score. Decays the score if it has not been updated recently
92 // enough.
93 void AddPoints(double points);
94 double GetScore() const;
95
96 // Returns true if the maximum number of points today has been added.
97 bool MaxPointsPerDayAdded() const;
98
99 // Resets the score to |points| and resets the daily point limit. If
100 // |updated_time| is non-null, sets the last engagement time and last
101 // shortcut launch time (if it is non-null) to |updated_time|. Otherwise, last
102 // engagement time is set to the current time and last shortcut launch time is
103 // left unchanged.
104 // TODO(calamity): Ideally, all SiteEngagementScore methods should take a
105 // base::Time argument like this one does rather than each SiteEngagementScore
106 // hold a pointer to a base::Clock. Then SiteEngagementScore doesn't need to
107 // worry about clock vending. See crbug.com/604305.
108 void Reset(double points, const base::Time* updated_time);
109
110 // Updates the content settings dictionary |score_dict| with the current score
111 // fields. Returns true if |score_dict| changed, otherwise return false.
112 bool UpdateScoreDict(base::DictionaryValue* score_dict);
113
114 // Get/set the last time this origin was launched from an installed shortcut.
115 base::Time last_shortcut_launch_time() const {
116 return last_shortcut_launch_time_;
117 }
118 void set_last_shortcut_launch_time(const base::Time& time) {
119 last_shortcut_launch_time_ = time;
120 }
121
122 private:
123 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PartiallyEmptyDictionary);
124 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary);
125 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset);
126 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, FirstDailyEngagementBonus);
127 friend class ImportantSitesUtilTest;
128 friend class SiteEngagementHelperTest;
129 friend class SiteEngagementScoreTest;
130 friend class SiteEngagementServiceTest;
131
132 // Array holding the values corresponding to each item in Variation array.
133 static double param_values[];
134
135 // Keys used in the content settings dictionary.
136 static const char* kRawScoreKey;
137 static const char* kPointsAddedTodayKey;
138 static const char* kLastEngagementTimeKey;
139 static const char* kLastShortcutLaunchTimeKey;
140
141 // This version of the constructor is used in unit tests.
142 explicit SiteEngagementScore(base::Clock* clock);
143
144 // Determine the score, accounting for any decay.
145 double DecayedScore() const;
146
147 // Determine any score bonus from having installed shortcuts.
148 double BonusScore() const;
149
150 // Sets fixed parameter values for testing site engagement. Ensure that any
151 // newly added parameters receive a fixed value here.
152 static void SetParamValuesForTesting();
153
154 // The clock used to vend times. Enables time travelling in tests. Owned by
155 // the SiteEngagementService.
156 base::Clock* clock_;
157
158 // |raw_score_| is the score before any decay is applied.
159 double raw_score_;
160
161 // The points added 'today' are tracked to avoid adding more than
162 // kMaxPointsPerDay on any one day. 'Today' is defined in local time.
163 double points_added_today_;
164
165 // The last time the score was updated for engagement. Used in conjunction
166 // with |points_added_today_| to avoid adding more than kMaxPointsPerDay on
167 // any one day.
168 base::Time last_engagement_time_;
169
170 // The last time the site with this score was launched from an installed
171 // shortcut.
172 base::Time last_shortcut_launch_time_;
173
174 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore);
175 };
176
177 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_helper_unittest.cc ('k') | chrome/browser/engagement/site_engagement_score.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698