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

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

Issue 2082953002: Prevent site engagement scores from decaying when Chrome isn't in use. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs); 119 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs);
120 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement); 120 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement);
121 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints); 121 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints);
122 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints); 122 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints);
123 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); 123 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch);
124 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, 124 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest,
125 CleanupOriginsOnHistoryDeletion); 125 CleanupOriginsOnHistoryDeletion);
126 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped); 126 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped);
127 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel); 127 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel);
128 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms); 128 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms);
129 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest,
130 PersistLastEngagementTime);
129 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); 131 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger);
130 132
131 // Only used in tests. 133 // Only used in tests.
132 SiteEngagementService(Profile* profile, std::unique_ptr<base::Clock> clock); 134 SiteEngagementService(Profile* profile, std::unique_ptr<base::Clock> clock);
133 135
134 // Adds the specified number of points to the given origin, respecting the 136 // Adds the specified number of points to the given origin, respecting the
135 // maximum limits for the day and overall. 137 // maximum limits for the day and overall.
136 void AddPoints(const GURL& url, double points); 138 void AddPoints(const GURL& url, double points);
137 139
138 // Retrieves the SiteEngagementScore object for |origin|. 140 // Retrieves the SiteEngagementScore object for |origin|.
139 SiteEngagementScore CreateEngagementScore(const GURL& origin); 141 SiteEngagementScore CreateEngagementScore(const GURL& origin);
140 const SiteEngagementScore CreateEngagementScore(const GURL& origin) const; 142 const SiteEngagementScore CreateEngagementScore(const GURL& origin) const;
141 143
142 // Post startup tasks: cleaning up origins which have decayed to 0, and 144 // Runs site engagement maintenance tasks.
143 // logging UMA statistics.
144 void AfterStartupTask(); 145 void AfterStartupTask();
145 void CleanupEngagementScores(); 146
147 // Removes any origins which have decayed to 0 engagement. If
148 // |update_last_engagement_time| is true, the last engagement time of all
149 // origins is reset by calculating the delta between the last engagement event
150 // recorded by the site engagement service and the origin. The origin's last
151 // engagement time is then set to clock_->Now() - delta.
152 //
153 // If a user does not use the browser at all for some period of time,
154 // engagement is not decayed, and the state is restored equivalent to how they
155 // left it once they return.
156 void CleanupEngagementScores(bool update_last_engagement_time);
157
158 // Records UMA metrics.
146 void RecordMetrics(); 159 void RecordMetrics();
147 160
148 // Returns the median engagement score of all recorded origins. 161 // Returns the median engagement score of all recorded origins.
149 double GetMedianEngagement(const std::map<GURL, double>& score_map) const; 162 double GetMedianEngagement(const std::map<GURL, double>& score_map) const;
150 163
151 // Update the engagement score of the origin loaded in |web_contents| for 164 // Update the engagement score of the origin loaded in |web_contents| for
152 // media playing. The points awarded are discounted if the media is being 165 // media playing. The points awarded are discounted if the media is being
153 // played in a non-visible tab. 166 // played in a non-visible tab.
154 void HandleMediaPlaying(content::WebContents* web_contents, bool is_hidden); 167 void HandleMediaPlaying(content::WebContents* web_contents, bool is_hidden);
155 168
156 // Update the engagement score of the origin loaded in |web_contents| for 169 // Update the engagement score of the origin loaded in |web_contents| for
157 // navigation. 170 // navigation.
158 void HandleNavigation(content::WebContents* web_contents, 171 void HandleNavigation(content::WebContents* web_contents,
159 ui::PageTransition transition); 172 ui::PageTransition transition);
160 173
161 // Update the engagement score of the origin loaded in |web_contents| for 174 // Update the engagement score of the origin loaded in |web_contents| for
162 // time-on-site, based on user input. 175 // time-on-site, based on user input.
163 void HandleUserInput(content::WebContents* web_contents, 176 void HandleUserInput(content::WebContents* web_contents,
164 SiteEngagementMetrics::EngagementType type); 177 SiteEngagementMetrics::EngagementType type);
165 178
179 // Returns true if the last engagement increasing event seen by the site
180 // engagement service was sufficiently long ago that we need to reset all
181 // scores to be relative to now. This ensures that users who do not use Chrome
182 // at all for an extended period of time do not have their engagement decay.
183 bool IsLastEngagementObsolete();
184
166 // Overridden from history::HistoryServiceObserver: 185 // Overridden from history::HistoryServiceObserver:
167 void OnURLsDeleted(history::HistoryService* history_service, 186 void OnURLsDeleted(history::HistoryService* history_service,
168 bool all_history, 187 bool all_history,
169 bool expired, 188 bool expired,
170 const history::URLRows& deleted_rows, 189 const history::URLRows& deleted_rows,
171 const std::set<GURL>& favicon_urls) override; 190 const std::set<GURL>& favicon_urls) override;
172 191
173 // Returns the number of origins with maximum daily and total engagement 192 // Returns the number of origins with maximum daily and total engagement
174 // respectively. 193 // respectively.
175 int OriginsWithMaxDailyEngagement() const; 194 int OriginsWithMaxDailyEngagement() const;
(...skipping 12 matching lines...) Expand all
188 // The clock used to vend times. 207 // The clock used to vend times.
189 std::unique_ptr<base::Clock> clock_; 208 std::unique_ptr<base::Clock> clock_;
190 209
191 // Metrics are recorded at non-incognito browser startup, and then 210 // Metrics are recorded at non-incognito browser startup, and then
192 // approximately once per hour thereafter. Store the local time at which 211 // approximately once per hour thereafter. Store the local time at which
193 // metrics were previously uploaded: the first event which affects any 212 // metrics were previously uploaded: the first event which affects any
194 // origin's engagement score after an hour has elapsed triggers the next 213 // origin's engagement score after an hour has elapsed triggers the next
195 // upload. 214 // upload.
196 base::Time last_metrics_time_; 215 base::Time last_metrics_time_;
197 216
217 // Keep track of the last time any engagement was recorded. If this date is
218 // too far in the past, assume that the user has not been using Chrome, and
219 // ensure that scores are not decayed as usual.
220 base::Time last_engagement_time_;
221
198 base::WeakPtrFactory<SiteEngagementService> weak_factory_; 222 base::WeakPtrFactory<SiteEngagementService> weak_factory_;
199 223
200 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); 224 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService);
201 }; 225 };
202 226
203 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ 227 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698