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

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

Issue 2173833002: Expand the functionality of the BudgetDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted change I decided against. 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 155f23d22c8f6e708c1f7282669e55b7ce0a9ae0..63de476352a819a8dd3e8c00fac0455bded7c758 100644
--- a/chrome/browser/budget_service/budget_database.h
+++ b/chrome/browser/budget_service/budget_database.h
@@ -5,9 +5,11 @@
#ifndef CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_
#define CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_
+#include <list>
#include <memory>
#include "base/callback_forward.h"
+#include "base/containers/hash_tables.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/leveldb_proto/proto_database.h"
@@ -26,6 +28,13 @@ class GURL;
// assigned to an origin. The class uses an underlying LevelDB.
class BudgetDatabase {
public:
+ // Data structure for caching budget information.
+ typedef std::list<std::pair<double, double>> BudgetChunks;
Peter Beverloo 2016/07/22 16:14:52 std::vector? I don't think any of the list-over-ve
harkness 2016/07/26 16:42:07 It doesn't really matter for my purposes. Access w
Peter Beverloo 2016/07/26 17:26:20 std::vector is more popular in Chromium code by an
harkness 2016/07/27 10:59:02 I changed BudgetChunks to be a vector, but because
+ typedef std::pair<double, BudgetChunks> BudgetInfo;
Peter Beverloo 2016/07/22 16:14:52 It looks like both BudgetChunks and BudgetInfo can
harkness 2016/07/26 16:42:07 Ah yes, I'd planned to talk to you about this. You
Peter Beverloo 2016/07/26 17:26:20 No, there are at most three blocks, one of each {p
harkness 2016/07/27 10:59:02 Done.
+
+ // Data structure for returing the budget decay expectations to the caller.
+ typedef std::list<std::pair<double, double>> BudgetExpectation;
Peter Beverloo 2016/07/22 16:14:52 All three of these should be using `using`, as you
harkness 2016/07/26 16:42:08 Done.
+
// Callback for the basic GetBudget call.
using GetValueCallback =
base::Callback<void(bool success,
@@ -34,6 +43,12 @@ class BudgetDatabase {
// Callback for setting a budget value.
using SetValueCallback = base::Callback<void(bool success)>;
+ // Callback for getting a list of all budget chunks.
+ using GetBudgetDetailsCallback = base::Callback<
+ void(bool success, double debt, const BudgetExpectation& expectation)>;
+
+ using AddToCacheCallback = base::Callback<void(bool success)>;
Peter Beverloo 2016/07/22 16:14:52 private
harkness 2016/07/26 16:42:07 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.
@@ -46,12 +61,30 @@ class BudgetDatabase {
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);
+
private:
void OnDatabaseInit(bool success);
+ void AddToCache(const GURL& origin,
+ const AddToCacheCallback& callback,
+ bool success,
+ std::unique_ptr<budget_service::Budget> budget);
+
+ void ReturnBudgetDetails(const GURL& origin,
+ const GetBudgetDetailsCallback& callback,
+ bool success);
+
// 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.
+ base::hash_map<std::string, BudgetInfo> budget_map_;
Peter Beverloo 2016/07/22 16:14:52 base::hash_map<> is deprecated, please use std::un
harkness 2016/07/26 16:42:08 Done.
+
base::WeakPtrFactory<BudgetDatabase> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BudgetDatabase);

Powered by Google App Engine
This is Rietveld 408576698