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

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

Issue 1919383005: Small cleanup of SiteEngagementService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: const some thangs Created 4 years, 6 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
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
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
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();
dominickn 2016/05/25 06:52:43 const
calamity 2016/05/26 08:26:20 Done.
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);
dominickn 2016/05/25 06:52:43 const
calamity 2016/05/26 08:26:20 So.... I don't want this to be const because it's
dominickn 2016/05/26 09:33:20 Acknowledged.
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);
dominickn 2016/05/25 06:52:43 const
106 107
107 // Overridden from SiteEngagementScoreProvider. 108 // Overridden from SiteEngagementScoreProvider.
108 double GetScore(const GURL& url) const override; 109 double GetScore(const GURL& url) const override;
109 double GetTotalEngagementPoints() const override; 110 double GetTotalEngagementPoints() const override;
110 111
111 private: 112 private:
112 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); 113 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms);
113 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); 114 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores);
114 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs); 115 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs);
115 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement); 116 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement);
116 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints); 117 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints);
117 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints); 118 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints);
118 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); 119 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch);
119 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, 120 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest,
120 CleanupOriginsOnHistoryDeletion); 121 CleanupOriginsOnHistoryDeletion);
121 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped); 122 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped);
122 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel); 123 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel);
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);
dominickn 2016/05/25 06:52:43 const
132 133
134 // Retrieves the SiteEngagementScore object for |origin|.
135 SiteEngagementScore GetEngagementScore(const GURL& origin) const;
dominickn 2016/05/25 06:52:43 This could be in the anonymous namespace in site_e
calamity 2016/05/26 08:26:20 I'd rather not do that for two reasons: - I'd have
dominickn 2016/05/26 09:33:20 Acknowledged.
136
133 // Post startup tasks: cleaning up origins which have decayed to 0, and 137 // Post startup tasks: cleaning up origins which have decayed to 0, and
134 // logging UMA statistics. 138 // logging UMA statistics.
135 void AfterStartupTask(); 139 void AfterStartupTask();
136 void CleanupEngagementScores(); 140 void CleanupEngagementScores();
137 void RecordMetrics(); 141 void RecordMetrics();
138 142
139 // Returns the median engagement score of all recorded origins. 143 // Returns the median engagement score of all recorded origins.
140 double GetMedianEngagement(const std::map<GURL, double>& score_map) const; 144 double GetMedianEngagement(const std::map<GURL, double>& score_map) const;
141 145
142 // Update the engagement score of the origin matching |url| for media playing. 146 // Update the engagement score of the origin matching |url| for media playing.
(...skipping 20 matching lines...) Expand all
163 // respectively. 167 // respectively.
164 int OriginsWithMaxDailyEngagement() const; 168 int OriginsWithMaxDailyEngagement() const;
165 int OriginsWithMaxEngagement(const std::map<GURL, double>& score_map) const; 169 int OriginsWithMaxEngagement(const std::map<GURL, double>& score_map) const;
166 170
167 // Callback for the history service when it is asked for a map of origins to 171 // 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. 172 // how many URLs corresponding to that origin remain in history.
169 void GetCountsAndLastVisitForOriginsComplete( 173 void GetCountsAndLastVisitForOriginsComplete(
170 history::HistoryService* history_service, 174 history::HistoryService* history_service,
171 const std::multiset<GURL>& deleted_url_origins, 175 const std::multiset<GURL>& deleted_url_origins,
172 bool expired, 176 bool expired,
173 const history::OriginCountAndLastVisitMap& remaining_origin_counts); 177 const history::OriginCountAndLastVisitMap& remaining_origin_counts);
dominickn 2016/05/25 06:52:43 Can this method be const now?
calamity 2016/05/26 08:26:20 Not anymore ;)
dominickn 2016/05/26 09:33:20 Acknowledged.
174 178
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
182 Profile* profile_; 179 Profile* profile_;
183 180
184 // The clock used to vend times. 181 // The clock used to vend times.
185 std::unique_ptr<base::Clock> clock_; 182 std::unique_ptr<base::Clock> clock_;
186 183
187 // Metrics are recorded at non-incognito browser startup, and then 184 // Metrics are recorded at non-incognito browser startup, and then
188 // approximately once per hour thereafter. Store the local time at which 185 // approximately once per hour thereafter. Store the local time at which
189 // metrics were previously uploaded: the first event which affects any 186 // metrics were previously uploaded: the first event which affects any
190 // origin's engagement score after an hour has elapsed triggers the next 187 // origin's engagement score after an hour has elapsed triggers the next
191 // upload. 188 // upload.
192 base::Time last_metrics_time_; 189 base::Time last_metrics_time_;
193 190
194 base::WeakPtrFactory<SiteEngagementService> weak_factory_; 191 base::WeakPtrFactory<SiteEngagementService> weak_factory_;
195 192
196 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); 193 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService);
197 }; 194 };
198 195
199 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ 196 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698