| 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_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 <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 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 "chrome/browser/budget_service/budget_database.h" | 13 #include "chrome/browser/budget_service/budget_database.h" |
| 14 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
| 15 #include "third_party/WebKit/public/platform/modules/budget_service/budget_servi
ce.mojom.h" | 15 #include "third_party/WebKit/public/platform/modules/budget_service/budget_servi
ce.mojom.h" |
| 16 | 16 |
| 17 class Profile; | 17 class Profile; |
| 18 | 18 |
| 19 namespace user_prefs { | |
| 20 class PrefRegistrySyncable; | |
| 21 } | |
| 22 | |
| 23 namespace url { | 19 namespace url { |
| 24 class Origin; | 20 class Origin; |
| 25 } | 21 } |
| 26 | 22 |
| 27 // A budget manager to help Chrome decide how much background work a service | 23 // A budget manager to help Chrome decide how much background work a service |
| 28 // worker should be able to do on behalf of the user. The budget is calculated | 24 // worker should be able to do on behalf of the user. The budget is calculated |
| 29 // based on the Site Engagment Score and is consumed when a origin does | 25 // based on the Site Engagment Score and is consumed when a origin does |
| 30 // background work on behalf of the user. | 26 // background work on behalf of the user. |
| 31 class BudgetManager : public KeyedService { | 27 class BudgetManager : public KeyedService { |
| 32 public: | 28 public: |
| 33 explicit BudgetManager(Profile* profile); | 29 explicit BudgetManager(Profile* profile); |
| 34 ~BudgetManager() override; | 30 ~BudgetManager() override; |
| 35 | 31 |
| 36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
| 37 | |
| 38 // Query for the base cost for any background processing. | 32 // Query for the base cost for any background processing. |
| 39 static double GetCost(blink::mojom::BudgetOperationType type); | 33 static double GetCost(blink::mojom::BudgetOperationType type); |
| 40 | 34 |
| 41 using GetBudgetCallback = blink::mojom::BudgetService::GetBudgetCallback; | 35 using GetBudgetCallback = blink::mojom::BudgetService::GetBudgetCallback; |
| 42 using ReserveCallback = blink::mojom::BudgetService::ReserveCallback; | 36 using ReserveCallback = blink::mojom::BudgetService::ReserveCallback; |
| 43 using ConsumeCallback = base::Callback<void(bool success)>; | 37 using ConsumeCallback = base::Callback<void(bool success)>; |
| 44 | 38 |
| 45 // Get the budget associated with the origin. This is passed to the | 39 // Get the budget associated with the origin. This is passed to the |
| 46 // callback. Budget will be a sequence of points describing the time and | 40 // callback. Budget will be a sequence of points describing the time and |
| 47 // the budget at that time. | 41 // the budget at that time. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 Profile* profile_; | 73 Profile* profile_; |
| 80 BudgetDatabase db_; | 74 BudgetDatabase db_; |
| 81 | 75 |
| 82 std::map<url::Origin, int> reservation_map_; | 76 std::map<url::Origin, int> reservation_map_; |
| 83 base::WeakPtrFactory<BudgetManager> weak_ptr_factory_; | 77 base::WeakPtrFactory<BudgetManager> weak_ptr_factory_; |
| 84 | 78 |
| 85 DISALLOW_COPY_AND_ASSIGN(BudgetManager); | 79 DISALLOW_COPY_AND_ASSIGN(BudgetManager); |
| 86 }; | 80 }; |
| 87 | 81 |
| 88 #endif // CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_ | 82 #endif // CHROME_BROWSER_BUDGET_SERVICE_BUDGET_MANAGER_H_ |
| OLD | NEW |