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

Unified Diff: chrome/browser/budget_service/budget_manager.h

Issue 2272563005: Start plumbing connections from the BudgetManager to the BudgetDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the task runner 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/budget_service/budget_manager.h
diff --git a/chrome/browser/budget_service/budget_manager.h b/chrome/browser/budget_service/budget_manager.h
index 33a0371fb21ea87a56216200ddb01bce0a2163dd..7bc38630da4c49a06d4f70ce28a6869c8a522e88 100644
--- a/chrome/browser/budget_service/budget_manager.h
+++ b/chrome/browser/budget_service/budget_manager.h
@@ -10,6 +10,7 @@
#include "base/callback_forward.h"
#include "base/gtest_prod_util.h"
+#include "chrome/browser/budget_service/budget_database.h"
#include "components/keyed_service/core/keyed_service.h"
#include "third_party/WebKit/public/platform/modules/budget_service/budget_service.mojom.h"
#include "url/gurl.h"
@@ -39,6 +40,8 @@ class BudgetManager : public KeyedService {
static double GetCost(blink::mojom::BudgetOperationType type);
using GetBudgetCallback = base::Callback<void(double budget)>;
+ using ReserveCallback = base::Callback<void(bool success)>;
+ using ConsumeCallback = base::Callback<void(bool success)>;
// Get the budget associated with the origin. This is passed to the
// callback. Budget will be a value between 0.0 and
@@ -52,9 +55,29 @@ class BudgetManager : public KeyedService {
double budget,
const base::Closure& closure);
+ // Spend enough budget to cover the cost of the desired action and create
+ // a reservation for that action. If this returns true to the callback, then
+ // the next action will consume that reservation and not cost any budget.
+ void Reserve(const GURL& origin,
+ blink::mojom::BudgetOperationType type,
+ const ReserveCallback& callback);
+
+ // Spend budget, first consuming a reservation if one exists, or spend
+ // directly from the budget.
+ void Consume(const GURL& origin,
+ blink::mojom::BudgetOperationType type,
+ const ConsumeCallback& callback);
+
private:
friend class BudgetManagerTest;
+ // Called as a callback from BudgetDatabase after it has made a reserve
+ // decision.
+ void DidReserve(const GURL& origin,
+ blink::mojom::BudgetOperationType type,
+ const ReserveCallback& callback,
+ bool success);
+
// Used to allow tests to fast forward/reverse time.
void SetClockForTesting(std::unique_ptr<base::Clock> clock);
@@ -62,6 +85,11 @@ class BudgetManager : public KeyedService {
std::unique_ptr<base::Clock> clock_;
Profile* profile_;
+ BudgetDatabase db_;
+
+ std::unordered_map<std::string, int> reservation_map_;
+ base::WeakPtrFactory<BudgetManager> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(BudgetManager);
};
« no previous file with comments | « chrome/browser/budget_service/budget_database_unittest.cc ('k') | chrome/browser/budget_service/budget_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698