Chromium Code Reviews| 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 6583fb4308faa247eb167692c80ad376bd739737..4360bd05d52e9a8350b326ee8fb27db5c8421df7 100644 |
| --- a/chrome/browser/budget_service/budget_database.h |
| +++ b/chrome/browser/budget_service/budget_database.h |
| @@ -74,6 +74,23 @@ class BudgetDatabase { |
| double amount, |
| const StoreBudgetCallback& callback); |
| + // Add budget based on engagement with an origin. The caller specifies the |
| + // engagement score of the origin, and the method calculates when engagement |
| + // budget was last awarded and awards a portion of the score based on that. |
| + // Callback is invoked after the value is written to storage. This should |
| + // only be called after the budget has been read from the database. |
| + void AddEngagementBudget(const GURL& origin, |
| + double engagementScore, |
| + const StoreBudgetCallback& callback); |
| + |
| + // Spend a particular amount of budget for an origin. The callback specifies |
|
johnme
2016/08/19 18:48:36
Nit: s/specifies/takes/
harkness
2016/08/22 13:46:26
Done.
|
| + // 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. This should only be called after the budget has been read. |
|
johnme
2016/08/19 18:48:36
It seems a slightly awkward constraint that "This
harkness
2016/08/22 13:46:26
Peter and I had a long discussion about how much w
johnme
2016/08/22 14:50:31
Doesn't that just mean you'll have to add equivale
|
| + void SpendBudget(const GURL& origin, |
| + double amount, |
| + const StoreBudgetCallback& callback); |
| + |
| private: |
| friend class BudgetDatabaseTest; |
| @@ -95,6 +112,18 @@ class BudgetDatabase { |
| // Data structure for caching budget information. |
| using BudgetChunks = std::vector<BudgetChunk>; |
| + // Holds information about the overall budget for a site. This includes the |
| + // time the budget was last incremented, as well as a list of budget chunks |
| + // which have been awarded. |
| + struct BudgetInfo { |
| + BudgetInfo(); |
| + BudgetInfo(const BudgetInfo& other); |
| + ~BudgetInfo(); |
| + |
| + base::Time last_engagement_award; |
| + BudgetChunks chunks; |
| + }; |
| + |
| using AddToCacheCallback = base::Callback<void(bool success)>; |
| void OnDatabaseInit(bool success); |
| @@ -119,7 +148,7 @@ class BudgetDatabase { |
| std::unique_ptr<leveldb_proto::ProtoDatabase<budget_service::Budget>> db_; |
| // Cached data for the origins which have been loaded. |
| - std::unordered_map<std::string, BudgetChunks> budget_map_; |
| + std::unordered_map<std::string, BudgetInfo> budget_map_; |
| // The clock used to vend times. |
| std::unique_ptr<base::Clock> clock_; |