Chromium Code Reviews| 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/observer_list.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/browser/engagement/site_engagement_details.mojom.h" | |
| 18 #include "chrome/browser/engagement/site_engagement_metrics.h" | 19 #include "chrome/browser/engagement/site_engagement_metrics.h" |
| 19 #include "chrome/browser/engagement/site_engagement_observer.h" | 20 #include "chrome/browser/engagement/site_engagement_observer.h" |
| 20 #include "components/history/core/browser/history_service_observer.h" | 21 #include "components/history/core/browser/history_service_observer.h" |
| 21 #include "components/keyed_service/core/keyed_service.h" | 22 #include "components/keyed_service/core/keyed_service.h" |
| 22 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" | 23 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" |
| 23 #include "ui/base/page_transition_types.h" | 24 #include "ui/base/page_transition_types.h" |
| 24 | 25 |
| 25 namespace base { | 26 namespace base { |
| 26 class Clock; | 27 class Clock; |
| 27 } | 28 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 | 110 |
| 110 explicit SiteEngagementService(Profile* profile); | 111 explicit SiteEngagementService(Profile* profile); |
| 111 ~SiteEngagementService() override; | 112 ~SiteEngagementService() override; |
| 112 | 113 |
| 113 // KeyedService support: | 114 // KeyedService support: |
| 114 void Shutdown() override; | 115 void Shutdown() override; |
| 115 | 116 |
| 116 // Returns the engagement level of |url|. | 117 // Returns the engagement level of |url|. |
| 117 blink::mojom::EngagementLevel GetEngagementLevel(const GURL& url) const; | 118 blink::mojom::EngagementLevel GetEngagementLevel(const GURL& url) const; |
| 118 | 119 |
| 120 // Returns SiteEngagementDetails structures describing the score details for | |
| 121 // all stored origins. | |
| 122 std::vector<mojom::SiteEngagementDetails> GetScoreDetails() const; | |
| 123 | |
| 119 // Returns a map of all stored origins and their engagement scores. | 124 // Returns a map of all stored origins and their engagement scores. |
| 125 // TODO(wez): Remove this! | |
|
Wez
2017/04/10 03:45:28
AFAICT the only callers of this are:
1. to calcula
| |
| 120 std::map<GURL, double> GetScoreMap() const; | 126 std::map<GURL, double> GetScoreMap() const; |
| 121 | 127 |
| 122 // Update the engagement score of |url| for a notification interaction. | 128 // Update the engagement score of |url| for a notification interaction. |
| 123 void HandleNotificationInteraction(const GURL& url); | 129 void HandleNotificationInteraction(const GURL& url); |
| 124 | 130 |
| 125 // Returns whether the engagement service has enough data to make meaningful | 131 // Returns whether the engagement service has enough data to make meaningful |
| 126 // decisions. Clients should avoid using engagement in their heuristic until | 132 // decisions. Clients should avoid using engagement in their heuristic until |
| 127 // this is true. | 133 // this is true. |
| 128 bool IsBootstrapped() const; | 134 bool IsBootstrapped() const; |
| 129 | 135 |
| 130 // Returns whether |url| has at least the given |level| of engagement. | 136 // Returns whether |url| has at least the given |level| of engagement. |
| 131 bool IsEngagementAtLeast(const GURL& url, | 137 bool IsEngagementAtLeast(const GURL& url, |
| 132 blink::mojom::EngagementLevel level) const; | 138 blink::mojom::EngagementLevel level) const; |
| 133 | 139 |
| 134 // Resets the base engagement for |url| to |score|, clearing daily limits. Any | 140 // Resets the base engagement for |url| to |score|, clearing daily limits. Any |
| 135 // bonus engagement that |url| has acquired is not affected by this method, so | 141 // bonus engagement that |url| has acquired is not affected by this method, so |
| 136 // the result of GetScore(|url|) may not be the same as |score|. | 142 // the result of GetScore(|url|) may not be the same as |score|. |
| 137 void ResetBaseScoreForURL(const GURL& url, double score); | 143 void ResetBaseScoreForURL(const GURL& url, double score); |
| 138 | 144 |
| 139 // Update the last time |url| was opened from an installed shortcut to be | 145 // Update the last time |url| was opened from an installed shortcut to be |
| 140 // clock_->Now(). | 146 // clock_->Now(). |
| 141 void SetLastShortcutLaunchTime(const GURL& url); | 147 void SetLastShortcutLaunchTime(const GURL& url); |
| 142 | 148 |
| 143 void HelperCreated(SiteEngagementService::Helper* helper); | 149 void HelperCreated(SiteEngagementService::Helper* helper); |
| 144 void HelperDeleted(SiteEngagementService::Helper* helper); | 150 void HelperDeleted(SiteEngagementService::Helper* helper); |
| 145 | 151 |
| 152 // Returns the site engagement details for the specified |url|. | |
| 153 mojom::SiteEngagementDetails GetScoreDetails(const GURL& url) const; | |
| 154 | |
| 146 // Overridden from SiteEngagementScoreProvider. | 155 // Overridden from SiteEngagementScoreProvider. |
| 147 double GetScore(const GURL& url) const override; | 156 double GetScore(const GURL& url) const override; |
| 148 double GetTotalEngagementPoints() const override; | 157 double GetTotalEngagementPoints() const override; |
| 149 | 158 |
| 150 private: | 159 private: |
| 151 friend class SiteEngagementObserver; | 160 friend class SiteEngagementObserver; |
| 152 friend class SiteEngagementServiceAndroid; | 161 friend class SiteEngagementServiceAndroid; |
| 153 friend class SiteEngagementServiceTest; | 162 friend class SiteEngagementServiceTest; |
| 154 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); | 163 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); |
| 155 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); | 164 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 // A list of observers. When any origin registers an engagement-increasing | 313 // A list of observers. When any origin registers an engagement-increasing |
| 305 // event, each observer's OnEngagementIncreased method will be called. | 314 // event, each observer's OnEngagementIncreased method will be called. |
| 306 base::ObserverList<SiteEngagementObserver> observer_list_; | 315 base::ObserverList<SiteEngagementObserver> observer_list_; |
| 307 | 316 |
| 308 base::WeakPtrFactory<SiteEngagementService> weak_factory_; | 317 base::WeakPtrFactory<SiteEngagementService> weak_factory_; |
| 309 | 318 |
| 310 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); | 319 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); |
| 311 }; | 320 }; |
| 312 | 321 |
| 313 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ | 322 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ |
| OLD | NEW |