| OLD | NEW |
| 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_BACKGROUND_BUDGET_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_ |
| 6 #define CHROME_BROWSER_BUDGET_SERVICE_BACKGROUND_BUDGET_SERVICE_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 "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class Clock; | 19 class Clock; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace user_prefs { | 22 namespace user_prefs { |
| 23 class PrefRegistrySyncable; | 23 class PrefRegistrySyncable; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // A budget service to help Chrome decide how much background work a service | 26 // 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 | 27 // 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 service worker does | 28 // based on the Site Engagment Score and is consumed when a origin does |
| 29 // background work on behalf of the user. | 29 // background work on behalf of the user. |
| 30 class BackgroundBudgetService : public KeyedService { | 30 class BudgetManager : public KeyedService { |
| 31 public: | 31 public: |
| 32 explicit BackgroundBudgetService(Profile* profile); | 32 explicit BudgetManager(Profile* profile); |
| 33 ~BackgroundBudgetService() override; | 33 ~BudgetManager() override; |
| 34 | 34 |
| 35 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 35 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 36 | 36 |
| 37 enum class CostType { | 37 enum class CostType { |
| 38 // The cost of silencing a push message. | 38 // The cost of silencing a push message. |
| 39 SILENT_PUSH = 0, | 39 SILENT_PUSH = 0, |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // Query for the base cost for any background processing. | 42 // Query for the base cost for any background processing. |
| 43 static double GetCost(CostType type); | 43 static double GetCost(CostType type); |
| 44 | 44 |
| 45 using GetBudgetCallback = base::Callback<void(double budget)>; | 45 using GetBudgetCallback = base::Callback<void(double budget)>; |
| 46 | 46 |
| 47 // Get the budget associated with the origin. This is passed to the | 47 // Get the budget associated with the origin. This is passed to the |
| 48 // callback. Budget will be a value between 0.0 and | 48 // callback. Budget will be a value between 0.0 and |
| 49 // SiteEngagementScore::kMaxPoints. | 49 // SiteEngagementScore::kMaxPoints. |
| 50 void GetBudget(const GURL& origin, const GetBudgetCallback& callback); | 50 void GetBudget(const GURL& origin, const GetBudgetCallback& callback); |
| 51 | 51 |
| 52 // Store the budget associated with the origin. Budget should be a value | 52 // Store the budget associated with the origin. Budget should be a value |
| 53 // between 0.0 and SiteEngagementScore::kMaxPoints. closure will be called | 53 // between 0.0 and SiteEngagementScore::kMaxPoints. closure will be called |
| 54 // when the store completes. | 54 // when the store completes. |
| 55 void StoreBudget(const GURL& origin, | 55 void StoreBudget(const GURL& origin, |
| 56 double budget, | 56 double budget, |
| 57 const base::Closure& closure); | 57 const base::Closure& closure); |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 friend class BackgroundBudgetServiceTest; | 60 friend class BudgetManagerTest; |
| 61 | 61 |
| 62 // Used to allow tests to fast forward/reverse time. | 62 // Used to allow tests to fast forward/reverse time. |
| 63 void SetClockForTesting(std::unique_ptr<base::Clock> clock); | 63 void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| 64 | 64 |
| 65 // The clock used to vend times. | 65 // The clock used to vend times. |
| 66 std::unique_ptr<base::Clock> clock_; | 66 std::unique_ptr<base::Clock> clock_; |
| 67 | 67 |
| 68 Profile* profile_; | 68 Profile* profile_; |
| 69 DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService); | 69 DISALLOW_COPY_AND_ASSIGN(BudgetManager); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 #endif // CHROME_BROWSER_BUDGET_SERVICE_BACKGROUND_BUDGET_SERVICE_H_ | 72 #endif // CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_ |
| OLD | NEW |