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

Side by Side Diff: chrome/browser/budget_service/budget_manager.h

Issue 2265173002: Created Mojo BudgetService implementation in chrome/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo_service
Patch Set: Remove use of local variable and call GetCost directly. 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
« no previous file with comments | « chrome/browser/DEPS ('k') | chrome/browser/budget_service/budget_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_BUDGET_SERVICE_BUDGET_MANAGER_H_ 5 #ifndef CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_
6 #define CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_ 6 #define CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "components/keyed_service/core/keyed_service.h" 13 #include "components/keyed_service/core/keyed_service.h"
14 #include "third_party/WebKit/public/platform/modules/budget_service/budget_servi ce.mojom.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 class Profile; 17 class Profile;
17 18
18 namespace base { 19 namespace base {
19 class Clock; 20 class Clock;
20 } 21 }
21 22
22 namespace user_prefs { 23 namespace user_prefs {
23 class PrefRegistrySyncable; 24 class PrefRegistrySyncable;
24 } 25 }
25 26
26 // A budget manager to help Chrome decide how much background work a service 27 // A budget manager to help Chrome decide how much background work a service
27 // worker should be able to do on behalf of the user. The budget is calculated 28 // worker should be able to do on behalf of the user. The budget is calculated
28 // based on the Site Engagment Score and is consumed when a origin does 29 // based on the Site Engagment Score and is consumed when a origin does
29 // background work on behalf of the user. 30 // background work on behalf of the user.
30 class BudgetManager : public KeyedService { 31 class BudgetManager : public KeyedService {
31 public: 32 public:
32 explicit BudgetManager(Profile* profile); 33 explicit BudgetManager(Profile* profile);
33 ~BudgetManager() override; 34 ~BudgetManager() override;
34 35
35 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
36 37
37 enum class CostType {
38 // The cost of silencing a push message.
39 SILENT_PUSH = 0,
40 };
41
42 // Query for the base cost for any background processing. 38 // Query for the base cost for any background processing.
43 static double GetCost(CostType type); 39 static double GetCost(blink::mojom::BudgetOperationType type);
44 40
45 using GetBudgetCallback = base::Callback<void(double budget)>; 41 using GetBudgetCallback = base::Callback<void(double budget)>;
46 42
47 // Get the budget associated with the origin. This is passed to the 43 // Get the budget associated with the origin. This is passed to the
48 // callback. Budget will be a value between 0.0 and 44 // callback. Budget will be a value between 0.0 and
49 // SiteEngagementScore::kMaxPoints. 45 // SiteEngagementScore::kMaxPoints.
50 void GetBudget(const GURL& origin, const GetBudgetCallback& callback); 46 void GetBudget(const GURL& origin, const GetBudgetCallback& callback);
51 47
52 // Store the budget associated with the origin. Budget should be a value 48 // Store the budget associated with the origin. Budget should be a value
53 // between 0.0 and SiteEngagementScore::kMaxPoints. closure will be called 49 // between 0.0 and SiteEngagementScore::kMaxPoints. closure will be called
54 // when the store completes. 50 // when the store completes.
55 void StoreBudget(const GURL& origin, 51 void StoreBudget(const GURL& origin,
56 double budget, 52 double budget,
57 const base::Closure& closure); 53 const base::Closure& closure);
58 54
59 private: 55 private:
60 friend class BudgetManagerTest; 56 friend class BudgetManagerTest;
61 57
62 // Used to allow tests to fast forward/reverse time. 58 // Used to allow tests to fast forward/reverse time.
63 void SetClockForTesting(std::unique_ptr<base::Clock> clock); 59 void SetClockForTesting(std::unique_ptr<base::Clock> clock);
64 60
65 // The clock used to vend times. 61 // The clock used to vend times.
66 std::unique_ptr<base::Clock> clock_; 62 std::unique_ptr<base::Clock> clock_;
67 63
68 Profile* profile_; 64 Profile* profile_;
69 DISALLOW_COPY_AND_ASSIGN(BudgetManager); 65 DISALLOW_COPY_AND_ASSIGN(BudgetManager);
70 }; 66 };
71 67
72 #endif // CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_ 68 #endif // CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/DEPS ('k') | chrome/browser/budget_service/budget_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698