Index: chrome/browser/budget_service/budget_database.h |
diff --git a/chrome/browser/budget_service/budget_database.h b/chrome/browser/budget_service/budget_database.h |
index b2017aad82c96302f4d113eae5d36bbf9a1120cf..32f2a9104b07ce0bc07fa4474b5b36a17383a2d7 100644 |
--- a/chrome/browser/budget_service/budget_database.h |
+++ b/chrome/browser/budget_service/budget_database.h |
@@ -32,12 +32,15 @@ class Profile; |
// assigned to an origin. The class uses an underlying LevelDB. |
class BudgetDatabase { |
public: |
- // Callback for setting a budget value. |
- using StoreBudgetCallback = base::Callback<void(bool success)>; |
- |
// Callback for getting a list of all budget chunks. |
using GetBudgetCallback = blink::mojom::BudgetService::GetBudgetCallback; |
+ // Callback for SpendBudget. This will be invoked only after the spend has |
+ // been written to the database. It takes two values, an error type which |
+ // indicates if there was a particular error, and a bool that indicates |
+ // whether the origin had budget to spend. |
+ using SpendBudgetCallback = blink::mojom::BudgetService::ReserveCallback; |
Peter Beverloo
2016/09/08 17:16:06
We should probably just redefine the callback form
harkness
2016/09/13 13:41:28
Done.
|
+ |
// The database_dir specifies the location of the budget information on |
// disk. The task_runner is used by the ProtoDatabase to handle all blocking |
// calls and disk access. |
@@ -50,13 +53,11 @@ class BudgetDatabase { |
// sequence of time points and the expected budget at those times. |
void GetBudgetDetails(const GURL& origin, const GetBudgetCallback& callback); |
- // Spend a particular amount of budget for an origin. The callback takes |
- // a boolean which indicates whether the origin had enough budget to spend. |
- // If it returns success, then the budget was deducted and the result written |
- // to the database. |
+ // Spend a particular amount of budget for an origin. The callback indicates |
+ // whether there was an error and if the origin had enough budget. |
void SpendBudget(const GURL& origin, |
double amount, |
- const StoreBudgetCallback& callback); |
+ const SpendBudgetCallback& callback); |
private: |
friend class BudgetDatabaseTest; |
@@ -93,8 +94,10 @@ class BudgetDatabase { |
DISALLOW_COPY_AND_ASSIGN(BudgetInfo); |
}; |
- using AddToCacheCallback = base::Callback<void(bool success)>; |
- using SyncCacheCallback = base::Callback<void(bool success)>; |
+ // Callback for writing budget values to the database. |
+ using StoreBudgetCallback = base::Callback<void(bool success)>; |
+ |
+ using CacheCallback = base::Callback<void(bool success)>; |
void OnDatabaseInit(bool success); |
@@ -103,7 +106,7 @@ class BudgetDatabase { |
double GetBudget(const GURL& origin) const; |
void AddToCache(const GURL& origin, |
- const AddToCacheCallback& callback, |
+ const CacheCallback& callback, |
bool success, |
std::unique_ptr<budget_service::Budget> budget); |
@@ -113,15 +116,17 @@ class BudgetDatabase { |
void SpendBudgetAfterSync(const GURL& origin, |
double amount, |
- const StoreBudgetCallback& callback, |
+ const SpendBudgetCallback& callback, |
bool success); |
+ void SpendBudgetAfterWrite(const SpendBudgetCallback& callback, bool success); |
+ |
void WriteCachedValuesToDatabase(const GURL& origin, |
const StoreBudgetCallback& callback); |
- void SyncCache(const GURL& origin, const SyncCacheCallback& callback); |
+ void SyncCache(const GURL& origin, const CacheCallback& callback); |
void SyncLoadedCache(const GURL& origin, |
- const SyncCacheCallback& callback, |
+ const CacheCallback& callback, |
bool success); |
// Add budget based on engagement with an origin. The method queries for the |