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