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

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

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_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
« no previous file with comments | « no previous file | chrome/browser/budget_service/budget_database.cc » ('j') | chrome/browser/budget_service/budget_database.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698