| 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/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/engagement/site_engagement_metrics.h" | 16 #include "chrome/browser/engagement/site_engagement_metrics.h" |
| 17 #include "components/history/core/browser/history_service_observer.h" | 17 #include "components/history/core/browser/history_service_observer.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "ui/base/page_transition_types.h" | 19 #include "ui/base/page_transition_types.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class DictionaryValue; | 22 class DictionaryValue; |
| 23 class Clock; | 23 class Clock; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace content { |
| 27 class WebContents; |
| 28 } |
| 29 |
| 26 namespace history { | 30 namespace history { |
| 27 class HistoryService; | 31 class HistoryService; |
| 28 } | 32 } |
| 29 | 33 |
| 30 class GURL; | 34 class GURL; |
| 31 class Profile; | 35 class Profile; |
| 32 class SiteEngagementScore; | 36 class SiteEngagementScore; |
| 33 | 37 |
| 34 class SiteEngagementScoreProvider { | 38 class SiteEngagementScoreProvider { |
| 35 public: | 39 public: |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 141 |
| 138 // Post startup tasks: cleaning up origins which have decayed to 0, and | 142 // Post startup tasks: cleaning up origins which have decayed to 0, and |
| 139 // logging UMA statistics. | 143 // logging UMA statistics. |
| 140 void AfterStartupTask(); | 144 void AfterStartupTask(); |
| 141 void CleanupEngagementScores(); | 145 void CleanupEngagementScores(); |
| 142 void RecordMetrics(); | 146 void RecordMetrics(); |
| 143 | 147 |
| 144 // Returns the median engagement score of all recorded origins. | 148 // Returns the median engagement score of all recorded origins. |
| 145 double GetMedianEngagement(const std::map<GURL, double>& score_map) const; | 149 double GetMedianEngagement(const std::map<GURL, double>& score_map) const; |
| 146 | 150 |
| 147 // Update the engagement score of the origin matching |url| for media playing. | 151 // Update the engagement score of the origin loaded in |web_contents| for |
| 148 // The points awarded are discounted if the media is being played in a non- | 152 // media playing. The points awarded are discounted if the media is being |
| 149 // visible tab. | 153 // played in a non-visible tab. |
| 150 void HandleMediaPlaying(const GURL& url, bool is_hidden); | 154 void HandleMediaPlaying(content::WebContents* web_contents, bool is_hidden); |
| 151 | 155 |
| 152 // Update the engagement score of the origin matching |url| for navigation. | 156 // Update the engagement score of the origin loaded in |web_contents| for |
| 153 void HandleNavigation(const GURL& url, ui::PageTransition transition); | 157 // navigation. |
| 158 void HandleNavigation(content::WebContents* web_contents, |
| 159 ui::PageTransition transition); |
| 154 | 160 |
| 155 // Update the engagement score of the origin matching |url| for time-on-site, | 161 // Update the engagement score of the origin loaded in |web_contents| for |
| 156 // based on user input. | 162 // time-on-site, based on user input. |
| 157 void HandleUserInput(const GURL& url, | 163 void HandleUserInput(content::WebContents* web_contents, |
| 158 SiteEngagementMetrics::EngagementType type); | 164 SiteEngagementMetrics::EngagementType type); |
| 159 | 165 |
| 160 // Overridden from history::HistoryServiceObserver: | 166 // Overridden from history::HistoryServiceObserver: |
| 161 void OnURLsDeleted(history::HistoryService* history_service, | 167 void OnURLsDeleted(history::HistoryService* history_service, |
| 162 bool all_history, | 168 bool all_history, |
| 163 bool expired, | 169 bool expired, |
| 164 const history::URLRows& deleted_rows, | 170 const history::URLRows& deleted_rows, |
| 165 const std::set<GURL>& favicon_urls) override; | 171 const std::set<GURL>& favicon_urls) override; |
| 166 | 172 |
| 167 // Returns the number of origins with maximum daily and total engagement | 173 // Returns the number of origins with maximum daily and total engagement |
| (...skipping 20 matching lines...) Expand all Loading... |
| 188 // origin's engagement score after an hour has elapsed triggers the next | 194 // origin's engagement score after an hour has elapsed triggers the next |
| 189 // upload. | 195 // upload. |
| 190 base::Time last_metrics_time_; | 196 base::Time last_metrics_time_; |
| 191 | 197 |
| 192 base::WeakPtrFactory<SiteEngagementService> weak_factory_; | 198 base::WeakPtrFactory<SiteEngagementService> weak_factory_; |
| 193 | 199 |
| 194 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); | 200 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |
| 195 }; | 201 }; |
| 196 | 202 |
| 197 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 203 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
| OLD | NEW |