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

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

Issue 1908443003: Set site engagement timestamps to privacy-respectful values when history is cleared. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/engagement/site_engagement_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 9 #include <set>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/engagement/site_engagement_metrics.h" 15 #include "chrome/browser/engagement/site_engagement_metrics.h"
16 #include "components/history/core/browser/history_service_observer.h" 16 #include "components/history/core/browser/history_service_observer.h"
17 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
18 #include "ui/base/page_transition_types.h" 18 #include "ui/base/page_transition_types.h"
19 19
20 namespace base { 20 namespace base {
21 class DictionaryValue; 21 class DictionaryValue;
22 class Clock; 22 class Clock;
23 } 23 }
24 24
25 namespace history {
26 class HistoryService;
27 }
28
25 class GURL; 29 class GURL;
26 class Profile; 30 class Profile;
27 31
28 class SiteEngagementScore { 32 class SiteEngagementScore {
29 public: 33 public:
30 // The parameters which can be varied via field trial. All "points" values 34 // The parameters which can be varied via field trial. All "points" values
31 // should be appended to the end of the enum prior to MAX_VARIATION. 35 // should be appended to the end of the enum prior to MAX_VARIATION.
32 enum Variation { 36 enum Variation {
33 // The maximum number of points that can be accrued in one day. 37 // The maximum number of points that can be accrued in one day.
34 MAX_POINTS_PER_DAY = 0, 38 MAX_POINTS_PER_DAY = 0,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // The SiteEngagementService does not take ownership of |clock|. It is the 98 // The SiteEngagementService does not take ownership of |clock|. It is the
95 // responsibility of the caller to make sure |clock| outlives this 99 // responsibility of the caller to make sure |clock| outlives this
96 // SiteEngagementScore. 100 // SiteEngagementScore.
97 SiteEngagementScore(base::Clock* clock, 101 SiteEngagementScore(base::Clock* clock,
98 const base::DictionaryValue& score_dict); 102 const base::DictionaryValue& score_dict);
99 ~SiteEngagementScore(); 103 ~SiteEngagementScore();
100 104
101 double Score() const; 105 double Score() const;
102 void AddPoints(double points); 106 void AddPoints(double points);
103 107
104 // Resets the score to |points| and reset the daily point limit. 108 // Resets the score to |points| and resets the daily point limit. If
105 void Reset(double points); 109 // |updated_time| is non-null, sets the last engagement time and last
110 // shortcut launch time (if it is non-null) to |updated_time|. Otherwise, last
111 // engagement time is set to the current time and last shortcut launch time is
112 // left unchanged.
113 // TODO(calamity): Ideally, all SiteEngagementScore methods should take a
114 // base::Time argument like this one does rather than each Score hold a
115 // pointer to a base::Clock. Then SiteEngagementScore doesn't need to worry
116 // about clock vending. See crbug.com/604305
117 void Reset(double points, const base::Time* updated_time);
106 118
107 // Returns true if the maximum number of points today has been added. 119 // Returns true if the maximum number of points today has been added.
108 bool MaxPointsPerDayAdded() const; 120 bool MaxPointsPerDayAdded() const;
109 121
110 // Get/set the last time this origin was launched from an installed shortcut. 122 // Get/set the last time this origin was launched from an installed shortcut.
111 base::Time last_shortcut_launch_time() const { 123 base::Time last_shortcut_launch_time() const {
112 return last_shortcut_launch_time_; 124 return last_shortcut_launch_time_;
113 } 125 }
114 void set_last_shortcut_launch_time(const base::Time& time) { 126 void set_last_shortcut_launch_time(const base::Time& time) {
115 last_shortcut_launch_time_ = time; 127 last_shortcut_launch_time_ = time;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 void RecordMetrics(); 303 void RecordMetrics();
292 304
293 // Returns the median engagement score of all recorded origins. 305 // Returns the median engagement score of all recorded origins.
294 double GetMedianEngagement(const std::map<GURL, double>& score_map) const; 306 double GetMedianEngagement(const std::map<GURL, double>& score_map) const;
295 307
296 // Returns the number of origins with maximum daily and total engagement 308 // Returns the number of origins with maximum daily and total engagement
297 // respectively. 309 // respectively.
298 int OriginsWithMaxDailyEngagement() const; 310 int OriginsWithMaxDailyEngagement() const;
299 int OriginsWithMaxEngagement(const std::map<GURL, double>& score_map) const; 311 int OriginsWithMaxEngagement(const std::map<GURL, double>& score_map) const;
300 312
301 void GetCountsForOriginsComplete( 313 void GetCountsAndLastVisitForOriginsComplete(
314 history::HistoryService* history_service,
302 const std::multiset<GURL>& deleted_url_origins, 315 const std::multiset<GURL>& deleted_url_origins,
303 bool expired, 316 bool expired,
304 const history::OriginCountMap& remaining_origin_counts); 317 const history::OriginCountAndLastVisitMap& remaining_origin_counts);
318
319 // Resets the engagement score for |url| to |score|, and sets the last
320 // engagement time and last shortcut launch time (if it is non-null) to
321 // |updated_time|. Clears daily limits.
322 void ResetScoreAndAccessTimesForURL(const GURL& url,
323 double score,
324 const base::Time* updated_time);
305 325
306 Profile* profile_; 326 Profile* profile_;
307 327
308 // The clock used to vend times. 328 // The clock used to vend times.
309 scoped_ptr<base::Clock> clock_; 329 scoped_ptr<base::Clock> clock_;
310 330
311 // Metrics are recorded at non-incognito browser startup, and then 331 // Metrics are recorded at non-incognito browser startup, and then
312 // approximately once per hour thereafter. Store the local time at which 332 // approximately once per hour thereafter. Store the local time at which
313 // metrics were previously uploaded: the first event which affects any 333 // metrics were previously uploaded: the first event which affects any
314 // origin's engagement score after an hour has elapsed triggers the next 334 // origin's engagement score after an hour has elapsed triggers the next
315 // upload. 335 // upload.
316 base::Time last_metrics_time_; 336 base::Time last_metrics_time_;
317 337
318 base::WeakPtrFactory<SiteEngagementService> weak_factory_; 338 base::WeakPtrFactory<SiteEngagementService> weak_factory_;
319 339
320 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); 340 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService);
321 }; 341 };
322 342
323 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ 343 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/engagement/site_engagement_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698