OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 // The number of points added to engagement when a site is launched from | 54 // The number of points added to engagement when a site is launched from |
55 // homescreen or added as a bookmark app. This bonus will apply for ten days | 55 // homescreen or added as a bookmark app. This bonus will apply for ten days |
56 // following a launch; each new launch resets the ten days. | 56 // following a launch; each new launch resets the ten days. |
57 WEB_APP_INSTALLED_POINTS, | 57 WEB_APP_INSTALLED_POINTS, |
58 | 58 |
59 // The number of points given for the first engagement event of the day for | 59 // The number of points given for the first engagement event of the day for |
60 // each site. | 60 // each site. |
61 FIRST_DAILY_ENGAGEMENT, | 61 FIRST_DAILY_ENGAGEMENT, |
62 | 62 |
| 63 // The number of points that the engagement service must accumulate to be |
| 64 // considered 'useful'. |
| 65 BOOTSTRAP_POINTS, |
| 66 |
63 MAX_VARIATION | 67 MAX_VARIATION |
64 }; | 68 }; |
65 | 69 |
66 // The maximum number of points that are allowed. | 70 // The maximum number of points that are allowed. |
67 static const double kMaxPoints; | 71 static const double kMaxPoints; |
68 | 72 |
69 static double GetMaxPointsPerDay(); | 73 static double GetMaxPointsPerDay(); |
70 static double GetDecayPeriodInDays(); | 74 static double GetDecayPeriodInDays(); |
71 static double GetDecayPoints(); | 75 static double GetDecayPoints(); |
72 static double GetNavigationPoints(); | 76 static double GetNavigationPoints(); |
73 static double GetUserInputPoints(); | 77 static double GetUserInputPoints(); |
74 static double GetVisibleMediaPoints(); | 78 static double GetVisibleMediaPoints(); |
75 static double GetHiddenMediaPoints(); | 79 static double GetHiddenMediaPoints(); |
76 static double GetWebAppInstalledPoints(); | 80 static double GetWebAppInstalledPoints(); |
77 static double GetFirstDailyEngagementPoints(); | 81 static double GetFirstDailyEngagementPoints(); |
| 82 static double GetBootstrapPoints(); |
78 | 83 |
79 // Update the default engagement settings via variations. | 84 // Update the default engagement settings via variations. |
80 static void UpdateFromVariations(); | 85 static void UpdateFromVariations(); |
81 | 86 |
82 // The SiteEngagementService does not take ownership of |clock|. It is the | 87 // The SiteEngagementService does not take ownership of |clock|. It is the |
83 // responsibility of the caller to make sure |clock| outlives this | 88 // responsibility of the caller to make sure |clock| outlives this |
84 // SiteEngagementScore. | 89 // SiteEngagementScore. |
85 SiteEngagementScore(base::Clock* clock, | 90 SiteEngagementScore(base::Clock* clock, |
86 const base::DictionaryValue& score_dict); | 91 const base::DictionaryValue& score_dict); |
87 ~SiteEngagementScore(); | 92 ~SiteEngagementScore(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 195 |
191 // Returns whether or not the SiteEngagementService is enabled. | 196 // Returns whether or not the SiteEngagementService is enabled. |
192 static bool IsEnabled(); | 197 static bool IsEnabled(); |
193 | 198 |
194 explicit SiteEngagementService(Profile* profile); | 199 explicit SiteEngagementService(Profile* profile); |
195 ~SiteEngagementService() override; | 200 ~SiteEngagementService() override; |
196 | 201 |
197 // Returns a map of all stored origins and their engagement scores. | 202 // Returns a map of all stored origins and their engagement scores. |
198 std::map<GURL, double> GetScoreMap(); | 203 std::map<GURL, double> GetScoreMap(); |
199 | 204 |
| 205 // Returns whether the engagement service has enough data to make meaningful |
| 206 // decisions. Clients should avoid using engagement in their heuristic until |
| 207 // this is true. |
| 208 bool IsBootstrapped(); |
| 209 |
200 // Update the engagement score of the origin matching |url| for navigation. | 210 // Update the engagement score of the origin matching |url| for navigation. |
201 void HandleNavigation(const GURL& url, ui::PageTransition transition); | 211 void HandleNavigation(const GURL& url, ui::PageTransition transition); |
202 | 212 |
203 // Update the engagement score of the origin matching |url| for time-on-site, | 213 // Update the engagement score of the origin matching |url| for time-on-site, |
204 // based on user input. | 214 // based on user input. |
205 void HandleUserInput(const GURL& url, | 215 void HandleUserInput(const GURL& url, |
206 SiteEngagementMetrics::EngagementType type); | 216 SiteEngagementMetrics::EngagementType type); |
207 | 217 |
208 // Update the engagement score of the origin matching |url| for media playing. | 218 // Update the engagement score of the origin matching |url| for media playing. |
209 // The points awarded are discounted if the media is being played in a non- | 219 // The points awarded are discounted if the media is being played in a non- |
(...skipping 21 matching lines...) Expand all Loading... |
231 private: | 241 private: |
232 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); | 242 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); |
233 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); | 243 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); |
234 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs); | 244 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs); |
235 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement); | 245 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement); |
236 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints); | 246 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints); |
237 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints); | 247 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints); |
238 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); | 248 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); |
239 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, | 249 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, |
240 CleanupOriginsOnHistoryDeletion); | 250 CleanupOriginsOnHistoryDeletion); |
| 251 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped); |
241 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); | 252 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); |
242 | 253 |
243 // Only used in tests. | 254 // Only used in tests. |
244 SiteEngagementService(Profile* profile, scoped_ptr<base::Clock> clock); | 255 SiteEngagementService(Profile* profile, scoped_ptr<base::Clock> clock); |
245 | 256 |
246 // Adds the specified number of points to the given origin, respecting the | 257 // Adds the specified number of points to the given origin, respecting the |
247 // maximum limits for the day and overall. | 258 // maximum limits for the day and overall. |
248 void AddPoints(const GURL& url, double points); | 259 void AddPoints(const GURL& url, double points); |
249 | 260 |
250 // Post startup tasks: cleaning up origins which have decayed to 0, and | 261 // Post startup tasks: cleaning up origins which have decayed to 0, and |
(...skipping 24 matching lines...) Expand all Loading... |
275 // origin's engagement score after an hour has elapsed triggers the next | 286 // origin's engagement score after an hour has elapsed triggers the next |
276 // upload. | 287 // upload. |
277 base::Time last_metrics_time_; | 288 base::Time last_metrics_time_; |
278 | 289 |
279 base::WeakPtrFactory<SiteEngagementService> weak_factory_; | 290 base::WeakPtrFactory<SiteEngagementService> weak_factory_; |
280 | 291 |
281 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); | 292 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |
282 }; | 293 }; |
283 | 294 |
284 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 295 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
OLD | NEW |