| 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 "chrome/browser/engagement/site_engagement_details.mojom.h" |
| 15 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" | 16 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class Clock; | 20 class Clock; |
| 20 } | 21 } |
| 21 | 22 |
| 22 class HostContentSettingsMap; | 23 class HostContentSettingsMap; |
| 23 | 24 |
| 24 class SiteEngagementScore { | 25 class SiteEngagementScore { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 HostContentSettingsMap* settings); | 131 HostContentSettingsMap* settings); |
| 131 SiteEngagementScore(SiteEngagementScore&& other); | 132 SiteEngagementScore(SiteEngagementScore&& other); |
| 132 ~SiteEngagementScore(); | 133 ~SiteEngagementScore(); |
| 133 | 134 |
| 134 SiteEngagementScore& operator=(SiteEngagementScore&& other); | 135 SiteEngagementScore& operator=(SiteEngagementScore&& other); |
| 135 | 136 |
| 136 // Adds |points| to this score, respecting daily limits and the maximum | 137 // Adds |points| to this score, respecting daily limits and the maximum |
| 137 // possible score. Decays the score if it has not been updated recently | 138 // possible score. Decays the score if it has not been updated recently |
| 138 // enough. | 139 // enough. |
| 139 void AddPoints(double points); | 140 void AddPoints(double points); |
| 141 |
| 142 // TODO(wez): Remove this? |
| 140 double GetScore() const; | 143 double GetScore() const; |
| 141 | 144 |
| 145 // Returns a structure containing the origin URL and score, and details |
| 146 // of the base and bonus scores. Note that the |score| is limited to |
| 147 // kMaxPoints, while the detailed scores are returned raw. |
| 148 mojom::SiteEngagementDetails GetDetails() const; |
| 149 |
| 142 // Writes the values in this score into |settings_map_|. | 150 // Writes the values in this score into |settings_map_|. |
| 143 void Commit(); | 151 void Commit(); |
| 144 | 152 |
| 145 // Returns the discrete engagement level for this score. | 153 // Returns the discrete engagement level for this score. |
| 146 blink::mojom::EngagementLevel GetEngagementLevel() const; | 154 blink::mojom::EngagementLevel GetEngagementLevel() const; |
| 147 | 155 |
| 148 // Returns true if the maximum number of points today has been added. | 156 // Returns true if the maximum number of points today has been added. |
| 149 bool MaxPointsPerDayAdded() const; | 157 bool MaxPointsPerDayAdded() const; |
| 150 | 158 |
| 151 // Resets the score to |points| and resets the daily point limit. If | 159 // Resets the score to |points| and resets the daily point limit. If |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 static const char* kLastShortcutLaunchTimeKey; | 197 static const char* kLastShortcutLaunchTimeKey; |
| 190 | 198 |
| 191 // This version of the constructor is used in unit tests. | 199 // This version of the constructor is used in unit tests. |
| 192 SiteEngagementScore(base::Clock* clock, | 200 SiteEngagementScore(base::Clock* clock, |
| 193 const GURL& origin, | 201 const GURL& origin, |
| 194 std::unique_ptr<base::DictionaryValue> score_dict); | 202 std::unique_ptr<base::DictionaryValue> score_dict); |
| 195 | 203 |
| 196 // Determine the score, accounting for any decay. | 204 // Determine the score, accounting for any decay. |
| 197 double DecayedScore() const; | 205 double DecayedScore() const; |
| 198 | 206 |
| 199 // Determine any score bonus from having installed shortcuts. | 207 // Determine bonus from being installed, and having been launched recently.. |
| 200 double BonusScore() const; | 208 double BonusIfShortcutLaunched() const; |
| 209 |
| 210 // Determine bonus from having been granted notifications permission. |
| 211 double BonusIfHasNotifications() const; |
| 201 | 212 |
| 202 // Updates the content settings dictionary |score_dict| with the current score | 213 // Updates the content settings dictionary |score_dict| with the current score |
| 203 // fields. Returns true if |score_dict| changed, otherwise return false. | 214 // fields. Returns true if |score_dict| changed, otherwise return false. |
| 204 bool UpdateScoreDict(base::DictionaryValue* score_dict); | 215 bool UpdateScoreDict(base::DictionaryValue* score_dict); |
| 205 | 216 |
| 206 // The clock used to vend times. Enables time travelling in tests. Owned by | 217 // The clock used to vend times. Enables time travelling in tests. Owned by |
| 207 // the SiteEngagementService. | 218 // the SiteEngagementService. |
| 208 base::Clock* clock_; | 219 base::Clock* clock_; |
| 209 | 220 |
| 210 // |raw_score_| is the score before any decay is applied. | 221 // |raw_score_| is the score before any decay is applied. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 229 // The origin this score represents. | 240 // The origin this score represents. |
| 230 GURL origin_; | 241 GURL origin_; |
| 231 | 242 |
| 232 // The settings to write this score to when Commit() is called. | 243 // The settings to write this score to when Commit() is called. |
| 233 HostContentSettingsMap* settings_map_; | 244 HostContentSettingsMap* settings_map_; |
| 234 | 245 |
| 235 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); | 246 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); |
| 236 }; | 247 }; |
| 237 | 248 |
| 238 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ | 249 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ |
| OLD | NEW |