| 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. |
| 207 bool IsBootstrapped(); |
| 208 |
| 200 // Update the engagement score of the origin matching |url| for navigation. | 209 // Update the engagement score of the origin matching |url| for navigation. |
| 201 void HandleNavigation(const GURL& url, ui::PageTransition transition); | 210 void HandleNavigation(const GURL& url, ui::PageTransition transition); |
| 202 | 211 |
| 203 // Update the engagement score of the origin matching |url| for time-on-site, | 212 // Update the engagement score of the origin matching |url| for time-on-site, |
| 204 // based on user input. | 213 // based on user input. |
| 205 void HandleUserInput(const GURL& url, | 214 void HandleUserInput(const GURL& url, |
| 206 SiteEngagementMetrics::EngagementType type); | 215 SiteEngagementMetrics::EngagementType type); |
| 207 | 216 |
| 208 // Update the engagement score of the origin matching |url| for media playing. | 217 // 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- | 218 // The points awarded are discounted if the media is being played in a non- |
| (...skipping 21 matching lines...) Expand all Loading... |
| 231 private: | 240 private: |
| 232 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); | 241 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); |
| 233 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); | 242 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); |
| 234 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs); | 243 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs); |
| 235 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement); | 244 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement); |
| 236 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints); | 245 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints); |
| 237 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints); | 246 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints); |
| 238 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); | 247 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); |
| 239 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, | 248 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, |
| 240 CleanupOriginsOnHistoryDeletion); | 249 CleanupOriginsOnHistoryDeletion); |
| 250 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped); |
| 241 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); | 251 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); |
| 242 | 252 |
| 243 // Only used in tests. | 253 // Only used in tests. |
| 244 SiteEngagementService(Profile* profile, scoped_ptr<base::Clock> clock); | 254 SiteEngagementService(Profile* profile, scoped_ptr<base::Clock> clock); |
| 245 | 255 |
| 246 // Adds the specified number of points to the given origin, respecting the | 256 // Adds the specified number of points to the given origin, respecting the |
| 247 // maximum limits for the day and overall. | 257 // maximum limits for the day and overall. |
| 248 void AddPoints(const GURL& url, double points); | 258 void AddPoints(const GURL& url, double points); |
| 249 | 259 |
| 250 // Post startup tasks: cleaning up origins which have decayed to 0, and | 260 // 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 | 285 // origin's engagement score after an hour has elapsed triggers the next |
| 276 // upload. | 286 // upload. |
| 277 base::Time last_metrics_time_; | 287 base::Time last_metrics_time_; |
| 278 | 288 |
| 279 base::WeakPtrFactory<SiteEngagementService> weak_factory_; | 289 base::WeakPtrFactory<SiteEngagementService> weak_factory_; |
| 280 | 290 |
| 281 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); | 291 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |
| 282 }; | 292 }; |
| 283 | 293 |
| 284 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 294 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
| OLD | NEW |