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

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

Issue 2107173002: Add the future storage framework for the BudgetDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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
new file mode 100644
index 0000000000000000000000000000000000000000..3fed36fb3951681bf355eadf1eb859a353c24241
--- /dev/null
+++ b/chrome/browser/budget_service/budget_database.h
@@ -0,0 +1,56 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_
+#define CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_
+
+#include <memory>
+
+#include "base/callback_forward.h"
+#include "base/memory/weak_ptr.h"
Peter Beverloo 2016/07/05 13:01:48 +base/macros.h for brownie points :)
harkness 2016/07/06 13:42:36 Done.
+#include "base/run_loop.h"
Peter Beverloo 2016/07/05 13:01:48 unused
harkness 2016/07/06 13:42:36 Done.
+#include "base/sequenced_task_runner.h"
Peter Beverloo 2016/07/05 13:01:48 forward declare? (it has a fairly heavy include-tr
harkness 2016/07/06 13:42:36 Done.
+#include "components/leveldb_proto/proto_database.h"
+#include "url/gurl.h"
Peter Beverloo 2016/07/05 13:01:48 forward declare?
harkness 2016/07/06 13:42:36 Done.
+
+namespace budget_service {
+class Budget;
+}
+
+// A class used to asynchronously read and write details of the budget
+// assigned to an origin. The class uses an underlying levelDB.
Peter Beverloo 2016/07/05 13:01:48 levelDB -> LevelDB (product name)
harkness 2016/07/06 13:42:36 Done.
+class BudgetDatabase {
+ public:
+ // 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)>;
+
+ // 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.
+ BudgetDatabase(const base::FilePath& database_dir,
+ 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);
+
+ private:
+ void OnDatabaseInit(bool success);
+
+ // The database for storing budget information.
+ std::unique_ptr<leveldb_proto::ProtoDatabase<budget_service::Budget>> db_;
+
+ base::WeakPtrFactory<BudgetDatabase> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BudgetDatabase);
+};
+
+#endif // CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_

Powered by Google App Engine
This is Rietveld 408576698