| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 // The number of points that the engagement service must accumulate to be | 56 // The number of points that the engagement service must accumulate to be |
| 57 // considered 'useful'. | 57 // considered 'useful'. |
| 58 BOOTSTRAP_POINTS, | 58 BOOTSTRAP_POINTS, |
| 59 | 59 |
| 60 // The boundaries between low/medium and medium/high engagement as returned | 60 // The boundaries between low/medium and medium/high engagement as returned |
| 61 // by GetEngagementLevel(). | 61 // by GetEngagementLevel(). |
| 62 MEDIUM_ENGAGEMENT_BOUNDARY, | 62 MEDIUM_ENGAGEMENT_BOUNDARY, |
| 63 HIGH_ENGAGEMENT_BOUNDARY, | 63 HIGH_ENGAGEMENT_BOUNDARY, |
| 64 | 64 |
| 65 // The maximum number of decays that a SiteEngagementScore can incur before |
| 66 // entering a grace period. MAX_DECAYS_PER_SCORE * DECAY_PERIOD_IN_DAYS is |
| 67 // the max decay period, i.e. the maximum duration permitted for |
| 68 // (clock_->Now() - score.last_engagement_time()). |
| 69 MAX_DECAYS_PER_SCORE, |
| 70 |
| 71 // If a SiteEngagamentScore has not been accessed or updated for a period |
| 72 // longer than the max decay period + LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS |
| 73 // (see above), its last engagement time will be reset to be max decay |
| 74 // period prior to clock_->Now(). |
| 75 LAST_ENGAGEMENT_GRACE_PERIOD_IN_HOURS, |
| 76 |
| 65 MAX_VARIATION | 77 MAX_VARIATION |
| 66 }; | 78 }; |
| 67 | 79 |
| 68 // The maximum number of points that are allowed. | 80 // The maximum number of points that are allowed. |
| 69 static const double kMaxPoints; | 81 static const double kMaxPoints; |
| 70 | 82 |
| 71 static double GetMaxPointsPerDay(); | 83 static double GetMaxPointsPerDay(); |
| 72 static double GetDecayPeriodInDays(); | 84 static double GetDecayPeriodInDays(); |
| 73 static double GetDecayPoints(); | 85 static double GetDecayPoints(); |
| 74 static double GetNavigationPoints(); | 86 static double GetNavigationPoints(); |
| 75 static double GetUserInputPoints(); | 87 static double GetUserInputPoints(); |
| 76 static double GetVisibleMediaPoints(); | 88 static double GetVisibleMediaPoints(); |
| 77 static double GetHiddenMediaPoints(); | 89 static double GetHiddenMediaPoints(); |
| 78 static double GetWebAppInstalledPoints(); | 90 static double GetWebAppInstalledPoints(); |
| 79 static double GetFirstDailyEngagementPoints(); | 91 static double GetFirstDailyEngagementPoints(); |
| 80 static double GetBootstrapPoints(); | 92 static double GetBootstrapPoints(); |
| 81 static double GetMediumEngagementBoundary(); | 93 static double GetMediumEngagementBoundary(); |
| 82 static double GetHighEngagementBoundary(); | 94 static double GetHighEngagementBoundary(); |
| 95 static double GetMaxDecaysPerScore(); |
| 96 static double GetLastEngagementGracePeriodInHours(); |
| 83 | 97 |
| 84 // Update the default engagement settings via variations. | 98 // Update the default engagement settings via variations. |
| 85 static void UpdateFromVariations(const char* param_name); | 99 static void UpdateFromVariations(const char* param_name); |
| 86 | 100 |
| 87 // The SiteEngagementScore does not take ownership of |clock|. It is the | 101 // The SiteEngagementScore does not take ownership of |clock|. It is the |
| 88 // responsibility of the caller to make sure |clock| outlives this | 102 // responsibility of the caller to make sure |clock| outlives this |
| 89 // SiteEngagementScore. | 103 // SiteEngagementScore. |
| 90 SiteEngagementScore(base::Clock* clock, | 104 SiteEngagementScore(base::Clock* clock, |
| 91 const GURL& origin, | 105 const GURL& origin, |
| 92 HostContentSettingsMap* settings_map); | 106 HostContentSettingsMap* settings_map); |
| 93 SiteEngagementScore(SiteEngagementScore&& other); | 107 SiteEngagementScore(SiteEngagementScore&& other); |
| 94 ~SiteEngagementScore(); | 108 ~SiteEngagementScore(); |
| 95 | 109 |
| 96 SiteEngagementScore& operator=(SiteEngagementScore&& other); | 110 SiteEngagementScore& operator=(SiteEngagementScore&& other); |
| 97 | 111 |
| 98 // Adds |points| to this score, respecting daily limits and the maximum | 112 // Adds |points| to this score, respecting daily limits and the maximum |
| 99 // possible score. Decays the score if it has not been updated recently | 113 // possible score. Decays the score if it has not been updated recently |
| 100 // enough. | 114 // enough. |
| 101 void AddPoints(double points); | 115 void AddPoints(double points); |
| 102 double GetScore() const; | 116 double GetScore() const; |
| 103 | 117 |
| 104 // Writes the values in this score into |settings_map_|. | 118 // Writes the values in this score into |settings_map_|. |
| 105 void Commit(); | 119 void Commit(); |
| 106 | 120 |
| 107 // Returns true if the maximum number of points today has been added. | 121 // Returns true if the maximum number of points today has been added. |
| 108 bool MaxPointsPerDayAdded() const; | 122 bool MaxPointsPerDayAdded() const; |
| 109 | 123 |
| 110 // Resets the score to |points| and resets the daily point limit. If | 124 // Resets the score to |points| and resets the daily point limit. If |
| 111 // |updated_time| is non-null, sets the last engagement time and last | 125 // |updated_time| is non-null, sets the last engagement time to that value. |
| 112 // shortcut launch time (if it is non-null) to |updated_time|. Otherwise, last | |
| 113 // engagement time is set to the current time and last shortcut launch time is | |
| 114 // left unchanged. | |
| 115 void Reset(double points, const base::Time updated_time); | 126 void Reset(double points, const base::Time updated_time); |
| 116 | 127 |
| 117 // Get/set the last time this origin was launched from an installed shortcut. | 128 // Get/set the last time this origin was launched from an installed shortcut. |
| 118 base::Time last_shortcut_launch_time() const { | 129 base::Time last_shortcut_launch_time() const { |
| 119 return last_shortcut_launch_time_; | 130 return last_shortcut_launch_time_; |
| 120 } | 131 } |
| 121 void set_last_shortcut_launch_time(const base::Time& time) { | 132 void set_last_shortcut_launch_time(const base::Time& time) { |
| 122 last_shortcut_launch_time_ = time; | 133 last_shortcut_launch_time_ = time; |
| 123 } | 134 } |
| 124 | 135 |
| 136 // Get/set the last time this origin recorded an engagement change. |
| 137 base::Time last_engagement_time() const { |
| 138 return last_engagement_time_; |
| 139 } |
| 140 void set_last_engagement_time(const base::Time& time) { |
| 141 last_engagement_time_ = time; |
| 142 } |
| 143 |
| 125 private: | 144 private: |
| 126 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PartiallyEmptyDictionary); | 145 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PartiallyEmptyDictionary); |
| 127 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary); | 146 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, PopulatedDictionary); |
| 128 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset); | 147 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, Reset); |
| 129 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, FirstDailyEngagementBonus); | 148 FRIEND_TEST_ALL_PREFIXES(SiteEngagementScoreTest, FirstDailyEngagementBonus); |
| 130 friend class ImportantSitesUtilTest; | 149 friend class ImportantSitesUtilTest; |
| 131 friend class SiteEngagementHelperTest; | 150 friend class SiteEngagementHelperTest; |
| 132 friend class SiteEngagementScoreTest; | 151 friend class SiteEngagementScoreTest; |
| 133 friend class SiteEngagementServiceTest; | 152 friend class SiteEngagementServiceTest; |
| 134 | 153 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // The origin this score represents. | 204 // The origin this score represents. |
| 186 GURL origin_; | 205 GURL origin_; |
| 187 | 206 |
| 188 // The settings map to write this score to when Commit() is called. | 207 // The settings map to write this score to when Commit() is called. |
| 189 HostContentSettingsMap* settings_map_; | 208 HostContentSettingsMap* settings_map_; |
| 190 | 209 |
| 191 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); | 210 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); |
| 192 }; | 211 }; |
| 193 | 212 |
| 194 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ | 213 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ |
| OLD | NEW |