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

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

Issue 2788413003: Add SiteEngagementService::GetAllDetails(), to return detailed scores. (Closed)
Patch Set: Fix notifications permission logic & test Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_SCORE_H_ 5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_
6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ 6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_
7 7
8 #include <array> 8 #include <array>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/engagement/site_engagement_details.mojom.h"
15 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" 16 #include "third_party/WebKit/public/platform/site_engagement.mojom.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 18
18 namespace base { 19 namespace base {
19 class Clock; 20 class Clock;
20 } 21 }
21 22
22 class HostContentSettingsMap; 23 class HostContentSettingsMap;
23 24
24 class SiteEngagementScore { 25 class SiteEngagementScore {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 HostContentSettingsMap* settings); 131 HostContentSettingsMap* settings);
131 SiteEngagementScore(SiteEngagementScore&& other); 132 SiteEngagementScore(SiteEngagementScore&& other);
132 ~SiteEngagementScore(); 133 ~SiteEngagementScore();
133 134
134 SiteEngagementScore& operator=(SiteEngagementScore&& other); 135 SiteEngagementScore& operator=(SiteEngagementScore&& other);
135 136
136 // Adds |points| to this score, respecting daily limits and the maximum 137 // Adds |points| to this score, respecting daily limits and the maximum
137 // possible score. Decays the score if it has not been updated recently 138 // possible score. Decays the score if it has not been updated recently
138 // enough. 139 // enough.
139 void AddPoints(double points); 140 void AddPoints(double points);
140 double GetScore() const; 141
142 // Returns the total score, taking into account the base, bonus and maximum
143 // values.
144 double GetTotalScore() const;
145
146 // Returns a structure containing the origin URL and score, and details
147 // of the base and bonus scores. Note that the |score| is limited to
148 // kMaxPoints, while the detailed scores are returned raw.
149 mojom::SiteEngagementDetails GetDetails() const;
dcheng 2017/04/11 05:28:06 FWIW, this seems potentially dicey. I think this i
Wez 2017/04/11 19:57:07 Checked w/ yzshen: Intention is that Mojo structs
141 150
142 // Writes the values in this score into |settings_map_|. 151 // Writes the values in this score into |settings_map_|.
143 void Commit(); 152 void Commit();
144 153
145 // Returns the discrete engagement level for this score. 154 // Returns the discrete engagement level for this score.
146 blink::mojom::EngagementLevel GetEngagementLevel() const; 155 blink::mojom::EngagementLevel GetEngagementLevel() const;
147 156
148 // Returns true if the maximum number of points today has been added. 157 // Returns true if the maximum number of points today has been added.
149 bool MaxPointsPerDayAdded() const; 158 bool MaxPointsPerDayAdded() const;
150 159
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 static const char* kLastShortcutLaunchTimeKey; 198 static const char* kLastShortcutLaunchTimeKey;
190 199
191 // This version of the constructor is used in unit tests. 200 // This version of the constructor is used in unit tests.
192 SiteEngagementScore(base::Clock* clock, 201 SiteEngagementScore(base::Clock* clock,
193 const GURL& origin, 202 const GURL& origin,
194 std::unique_ptr<base::DictionaryValue> score_dict); 203 std::unique_ptr<base::DictionaryValue> score_dict);
195 204
196 // Determine the score, accounting for any decay. 205 // Determine the score, accounting for any decay.
197 double DecayedScore() const; 206 double DecayedScore() const;
198 207
199 // Determine any score bonus from having installed shortcuts. 208 // Determine bonus from being installed, and having been launched recently..
200 double BonusScore() const; 209 double BonusIfShortcutLaunched() const;
210
211 // Determine bonus from having been granted notifications permission.
212 double BonusIfHasNotifications() const;
201 213
202 // Updates the content settings dictionary |score_dict| with the current score 214 // Updates the content settings dictionary |score_dict| with the current score
203 // fields. Returns true if |score_dict| changed, otherwise return false. 215 // fields. Returns true if |score_dict| changed, otherwise return false.
204 bool UpdateScoreDict(base::DictionaryValue* score_dict); 216 bool UpdateScoreDict(base::DictionaryValue* score_dict);
205 217
206 // The clock used to vend times. Enables time travelling in tests. Owned by 218 // The clock used to vend times. Enables time travelling in tests. Owned by
207 // the SiteEngagementService. 219 // the SiteEngagementService.
208 base::Clock* clock_; 220 base::Clock* clock_;
209 221
210 // |raw_score_| is the score before any decay is applied. 222 // |raw_score_| is the score before any decay is applied.
(...skipping 18 matching lines...) Expand all
229 // The origin this score represents. 241 // The origin this score represents.
230 GURL origin_; 242 GURL origin_;
231 243
232 // The settings to write this score to when Commit() is called. 244 // The settings to write this score to when Commit() is called.
233 HostContentSettingsMap* settings_map_; 245 HostContentSettingsMap* settings_map_;
234 246
235 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore); 247 DISALLOW_COPY_AND_ASSIGN(SiteEngagementScore);
236 }; 248 };
237 249
238 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_ 250 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_SCORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698