| 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 <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class DictionaryValue; | 22 class DictionaryValue; |
| 23 class Clock; | 23 class Clock; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace history { | 26 namespace history { |
| 27 class HistoryService; | 27 class HistoryService; |
| 28 } | 28 } |
| 29 | 29 |
| 30 class GURL; | 30 class GURL; |
| 31 class Profile; | 31 class Profile; |
| 32 class SiteEngagementScore; |
| 32 | 33 |
| 33 class SiteEngagementScoreProvider { | 34 class SiteEngagementScoreProvider { |
| 34 public: | 35 public: |
| 35 // Returns a non-negative integer representing the engagement score of the | 36 // Returns a non-negative integer representing the engagement score of the |
| 36 // origin for this URL. | 37 // origin for this URL. |
| 37 virtual double GetScore(const GURL& url) const = 0; | 38 virtual double GetScore(const GURL& url) const = 0; |
| 38 | 39 |
| 39 // Returns the sum of engagement points awarded to all sites. | 40 // Returns the sum of engagement points awarded to all sites. |
| 40 virtual double GetTotalEngagementPoints() const = 0; | 41 virtual double GetTotalEngagementPoints() const = 0; |
| 41 }; | 42 }; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Returns the engagement level of |url|. This is the recommended API for | 86 // Returns the engagement level of |url|. This is the recommended API for |
| 86 // clients | 87 // clients |
| 87 EngagementLevel GetEngagementLevel(const GURL& url) const; | 88 EngagementLevel GetEngagementLevel(const GURL& url) const; |
| 88 | 89 |
| 89 // Returns a map of all stored origins and their engagement scores. | 90 // Returns a map of all stored origins and their engagement scores. |
| 90 std::map<GURL, double> GetScoreMap() const; | 91 std::map<GURL, double> GetScoreMap() const; |
| 91 | 92 |
| 92 // Returns whether the engagement service has enough data to make meaningful | 93 // Returns whether the engagement service has enough data to make meaningful |
| 93 // decisions. Clients should avoid using engagement in their heuristic until | 94 // decisions. Clients should avoid using engagement in their heuristic until |
| 94 // this is true. | 95 // this is true. |
| 95 bool IsBootstrapped(); | 96 bool IsBootstrapped() const; |
| 96 | 97 |
| 97 // Returns whether |url| has at least the given |level| of engagement. | 98 // Returns whether |url| has at least the given |level| of engagement. |
| 98 bool IsEngagementAtLeast(const GURL& url, EngagementLevel level) const; | 99 bool IsEngagementAtLeast(const GURL& url, EngagementLevel level) const; |
| 99 | 100 |
| 100 // Resets the engagement score |url| to |score|, clearing daily limits. | 101 // Resets the engagement score |url| to |score|, clearing daily limits. |
| 101 void ResetScoreForURL(const GURL& url, double score); | 102 void ResetScoreForURL(const GURL& url, double score); |
| 102 | 103 |
| 103 // Update the last time |url| was opened from an installed shortcut to be | 104 // Update the last time |url| was opened from an installed shortcut to be |
| 104 // clock_->Now(). | 105 // clock_->Now(). |
| 105 void SetLastShortcutLaunchTime(const GURL& url); | 106 void SetLastShortcutLaunchTime(const GURL& url); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 123 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms); | 124 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms); |
| 124 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); | 125 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); |
| 125 | 126 |
| 126 // Only used in tests. | 127 // Only used in tests. |
| 127 SiteEngagementService(Profile* profile, std::unique_ptr<base::Clock> clock); | 128 SiteEngagementService(Profile* profile, std::unique_ptr<base::Clock> clock); |
| 128 | 129 |
| 129 // Adds the specified number of points to the given origin, respecting the | 130 // Adds the specified number of points to the given origin, respecting the |
| 130 // maximum limits for the day and overall. | 131 // maximum limits for the day and overall. |
| 131 void AddPoints(const GURL& url, double points); | 132 void AddPoints(const GURL& url, double points); |
| 132 | 133 |
| 134 // Retrieves the SiteEngagementScore object for |origin|. |
| 135 SiteEngagementScore CreateEngagementScore(const GURL& origin); |
| 136 const SiteEngagementScore CreateEngagementScore(const GURL& origin) const; |
| 137 |
| 133 // Post startup tasks: cleaning up origins which have decayed to 0, and | 138 // Post startup tasks: cleaning up origins which have decayed to 0, and |
| 134 // logging UMA statistics. | 139 // logging UMA statistics. |
| 135 void AfterStartupTask(); | 140 void AfterStartupTask(); |
| 136 void CleanupEngagementScores(); | 141 void CleanupEngagementScores(); |
| 137 void RecordMetrics(); | 142 void RecordMetrics(); |
| 138 | 143 |
| 139 // Returns the median engagement score of all recorded origins. | 144 // Returns the median engagement score of all recorded origins. |
| 140 double GetMedianEngagement(const std::map<GURL, double>& score_map) const; | 145 double GetMedianEngagement(const std::map<GURL, double>& score_map) const; |
| 141 | 146 |
| 142 // Update the engagement score of the origin matching |url| for media playing. | 147 // Update the engagement score of the origin matching |url| for media playing. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 160 const std::set<GURL>& favicon_urls) override; | 165 const std::set<GURL>& favicon_urls) override; |
| 161 | 166 |
| 162 // Returns the number of origins with maximum daily and total engagement | 167 // Returns the number of origins with maximum daily and total engagement |
| 163 // respectively. | 168 // respectively. |
| 164 int OriginsWithMaxDailyEngagement() const; | 169 int OriginsWithMaxDailyEngagement() const; |
| 165 int OriginsWithMaxEngagement(const std::map<GURL, double>& score_map) const; | 170 int OriginsWithMaxEngagement(const std::map<GURL, double>& score_map) const; |
| 166 | 171 |
| 167 // Callback for the history service when it is asked for a map of origins to | 172 // Callback for the history service when it is asked for a map of origins to |
| 168 // how many URLs corresponding to that origin remain in history. | 173 // how many URLs corresponding to that origin remain in history. |
| 169 void GetCountsAndLastVisitForOriginsComplete( | 174 void GetCountsAndLastVisitForOriginsComplete( |
| 170 history::HistoryService* history_service, | 175 history::HistoryService* history_service, |
| 171 const std::multiset<GURL>& deleted_url_origins, | 176 const std::multiset<GURL>& deleted_url_origins, |
| 172 bool expired, | 177 bool expired, |
| 173 const history::OriginCountAndLastVisitMap& remaining_origin_counts); | 178 const history::OriginCountAndLastVisitMap& remaining_origin_counts); |
| 174 | |
| 175 // Resets the engagement score for |url| to |score|, and sets the last | |
| 176 // engagement time and last shortcut launch time (if it is non-null) to | |
| 177 // |updated_time|. Clears daily limits. | |
| 178 void ResetScoreAndAccessTimesForURL(const GURL& url, | |
| 179 double score, | |
| 180 const base::Time* updated_time); | |
| 181 | 179 |
| 182 Profile* profile_; | 180 Profile* profile_; |
| 183 | 181 |
| 184 // The clock used to vend times. | 182 // The clock used to vend times. |
| 185 std::unique_ptr<base::Clock> clock_; | 183 std::unique_ptr<base::Clock> clock_; |
| 186 | 184 |
| 187 // Metrics are recorded at non-incognito browser startup, and then | 185 // Metrics are recorded at non-incognito browser startup, and then |
| 188 // approximately once per hour thereafter. Store the local time at which | 186 // approximately once per hour thereafter. Store the local time at which |
| 189 // metrics were previously uploaded: the first event which affects any | 187 // metrics were previously uploaded: the first event which affects any |
| 190 // origin's engagement score after an hour has elapsed triggers the next | 188 // origin's engagement score after an hour has elapsed triggers the next |
| 191 // upload. | 189 // upload. |
| 192 base::Time last_metrics_time_; | 190 base::Time last_metrics_time_; |
| 193 | 191 |
| 194 base::WeakPtrFactory<SiteEngagementService> weak_factory_; | 192 base::WeakPtrFactory<SiteEngagementService> weak_factory_; |
| 195 | 193 |
| 196 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); | 194 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |
| 197 }; | 195 }; |
| 198 | 196 |
| 199 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 197 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
| OLD | NEW |