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

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

Issue 2188953004: Adding more functionality to BudgetDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 4303bb5934ae80169355df7280de2e571d182241..49df76bc3e0a919539e22c4600c39344b51dc919 100644
--- a/chrome/browser/budget_service/budget_database.h
+++ b/chrome/browser/budget_service/budget_database.h
@@ -16,6 +16,7 @@
#include "components/leveldb_proto/proto_database.h"
namespace base {
+class Clock;
class SequencedTaskRunner;
}
@@ -32,13 +33,8 @@ class BudgetDatabase {
// Data structure for returing the budget decay expectations to the caller.
using BudgetExpectation = std::list<std::pair<double, double>>;
- // Callback for the basic GetBudget call.
- using GetValueCallback =
- base::Callback<void(bool success,
- std::unique_ptr<budget_service::Budget>)>;
-
// Callback for setting a budget value.
- using SetValueCallback = base::Callback<void(bool success)>;
+ using StoreBudgetCallback = base::Callback<void(bool success)>;
// Callback for getting a list of all budget chunks.
using GetBudgetDetailsCallback = base::Callback<
@@ -51,20 +47,24 @@ class BudgetDatabase {
const scoped_refptr<base::SequencedTaskRunner>& task_runner);
~BudgetDatabase();
- void GetValue(const GURL& origin, const GetValueCallback& callback);
- void SetValue(const GURL& origin,
- const budget_service::Budget& budget,
- const SetValueCallback& callback);
-
// Get the full budget expectation for the origin. This will return any
// debt as well as a sequence of time points and the expected budget at
// those times.
void GetBudgetDetails(const GURL& origin,
const GetBudgetDetailsCallback& callback);
+ void AddBudget(const GURL& origin,
Peter Beverloo 2016/08/01 17:33:09 +docs
harkness 2016/08/03 11:17:48 Done.
+ double amount,
+ const StoreBudgetCallback& callback);
+
private:
+ friend class BudgetDatabaseTest;
+
+ // Used to allow tests to change time for testing.
+ void SetClockForTesting(std::unique_ptr<base::Clock> clock);
+
// Data structure for caching budget information.
- using BudgetChunks = std::vector<std::pair<double, double>>;
+ using BudgetChunks = std::list<std::pair<double, double>>;
Peter Beverloo 2016/08/01 17:33:09 Merge error or deliberate?
harkness 2016/08/03 11:17:48 oops, merge error.
using BudgetInfo = std::pair<double, BudgetChunks>;
using AddToCacheCallback = base::Callback<void(bool success)>;
@@ -80,12 +80,18 @@ class BudgetDatabase {
const GetBudgetDetailsCallback& callback,
bool success);
+ void WriteCachedValuesToDatabase(const GURL& origin,
+ const StoreBudgetCallback& callback);
+
// The database for storing budget information.
std::unique_ptr<leveldb_proto::ProtoDatabase<budget_service::Budget>> db_;
// Cached data for the origins which have been loaded.
std::unordered_map<std::string, BudgetInfo> budget_map_;
+ // The clock used to vend times.
+ std::unique_ptr<base::Clock> clock_;
+
base::WeakPtrFactory<BudgetDatabase> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BudgetDatabase);
« 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