Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/engagement/site_engagement_service.h

Issue 2285553002: [HBD] Gate the advertising of Flash on Site Engagement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nit Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 16 matching lines...) Expand all
27 27
28 namespace content { 28 namespace content {
29 class WebContents; 29 class WebContents;
30 } 30 }
31 31
32 namespace history { 32 namespace history {
33 class HistoryService; 33 class HistoryService;
34 } 34 }
35 35
36 class GURL; 36 class GURL;
37 class HostContentSettingsMap;
37 class Profile; 38 class Profile;
38 class SiteEngagementScore; 39 class SiteEngagementScore;
39 40
40 class SiteEngagementScoreProvider { 41 class SiteEngagementScoreProvider {
41 public: 42 public:
42 // Returns a non-negative integer representing the engagement score of the 43 // Returns a non-negative integer representing the engagement score of the
43 // origin for this URL. 44 // origin for this URL.
44 virtual double GetScore(const GURL& url) const = 0; 45 virtual double GetScore(const GURL& url) const = 0;
45 46
46 // Returns the sum of engagement points awarded to all sites. 47 // Returns the sum of engagement points awarded to all sites.
47 virtual double GetTotalEngagementPoints() const = 0; 48 virtual double GetTotalEngagementPoints() const = 0;
48 }; 49 };
49 50
50 // Stores and retrieves the engagement score of an origin. 51 // Stores and retrieves the engagement score of an origin.
51 // 52 //
52 // An engagement score is a positive integer that represents how much a user has 53 // An engagement score is a non-negative double that represents how much a user
53 // engaged with an origin - the higher it is, the more engagement the user has 54 // has engaged with an origin - the higher it is, the more engagement the user
54 // had with this site recently. 55 // has had with this site recently.
55 // 56 //
56 // Positive user activity, such as visiting the origin often and adding it to 57 // User activity such as visiting the origin often, interacting with the origin,
57 // the homescreen, will increase the site engagement score. Negative activity, 58 // and adding it to the homescreen will increase the site engagement score. If
58 // such as rejecting permission prompts or not responding to notifications, will 59 // a site's score does not increase for some time, it will decay, eventually
59 // decrease the site engagement score. 60 // reaching zero with further disuse.
61 //
62 // The SiteEngagementService object must be created and used on the UI thread
63 // only. Engagement scores may be queried in a read-only fashion from other
64 // threads using SiteEngagementService::GetScoreFromSettings, but use of this
65 // method is discouraged unless it is not possible to use the UI thread.
60 class SiteEngagementService : public KeyedService, 66 class SiteEngagementService : public KeyedService,
61 public history::HistoryServiceObserver, 67 public history::HistoryServiceObserver,
62 public SiteEngagementScoreProvider { 68 public SiteEngagementScoreProvider {
63 public: 69 public:
64 // WebContentsObserver that detects engagement triggering events and notifies 70 // WebContentsObserver that detects engagement triggering events and notifies
65 // the service of them. 71 // the service of them.
66 class Helper; 72 class Helper;
67 73
68 enum EngagementLevel { 74 enum EngagementLevel {
69 ENGAGEMENT_LEVEL_NONE, 75 ENGAGEMENT_LEVEL_NONE,
70 ENGAGEMENT_LEVEL_LOW, 76 ENGAGEMENT_LEVEL_LOW,
71 ENGAGEMENT_LEVEL_MEDIUM, 77 ENGAGEMENT_LEVEL_MEDIUM,
72 ENGAGEMENT_LEVEL_HIGH, 78 ENGAGEMENT_LEVEL_HIGH,
73 ENGAGEMENT_LEVEL_MAX, 79 ENGAGEMENT_LEVEL_MAX,
74 }; 80 };
75 81
76 // The name of the site engagement variation field trial. 82 // The name of the site engagement variation field trial.
77 static const char kEngagementParams[]; 83 static const char kEngagementParams[];
78 84
79 // Returns the site engagement service attached to this profile. May return 85 // Returns the site engagement service attached to this profile. The service
80 // null if the service does not exist (e.g. the user is in incognito). 86 // exists in incognito mode; scores will be initialised using the score from
87 // the profile that the incognito session was created from, and will increase
88 // and decrease as usual. Engagement earned or decayed in incognito will not
89 // be persisted or reflected in the original profile.
90 //
91 // This method must be called on the UI thread.
81 static SiteEngagementService* Get(Profile* profile); 92 static SiteEngagementService* Get(Profile* profile);
82 93
83 // Returns the maximum possible amount of engagement that a site can accrue. 94 // Returns the maximum possible amount of engagement that a site can accrue.
84 static double GetMaxPoints(); 95 static double GetMaxPoints();
85 96
86 // Returns whether or not the site engagement service is enabled. 97 // Returns whether or not the site engagement service is enabled.
87 static bool IsEnabled(); 98 static bool IsEnabled();
88 99
100 // Returns the score for |origin| based on |settings|. Can be called on any
101 // thread and does not cause any cleanup, decay, etc.
102 //
103 // Should only be used if you cannot create a SiteEngagementService (i.e. you
104 // cannot run on the UI thread).
105 static double GetScoreFromSettings(HostContentSettingsMap* settings,
106 const GURL& origin);
107
89 explicit SiteEngagementService(Profile* profile); 108 explicit SiteEngagementService(Profile* profile);
90 ~SiteEngagementService() override; 109 ~SiteEngagementService() override;
91 110
92 // Returns the engagement level of |url|. This is the recommended API for 111 // Returns the engagement level of |url|.
93 // clients
94 EngagementLevel GetEngagementLevel(const GURL& url) const; 112 EngagementLevel GetEngagementLevel(const GURL& url) const;
95 113
96 // Returns a map of all stored origins and their engagement scores. 114 // Returns a map of all stored origins and their engagement scores.
97 std::map<GURL, double> GetScoreMap() const; 115 std::map<GURL, double> GetScoreMap() const;
98 116
99 // Returns whether the engagement service has enough data to make meaningful 117 // Returns whether the engagement service has enough data to make meaningful
100 // decisions. Clients should avoid using engagement in their heuristic until 118 // decisions. Clients should avoid using engagement in their heuristic until
101 // this is true. 119 // this is true.
102 bool IsBootstrapped() const; 120 bool IsBootstrapped() const;
103 121
(...skipping 24 matching lines...) Expand all
128 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch); 146 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastShortcutLaunch);
129 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, 147 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest,
130 CleanupOriginsOnHistoryDeletion); 148 CleanupOriginsOnHistoryDeletion);
131 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped); 149 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, IsBootstrapped);
132 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel); 150 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, EngagementLevel);
133 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, Observers); 151 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, Observers);
134 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms); 152 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, ScoreDecayHistograms);
135 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastEngagementTime); 153 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, LastEngagementTime);
136 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, 154 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest,
137 IncognitoEngagementService); 155 IncognitoEngagementService);
156 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, GetScoreFromSettings);
138 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger); 157 FRIEND_TEST_ALL_PREFIXES(AppBannerSettingsHelperTest, SiteEngagementTrigger);
139 158
140 // Only used in tests. 159 // Only used in tests.
141 SiteEngagementService(Profile* profile, std::unique_ptr<base::Clock> clock); 160 SiteEngagementService(Profile* profile, std::unique_ptr<base::Clock> clock);
142 161
143 // Adds the specified number of points to the given origin, respecting the 162 // Adds the specified number of points to the given origin, respecting the
144 // maximum limits for the day and overall. 163 // maximum limits for the day and overall.
145 void AddPoints(const GURL& url, double points); 164 void AddPoints(const GURL& url, double points);
146 165
147 // Retrieves the SiteEngagementScore object for |origin|. 166 // Retrieves the SiteEngagementScore object for |origin|.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // A list of observers. When any origin registers an engagement-increasing 255 // A list of observers. When any origin registers an engagement-increasing
237 // event, each observer's OnEngagementIncreased method will be called. 256 // event, each observer's OnEngagementIncreased method will be called.
238 base::ObserverList<SiteEngagementObserver> observer_list_; 257 base::ObserverList<SiteEngagementObserver> observer_list_;
239 258
240 base::WeakPtrFactory<SiteEngagementService> weak_factory_; 259 base::WeakPtrFactory<SiteEngagementService> weak_factory_;
241 260
242 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService); 261 DISALLOW_COPY_AND_ASSIGN(SiteEngagementService);
243 }; 262 };
244 263
245 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_ 264 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_score_unittest.cc ('k') | chrome/browser/engagement/site_engagement_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698