| 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/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/time/default_clock.h" | 11 #include "base/time/default_clock.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "chrome/browser/engagement/site_engagement_metrics.h" |
| 13 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
| 14 #include "ui/base/page_transition_types.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 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 49 // The SiteEngagementService does not take ownership of |clock|. It is the | 50 // The SiteEngagementService does not take ownership of |clock|. It is the |
| 50 // responsibility of the caller to make sure |clock| outlives this | 51 // responsibility of the caller to make sure |clock| outlives this |
| 51 // SiteEngagementScore. | 52 // SiteEngagementScore. |
| 52 SiteEngagementScore(base::Clock* clock, | 53 SiteEngagementScore(base::Clock* clock, |
| 53 const base::DictionaryValue& score_dict); | 54 const base::DictionaryValue& score_dict); |
| 54 ~SiteEngagementScore(); | 55 ~SiteEngagementScore(); |
| 55 | 56 |
| 56 double Score() const; | 57 double Score() const; |
| 57 void AddPoints(double points); | 58 void AddPoints(double points); |
| 58 | 59 |
| 60 // Returns true if the maximum number of points today has been added. Resets |
| 61 // the number of points added today if the day has changed. |
| 62 bool MaxPointsPerDayAdded(); |
| 63 |
| 59 // Updates the content settings dictionary |score_dict| with the current score | 64 // Updates the content settings dictionary |score_dict| with the current score |
| 60 // fields. Returns true if |score_dict| changed, otherwise return false. | 65 // fields. Returns true if |score_dict| changed, otherwise return false. |
| 61 bool UpdateScoreDict(base::DictionaryValue* score_dict); | 66 bool UpdateScoreDict(base::DictionaryValue* score_dict); |
| 62 | 67 |
| 63 private: | 68 private: |
| 64 friend class SiteEngagementScoreTest; | 69 friend class SiteEngagementScoreTest; |
| 65 | 70 |
| 66 // This version of the constructor is used in unit tests. | 71 // This version of the constructor is used in unit tests. |
| 67 explicit SiteEngagementScore(base::Clock* clock); | 72 explicit SiteEngagementScore(base::Clock* clock); |
| 68 | 73 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ~SiteEngagementService() override; | 125 ~SiteEngagementService() override; |
| 121 | 126 |
| 122 // Returns a map of all stored origins and their engagement scores. | 127 // Returns a map of all stored origins and their engagement scores. |
| 123 std::map<GURL, double> GetScoreMap(); | 128 std::map<GURL, double> GetScoreMap(); |
| 124 | 129 |
| 125 // Update the karma score of the origin matching |url| for navigation. | 130 // Update the karma score of the origin matching |url| for navigation. |
| 126 void HandleNavigation(const GURL& url, ui::PageTransition transition); | 131 void HandleNavigation(const GURL& url, ui::PageTransition transition); |
| 127 | 132 |
| 128 // Update the karma score of the origin matching |url| for time-on-site, based | 133 // Update the karma score of the origin matching |url| for time-on-site, based |
| 129 // on user input. | 134 // on user input. |
| 130 void HandleUserInput(const GURL& url); | 135 void HandleUserInput(const GURL& url, |
| 136 SiteEngagementMetrics::EngagementType type); |
| 131 | 137 |
| 132 // Overridden from SiteEngagementScoreProvider: | 138 // Overridden from SiteEngagementScoreProvider: |
| 133 double GetScore(const GURL& url) override; | 139 double GetScore(const GURL& url) override; |
| 134 double GetTotalEngagementPoints() override; | 140 double GetTotalEngagementPoints() override; |
| 135 | 141 |
| 136 private: | 142 private: |
| 137 // Adds the specified number of points to the given origin, respecting the | 143 // Adds the specified number of points to the given origin, respecting the |
| 138 // maximum limits for the day and overall. | 144 // maximum limits for the day and overall. |
| 139 void AddPoints(const GURL& url, double points); | 145 void AddPoints(const GURL& url, double points); |
| 140 | 146 |
| 147 // Returns the number of origins with maximum daily and total engagement |
| 148 // respectively. |
| 149 int OriginsWithMaxDailyEngagement(); |
| 150 int OriginsWithMaxEngagement(); |
| 151 |
| 152 // Logs the total number of origins stored by the site engagement service, and |
| 153 // the total accumulated engagement score. |
| 154 void RecordStartupUmaStats(); |
| 155 |
| 141 Profile* profile_; | 156 Profile* profile_; |
| 142 | 157 |
| 143 // The clock used to vend times. | 158 // The clock used to vend times. |
| 144 base::DefaultClock clock_; | 159 base::DefaultClock clock_; |
| 145 | 160 |
| 146 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); | 161 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |
| 147 }; | 162 }; |
| 148 | 163 |
| 149 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 164 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
| OLD | NEW |