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

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

Issue 1338603002: Implement a site engagement score based on time-on-site. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore unit tests to test navigations Created 5 years, 3 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 "base/gtest_prod_util.h" 8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/time/default_clock.h" 10 #include "base/time/default_clock.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "components/keyed_service/core/keyed_service.h" 12 #include "components/keyed_service/core/keyed_service.h"
13 #include "ui/base/page_transition_types.h"
13 14
14 namespace base { 15 namespace base {
15 class DictionaryValue; 16 class DictionaryValue;
16 } 17 }
17 18
18 class GURL; 19 class GURL;
19 class Profile; 20 class Profile;
20 21
21 class SiteEngagementScore { 22 class SiteEngagementScore {
22 public: 23 public:
23 // Keys used in the content settings dictionary. 24 // Keys used in the content settings dictionary.
24 static const char* kRawScoreKey; 25 static const char* kRawScoreKey;
25 static const char* kPointsAddedTodayKey; 26 static const char* kPointsAddedTodayKey;
26 static const char* kLastEngagementTimeKey; 27 static const char* kLastEngagementTimeKey;
27 28
28 // The maximum number of points that are allowed. 29 // The maximum number of points that are allowed.
29 static const double kMaxPoints; 30 static const double kMaxPoints;
30 31
31 // The maximum number of points that can be accrued in one day. 32 // The maximum number of points that can be accrued in one day.
32 static const double kMaxPointsPerDay; 33 static const double kMaxPointsPerDay;
33 34
34 // The number of points given for a navigation. 35 // The number of points given for navigations.
35 static const double kNavigationPoints; 36 static const double kNavigationPoints;
36 37
38 // The number of points given for user input (indicating time-on-site).
39 static const double kUserInputPoints;
40
37 // Decaying works by removing a portion of the score periodically. This 41 // Decaying works by removing a portion of the score periodically. This
38 // constant determines how often that happens. 42 // constant determines how often that happens.
39 static const int kDecayPeriodInDays; 43 static const int kDecayPeriodInDays;
40 44
41 // How much the score decays after every kDecayPeriodInDays. 45 // How much the score decays after every kDecayPeriodInDays.
42 static const double kDecayPoints; 46 static const double kDecayPoints;
43 47
44 // The SiteEngagementService does not take ownership of |clock|. It is the 48 // The SiteEngagementService does not take ownership of |clock|. It is the
45 // responsibility of the caller to make sure |clock| outlives this 49 // responsibility of the caller to make sure |clock| outlives this
46 // SiteEngagementScore. 50 // SiteEngagementScore.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // any one day. 84 // any one day.
81 base::Time last_engagement_time_; 85 base::Time last_engagement_time_;
82 86
83 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); 87 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore);
84 }; 88 };
85 89
86 class SiteEngagementScoreProvider { 90 class SiteEngagementScoreProvider {
87 public: 91 public:
88 // Returns a non-negative integer representing the engagement score of the 92 // Returns a non-negative integer representing the engagement score of the
89 // origin for this URL. 93 // origin for this URL.
90 virtual int GetScore(const GURL& url) = 0; 94 virtual double GetScore(const GURL& url) = 0;
91 95
92 // Returns the sum of engagement points awarded to all sites. 96 // Returns the sum of engagement points awarded to all sites.
93 virtual int GetTotalEngagementPoints() = 0; 97 virtual double GetTotalEngagementPoints() = 0;
94 }; 98 };
95 99
96 // Stores and retrieves the engagement score of an origin. 100 // Stores and retrieves the engagement score of an origin.
97 // 101 //
98 // An engagement score is a positive integer that represents how much a user has 102 // An engagement score is a positive integer that represents how much a user has
99 // engaged with an origin - the higher it is, the more engagement the user has 103 // engaged with an origin - the higher it is, the more engagement the user has
100 // had with this site recently. 104 // had with this site recently.
101 // 105 //
102 // Positive user activity, such as visiting the origin often and adding it to 106 // Positive user activity, such as visiting the origin often and adding it to
103 // the homescreen, will increase the site engagement score. Negative activity, 107 // the homescreen, will increase the site engagement score. Negative activity,
104 // such as rejecting permission prompts or not responding to notifications, will 108 // such as rejecting permission prompts or not responding to notifications, will
105 // decrease the site engagement score. 109 // decrease the site engagement score.
106 class SiteEngagementService : public KeyedService, 110 class SiteEngagementService : public KeyedService,
107 public SiteEngagementScoreProvider { 111 public SiteEngagementScoreProvider {
108 public: 112 public:
109 static SiteEngagementService* Get(Profile* profile); 113 static SiteEngagementService* Get(Profile* profile);
110 114
111 // Returns whether or not the SiteEngagementService is enabled. 115 // Returns whether or not the SiteEngagementService is enabled.
112 static bool IsEnabled(); 116 static bool IsEnabled();
113 117
114 explicit SiteEngagementService(Profile* profile); 118 explicit SiteEngagementService(Profile* profile);
115 ~SiteEngagementService() override; 119 ~SiteEngagementService() override;
116 120
117 // Update the karma score of the origin matching |url| for user navigation. 121 // Update the karma score of the origin matching |url| for navigation.
118 void HandleNavigation(const GURL& url); 122 void HandleNavigation(const GURL& url, ui::PageTransition transition);
123
124 // Update the karma score of the origin matching |url| for time-on-site, based
125 // on user input.
126 void HandleUserInput(const GURL& url);
119 127
120 // Overridden from SiteEngagementScoreProvider: 128 // Overridden from SiteEngagementScoreProvider:
121 int GetScore(const GURL& url) override; 129 double GetScore(const GURL& url) override;
122 int GetTotalEngagementPoints() override; 130 double GetTotalEngagementPoints() override;
123 131
124 private: 132 private:
133 void AddPoints(const GURL& url, double points);
134
125 Profile* profile_; 135 Profile* profile_;
126 136
127 // The clock used to vend times. 137 // The clock used to vend times.
128 base::DefaultClock clock_; 138 base::DefaultClock clock_;
129 139
130 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); 140 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService);
131 }; 141 };
132 142
133 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ 143 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698