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

Side by Side Diff: chrome/browser/push_messaging/background_budget_service.h

Issue 1887623002: Replace the 1 in 10 grace period with an accumulating budget based on SES. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Integrated code review comments Created 4 years, 7 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_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ 5 #ifndef CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_
6 #define CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ 6 #define CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
Peter Beverloo 2016/05/04 15:41:52 IWYU: #include <memory>
harkness 2016/05/09 15:33:27 Done.
9 9
10 #include "base/gtest_prod_util.h"
10 #include "components/keyed_service/core/keyed_service.h" 11 #include "components/keyed_service/core/keyed_service.h"
11 #include "url/gurl.h" 12 #include "url/gurl.h"
12 13
13 class Profile; 14 class Profile;
14 15
16 namespace base {
17 class Clock;
18 }
19
15 namespace user_prefs { 20 namespace user_prefs {
16 class PrefRegistrySyncable; 21 class PrefRegistrySyncable;
17 } 22 }
18 23
19 // A budget service to help Chrome decide how much background work a service 24 // A budget service to help Chrome decide how much background work a service
20 // worker should be able to do on behalf of the user. The budget currently 25 // worker should be able to do on behalf of the user. The budget is calculated
21 // implements a grace period of 1 non-visual notification in 10. 26 // based on the Site Engagment Score and is consumed when a service worker
27 // doesn't show a notification when it needed to.
Peter Beverloo 2016/05/04 15:41:52 I've noticed that you're very diligent in keeping
harkness 2016/05/09 15:33:27 I'll generify the comment.
22 class BackgroundBudgetService : public KeyedService { 28 class BackgroundBudgetService : public KeyedService {
23 public: 29 public:
24 explicit BackgroundBudgetService(Profile* profile); 30 explicit BackgroundBudgetService(Profile* profile);
25 ~BackgroundBudgetService() override {} 31 ~BackgroundBudgetService() override;
26 32
27 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 33 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
28 34
29 // Get the budget associated with the origin. This currently tracks a string 35 // Get the budget associated with the origin. This is returned as the double
30 // which holds 0 and 1 for the last 10 push messages and whether they 36 // budget. Budget will be a value between 0.0 and
31 // triggered a visual notification. 37 // SiteEngagementScore::kMaxPoints.
32 std::string GetBudget(const GURL& origin); 38 double GetBudget(const GURL& origin);
33 39
34 // Store the budget associated with the origin. notifications_shown is 40 // Store the budget associated with the origin. Budget should be a value
35 // expected to be a string encoding whether the last 10 push messages 41 // between 0.0 and SiteEngagementScore::kMaxPoints.
36 // triggered 42 void StoreBudget(const GURL& origin, double budget);
37 // a visual notification.
38 void StoreBudget(const GURL& origin, const std::string& notifications_shown);
39 43
40 private: 44 private:
45 FRIEND_TEST_ALL_PREFIXES(BackgroundBudgetServiceTest, GetBudgetNoElapsedTime);
46 FRIEND_TEST_ALL_PREFIXES(BackgroundBudgetServiceTest, GetBudgetElapsedTime);
47 FRIEND_TEST_ALL_PREFIXES(BackgroundBudgetServiceTest,
48 GetBudgetConsumedOverTime);
49
50 // Only called directly by tests.
51 BackgroundBudgetService(Profile* profile, std::unique_ptr<base::Clock> clock);
Peter Beverloo 2016/05/04 15:41:52 You could move some of the complexity from the Bac
harkness 2016/05/09 15:33:27 As discussed in person, I've combined the two cons
52
53 // The clock used to vend times.
54 std::unique_ptr<base::Clock> clock_;
55
41 Profile* profile_; 56 Profile* profile_;
42 DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService); 57 DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService);
43 }; 58 };
44 59
45 #endif // CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ 60 #endif // CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698