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

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

Issue 1977423002: Added UMA stats to track the budget for any service worker which receives a (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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 15 matching lines...) Expand all
26 // worker should be able to do on behalf of the user. The budget is calculated 26 // worker should be able to do on behalf of the user. The budget is calculated
27 // based on the Site Engagment Score and is consumed when a service worker does 27 // based on the Site Engagment Score and is consumed when a service worker does
28 // background work on behalf of the user. 28 // background work on behalf of the user.
29 class BackgroundBudgetService : public KeyedService { 29 class BackgroundBudgetService : public KeyedService {
30 public: 30 public:
31 explicit BackgroundBudgetService(Profile* profile); 31 explicit BackgroundBudgetService(Profile* profile);
32 ~BackgroundBudgetService() override; 32 ~BackgroundBudgetService() override;
33 33
34 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 34 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
35 35
36 enum CostType {
Peter Beverloo 2016/05/17 13:51:02 nit: enum class
harkness 2016/05/17 15:49:32 Done.
37 // The cost of silencing a push message.
38 SILENT_PUSH_COST = 0,
39
40 MAX_COST_TYPE
41 };
42
43 // Query for the base cost for any background processing.
44 static double GetBackgroundProcessingCost(CostType type);
45
36 // Get the budget associated with the origin. This is returned as the double 46 // Get the budget associated with the origin. This is returned as the double
37 // budget. Budget will be a value between 0.0 and 47 // budget. Budget will be a value between 0.0 and
38 // SiteEngagementScore::kMaxPoints. 48 // SiteEngagementScore::kMaxPoints.
39 double GetBudget(const GURL& origin); 49 double GetBudget(const GURL& origin);
40 50
41 // Store the budget associated with the origin. Budget should be a value 51 // Store the budget associated with the origin. Budget should be a value
42 // between 0.0 and SiteEngagementScore::kMaxPoints. 52 // between 0.0 and SiteEngagementScore::kMaxPoints.
43 void StoreBudget(const GURL& origin, double budget); 53 void StoreBudget(const GURL& origin, double budget);
44 54
45 private: 55 private:
46 friend class BackgroundBudgetServiceTest; 56 friend class BackgroundBudgetServiceTest;
47 57
48 // Used to allow tests to fast forward/reverse time. 58 // Used to allow tests to fast forward/reverse time.
49 void SetClockForTesting(std::unique_ptr<base::Clock> clock); 59 void SetClockForTesting(std::unique_ptr<base::Clock> clock);
50 60
51 // The clock used to vend times. 61 // The clock used to vend times.
52 std::unique_ptr<base::Clock> clock_; 62 std::unique_ptr<base::Clock> clock_;
53 63
64 // Array holding the costs for various background operations.
65 static double costs_[];
Peter Beverloo 2016/05/17 13:51:01 This can live in an anonymous namespace, no need t
harkness 2016/05/17 15:49:32 As discussed in person, I'm just returning the res
66
54 Profile* profile_; 67 Profile* profile_;
55 DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService); 68 DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService);
56 }; 69 };
57 70
58 #endif // CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ 71 #endif // CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698