| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_SCORE_H_ | 5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ |
| 6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ | 6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ |
| 7 | 7 |
| 8 #include <array> | 8 #include <array> |
| 9 #include <memory> | 9 #include <memory> |
| 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/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class Clock; | 18 class Clock; |
| 19 } | 19 } |
| 20 | 20 |
| 21 class Profile; | 21 class HostContentSettingsMap; |
| 22 | 22 |
| 23 class SiteEngagementScore { | 23 class SiteEngagementScore { |
| 24 public: | 24 public: |
| 25 // The parameters which can be varied via field trial. | 25 // The parameters which can be varied via field trial. |
| 26 enum Variation { | 26 enum Variation { |
| 27 // The maximum number of points that can be accrued in one day. | 27 // The maximum number of points that can be accrued in one day. |
| 28 MAX_POINTS_PER_DAY = 0, | 28 MAX_POINTS_PER_DAY = 0, |
| 29 | 29 |
| 30 // The period over which site engagement decays. | 30 // The period over which site engagement decays. |
| 31 DECAY_PERIOD_IN_HOURS, | 31 DECAY_PERIOD_IN_HOURS, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 static double GetLastEngagementGracePeriodInHours(); | 107 static double GetLastEngagementGracePeriodInHours(); |
| 108 | 108 |
| 109 // Update the default engagement settings via variations. | 109 // Update the default engagement settings via variations. |
| 110 static void UpdateFromVariations(const char* param_name); | 110 static void UpdateFromVariations(const char* param_name); |
| 111 | 111 |
| 112 // The SiteEngagementScore does not take ownership of |clock|. It is the | 112 // The SiteEngagementScore does not take ownership of |clock|. It is the |
| 113 // responsibility of the caller to make sure |clock| outlives this | 113 // responsibility of the caller to make sure |clock| outlives this |
| 114 // SiteEngagementScore. | 114 // SiteEngagementScore. |
| 115 SiteEngagementScore(base::Clock* clock, | 115 SiteEngagementScore(base::Clock* clock, |
| 116 const GURL& origin, | 116 const GURL& origin, |
| 117 Profile* profile); | 117 HostContentSettingsMap* settings); |
| 118 SiteEngagementScore(SiteEngagementScore&& other); | 118 SiteEngagementScore(SiteEngagementScore&& other); |
| 119 ~SiteEngagementScore(); | 119 ~SiteEngagementScore(); |
| 120 | 120 |
| 121 SiteEngagementScore& operator=(SiteEngagementScore&& other); | 121 SiteEngagementScore& operator=(SiteEngagementScore&& other); |
| 122 | 122 |
| 123 // Adds |points| to this score, respecting daily limits and the maximum | 123 // Adds |points| to this score, respecting daily limits and the maximum |
| 124 // possible score. Decays the score if it has not been updated recently | 124 // possible score. Decays the score if it has not been updated recently |
| 125 // enough. | 125 // enough. |
| 126 void AddPoints(double points); | 126 void AddPoints(double points); |
| 127 double GetScore() const; | 127 double GetScore() const; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PartiallyEmptyDictionary); | 156 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PartiallyEmptyDictionary); |
| 157 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary); | 157 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary); |
| 158 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset); | 158 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset); |
| 159 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, FirstDailyEngagementBonus); | 159 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, FirstDailyEngagementBonus); |
| 160 friend class ImportantSitesUtilTest; | 160 friend class ImportantSitesUtilTest; |
| 161 friend class SiteEngagementHelperTest; | 161 friend class SiteEngagementHelperTest; |
| 162 friend class SiteEngagementScoreTest; | 162 friend class SiteEngagementScoreTest; |
| 163 friend class SiteEngagementServiceTest; | 163 friend class SiteEngagementServiceTest; |
| 164 friend class ChromePluginServiceFilterTest; |
| 164 | 165 |
| 165 using ParamValues = std::array<std::pair<std::string, double>, MAX_VARIATION>; | 166 using ParamValues = std::array<std::pair<std::string, double>, MAX_VARIATION>; |
| 166 | 167 |
| 167 // Array holding the values corresponding to each item in Variation array. | 168 // Array holding the values corresponding to each item in Variation array. |
| 168 static ParamValues& GetParamValues(); | 169 static ParamValues& GetParamValues(); |
| 169 static ParamValues BuildParamValues(); | 170 static ParamValues BuildParamValues(); |
| 170 | 171 |
| 171 // Keys used in the content settings dictionary. | 172 // Keys used in the content settings dictionary. |
| 172 static const char* kRawScoreKey; | 173 static const char* kRawScoreKey; |
| 173 static const char* kPointsAddedTodayKey; | 174 static const char* kPointsAddedTodayKey; |
| 174 static const char* kLastEngagementTimeKey; | 175 static const char* kLastEngagementTimeKey; |
| 175 static const char* kLastShortcutLaunchTimeKey; | 176 static const char* kLastShortcutLaunchTimeKey; |
| 176 | 177 |
| 177 // This version of the constructor is used in unit tests. | 178 // This version of the constructor is used in unit tests. |
| 178 SiteEngagementScore(base::Clock* clock, | 179 SiteEngagementScore(base::Clock* clock, |
| 180 const GURL& origin, |
| 179 std::unique_ptr<base::DictionaryValue> score_dict); | 181 std::unique_ptr<base::DictionaryValue> score_dict); |
| 180 | 182 |
| 181 // Determine the score, accounting for any decay. | 183 // Determine the score, accounting for any decay. |
| 182 double DecayedScore() const; | 184 double DecayedScore() const; |
| 183 | 185 |
| 184 // Determine any score bonus from having installed shortcuts. | 186 // Determine any score bonus from having installed shortcuts. |
| 185 double BonusScore() const; | 187 double BonusScore() const; |
| 186 | 188 |
| 187 // Sets fixed parameter values for testing site engagement. Ensure that any | 189 // Sets fixed parameter values for testing site engagement. Ensure that any |
| 188 // newly added parameters receive a fixed value here. | 190 // newly added parameters receive a fixed value here. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 211 // The last time the site with this score was launched from an installed | 213 // The last time the site with this score was launched from an installed |
| 212 // shortcut. | 214 // shortcut. |
| 213 base::Time last_shortcut_launch_time_; | 215 base::Time last_shortcut_launch_time_; |
| 214 | 216 |
| 215 // The dictionary that represents this engagement score. | 217 // The dictionary that represents this engagement score. |
| 216 std::unique_ptr<base::DictionaryValue> score_dict_; | 218 std::unique_ptr<base::DictionaryValue> score_dict_; |
| 217 | 219 |
| 218 // The origin this score represents. | 220 // The origin this score represents. |
| 219 GURL origin_; | 221 GURL origin_; |
| 220 | 222 |
| 221 // The profile to write this score to when Commit() is called. | 223 // The settings to write this score to when Commit() is called. |
| 222 Profile* profile_; | 224 HostContentSettingsMap* settings_map_; |
| 223 | 225 |
| 224 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); | 226 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); |
| 225 }; | 227 }; |
| 226 | 228 |
| 227 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ | 229 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ |
| OLD | NEW |