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

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

Issue 2326523003: Connect Mojo budget_service to BudgetManager implementation of Reserve. (Closed)
Patch Set: 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.cc
diff --git a/chrome/browser/budget_service/budget_manager.cc b/chrome/browser/budget_service/budget_manager.cc
index 94b5f9f1d7006bb9717bf0ed7d1d948057b2ddfb..897f9062e65204af43b25ebccd8d93349e5ac735 100644
--- a/chrome/browser/budget_service/budget_manager.cc
+++ b/chrome/browser/budget_service/budget_manager.cc
@@ -75,10 +75,9 @@ void BudgetManager::Reserve(const GURL& origin,
const ReserveCallback& callback) {
DCHECK_EQ(origin, origin.GetOrigin());
- db_.SpendBudget(
- origin, GetCost(type),
- base::Bind(&BudgetManager::DidReserve, weak_ptr_factory_.GetWeakPtr(),
- origin, type, callback));
+ db_.SpendBudget(origin, GetCost(type),
+ base::Bind(&BudgetManager::DidReserve,
+ weak_ptr_factory_.GetWeakPtr(), origin, callback));
}
void BudgetManager::Consume(const GURL& origin,
@@ -104,19 +103,30 @@ void BudgetManager::Consume(const GURL& origin,
// If there wasn't a reservation already, try to directly consume budget.
// The callback will return directly to the caller.
- db_.SpendBudget(origin, GetCost(type), callback);
+ db_.SpendBudget(origin, GetCost(type),
+ base::Bind(&BudgetManager::DidConsume,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
-void BudgetManager::DidReserve(const GURL& origin,
- blink::mojom::BudgetOperationType type,
- const ReserveCallback& callback,
+void BudgetManager::DidConsume(const ConsumeCallback& callback,
+ blink::mojom::BudgetServiceErrorType error,
bool success) {
- if (!success) {
- callback.Run(false);
+ // The caller of Consume only cares whether it succeeded or failed and not
+ // why. So, only return a combined bool.
+ if (error != blink::mojom::BudgetServiceErrorType::NONE || !success) {
Peter Beverloo 2016/09/08 17:16:06 Let's remove "!success" from this conditional, so
harkness 2016/09/13 13:41:29 Good point. Updated.
+ callback.Run(false /* success */);
return;
}
+ callback.Run(success);
+}
+
+void BudgetManager::DidReserve(const GURL& origin,
+ const ReserveCallback& callback,
+ blink::mojom::BudgetServiceErrorType error,
+ bool success) {
+ // If the call succeeded, write the new reservation into the map.
+ if (success && error == blink::mojom::BudgetServiceErrorType::NONE)
+ reservation_map_[origin.spec()]++;
- // Write the new reservation into the map.
- reservation_map_[origin.spec()]++;
- callback.Run(true);
+ callback.Run(error, success);
}

Powered by Google App Engine
This is Rietveld 408576698