| 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 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "chrome/browser/engagement/site_engagement_metrics.h" | 17 #include "chrome/browser/engagement/site_engagement_metrics.h" |
| 18 #include "chrome/browser/engagement/site_engagement_observer.h" |
| 17 #include "components/history/core/browser/history_service_observer.h" | 19 #include "components/history/core/browser/history_service_observer.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "ui/base/page_transition_types.h" | 21 #include "ui/base/page_transition_types.h" |
| 20 | 22 |
| 21 namespace base { | 23 namespace base { |
| 22 class DictionaryValue; | 24 class DictionaryValue; |
| 23 class Clock; | 25 class Clock; |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace content { | 28 namespace content { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 109 |
| 108 // Update the last time |url| was opened from an installed shortcut to be | 110 // Update the last time |url| was opened from an installed shortcut to be |
| 109 // clock_->Now(). | 111 // clock_->Now(). |
| 110 void SetLastShortcutLaunchTime(const GURL& url); | 112 void SetLastShortcutLaunchTime(const GURL& url); |
| 111 | 113 |
| 112 // Overridden from SiteEngagementScoreProvider. | 114 // Overridden from SiteEngagementScoreProvider. |
| 113 double GetScore(const GURL& url) const override; | 115 double GetScore(const GURL& url) const override; |
| 114 double GetTotalEngagementPoints() const override; | 116 double GetTotalEngagementPoints() const override; |
| 115 | 117 |
| 116 private: | 118 private: |
| 119 friend class SiteEngagementObserver; |
| 117 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); | 120 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); |
| 118 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); | 121 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); |
| 119 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs); | 122 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ClearHistoryForURLs); |
| 120 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement); | 123 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetMedianEngagement); |
| 121 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints); | 124 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalNavigationPoints); |
| 122 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints); | 125 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetTotalUserInputPoints); |
| 123 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); | 126 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); |
| 124 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, | 127 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, |
| 125 CleanupOriginsOnHistoryDeletion); | 128 CleanupOriginsOnHistoryDeletion); |
| 126 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped); | 129 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped); |
| 127 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel); | 130 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel); |
| 131 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, Observers); |
| 128 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms); | 132 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms); |
| 129 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); | 133 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); |
| 130 | 134 |
| 131 // Only used in tests. | 135 // Only used in tests. |
| 132 SiteEngagementService(Profile* profile, std::unique_ptr<base::Clock> clock); | 136 SiteEngagementService(Profile* profile, std::unique_ptr<base::Clock> clock); |
| 133 | 137 |
| 134 // Adds the specified number of points to the given origin, respecting the | 138 // Adds the specified number of points to the given origin, respecting the |
| 135 // maximum limits for the day and overall. | 139 // maximum limits for the day and overall. |
| 136 void AddPoints(const GURL& url, double points); | 140 void AddPoints(const GURL& url, double points); |
| 137 | 141 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 int OriginsWithMaxEngagement(const std::map<GURL, double>& score_map) const; | 180 int OriginsWithMaxEngagement(const std::map<GURL, double>& score_map) const; |
| 177 | 181 |
| 178 // Callback for the history service when it is asked for a map of origins to | 182 // Callback for the history service when it is asked for a map of origins to |
| 179 // how many URLs corresponding to that origin remain in history. | 183 // how many URLs corresponding to that origin remain in history. |
| 180 void GetCountsAndLastVisitForOriginsComplete( | 184 void GetCountsAndLastVisitForOriginsComplete( |
| 181 history::HistoryService* history_service, | 185 history::HistoryService* history_service, |
| 182 const std::multiset<GURL>& deleted_url_origins, | 186 const std::multiset<GURL>& deleted_url_origins, |
| 183 bool expired, | 187 bool expired, |
| 184 const history::OriginCountAndLastVisitMap& remaining_origin_counts); | 188 const history::OriginCountAndLastVisitMap& remaining_origin_counts); |
| 185 | 189 |
| 190 // Add and remove observers of this service. |
| 191 void AddObserver(SiteEngagementObserver* observer); |
| 192 void RemoveObserver(SiteEngagementObserver* observer); |
| 193 |
| 186 Profile* profile_; | 194 Profile* profile_; |
| 187 | 195 |
| 188 // The clock used to vend times. | 196 // The clock used to vend times. |
| 189 std::unique_ptr<base::Clock> clock_; | 197 std::unique_ptr<base::Clock> clock_; |
| 190 | 198 |
| 191 // Metrics are recorded at non-incognito browser startup, and then | 199 // Metrics are recorded at non-incognito browser startup, and then |
| 192 // approximately once per hour thereafter. Store the local time at which | 200 // approximately once per hour thereafter. Store the local time at which |
| 193 // metrics were previously uploaded: the first event which affects any | 201 // metrics were previously uploaded: the first event which affects any |
| 194 // origin's engagement score after an hour has elapsed triggers the next | 202 // origin's engagement score after an hour has elapsed triggers the next |
| 195 // upload. | 203 // upload. |
| 196 base::Time last_metrics_time_; | 204 base::Time last_metrics_time_; |
| 197 | 205 |
| 206 // A list of observers. When any origin registers an engagement-increasing |
| 207 // event, each observer's OnEngagementIncreased method will be called. |
| 208 base::ObserverList<SiteEngagementObserver> observer_list_; |
| 209 |
| 198 base::WeakPtrFactory<SiteEngagementService> weak_factory_; | 210 base::WeakPtrFactory<SiteEngagementService> weak_factory_; |
| 199 | 211 |
| 200 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); | 212 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |
| 201 }; | 213 }; |
| 202 | 214 |
| 203 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 215 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
| OLD | NEW |