| 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 "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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // constant determines how often that happens. | 39 // constant determines how often that happens. |
| 40 static const int kDecayPeriodInDays; | 40 static const int kDecayPeriodInDays; |
| 41 | 41 |
| 42 // How much the score decays after every kDecayPeriodInDays. | 42 // How much the score decays after every kDecayPeriodInDays. |
| 43 static const double kDecayPoints; | 43 static const double kDecayPoints; |
| 44 | 44 |
| 45 // The SiteEngagementService does not take ownership of |clock|. It is the | 45 // The SiteEngagementService does not take ownership of |clock|. It is the |
| 46 // responsibility of the caller to make sure |clock| outlives this | 46 // responsibility of the caller to make sure |clock| outlives this |
| 47 // SiteEngagementScore. | 47 // SiteEngagementScore. |
| 48 SiteEngagementScore(base::Clock* clock, | 48 SiteEngagementScore(base::Clock* clock, |
| 49 const base::DictionaryValue& settings); | 49 const base::DictionaryValue& score_dict); |
| 50 ~SiteEngagementScore(); | 50 ~SiteEngagementScore(); |
| 51 | 51 |
| 52 double Score() const; | 52 double Score() const; |
| 53 void AddPoints(double points); | 53 void AddPoints(double points); |
| 54 | 54 |
| 55 // Updates the content settings dictionary |settings| with the current score | 55 // Updates the content settings dictionary |score_dict| with the current score |
| 56 // fields. Returns true if |settings| changed, otherwise return false. | 56 // fields. Returns true if |score_dict| changed, otherwise return false. |
| 57 bool UpdateSettings(base::DictionaryValue* settings); | 57 bool UpdateScoreDict(base::DictionaryValue* score_dict); |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 friend class SiteEngagementScoreTest; | 60 friend class SiteEngagementScoreTest; |
| 61 | 61 |
| 62 // This version of the constructor is used in unit tests. | 62 // This version of the constructor is used in unit tests. |
| 63 explicit SiteEngagementScore(base::Clock* clock); | 63 explicit SiteEngagementScore(base::Clock* clock); |
| 64 | 64 |
| 65 // Determine the score, accounting for any decay. | 65 // Determine the score, accounting for any decay. |
| 66 double DecayedScore() const; | 66 double DecayedScore() const; |
| 67 | 67 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 explicit SiteEngagementService(Profile* profile); | 104 explicit SiteEngagementService(Profile* profile); |
| 105 ~SiteEngagementService() override; | 105 ~SiteEngagementService() override; |
| 106 | 106 |
| 107 // Update the karma score of the origin matching |url| for user navigation. | 107 // Update the karma score of the origin matching |url| for user navigation. |
| 108 void HandleNavigation(const GURL& url); | 108 void HandleNavigation(const GURL& url); |
| 109 | 109 |
| 110 // Returns a non-negative integer representing the engagement score of the | 110 // Returns a non-negative integer representing the engagement score of the |
| 111 // origin for this URL. | 111 // origin for this URL. |
| 112 int GetScore(const GURL& url); | 112 int GetScore(const GURL& url); |
| 113 | 113 |
| 114 // Returns the sum of engagement points awarded to all sites. |
| 115 int GetTotalEngagementPoints(); |
| 116 |
| 114 private: | 117 private: |
| 115 Profile* profile_; | 118 Profile* profile_; |
| 116 | 119 |
| 117 // The clock used to vend times. | 120 // The clock used to vend times. |
| 118 base::DefaultClock clock_; | 121 base::DefaultClock clock_; |
| 119 | 122 |
| 120 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); | 123 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |
| 121 }; | 124 }; |
| 122 | 125 |
| 123 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 126 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
| OLD | NEW |