OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_ |
| 6 #define CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "components/leveldb_proto/proto_database.h" |
| 14 |
| 15 namespace base { |
| 16 class SequencedTaskRunner; |
| 17 } |
| 18 |
| 19 namespace budget_service { |
| 20 class Budget; |
| 21 } |
| 22 |
| 23 class GURL; |
| 24 |
| 25 // A class used to asynchronously read and write details of the budget |
| 26 // assigned to an origin. The class uses an underlying LevelDB. |
| 27 class BudgetDatabase { |
| 28 public: |
| 29 // Callback for the basic GetBudget call. |
| 30 using GetValueCallback = |
| 31 base::Callback<void(bool success, |
| 32 std::unique_ptr<budget_service::Budget>)>; |
| 33 |
| 34 // Callback for setting a budget value. |
| 35 using SetValueCallback = base::Callback<void(bool success)>; |
| 36 |
| 37 // The database_dir specifies the location of the budget information on |
| 38 // disk. The task_runner is used by the ProtoDatabase to handle all blocking |
| 39 // calls and disk access. |
| 40 BudgetDatabase(const base::FilePath& database_dir, |
| 41 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 42 ~BudgetDatabase(); |
| 43 |
| 44 void GetValue(const GURL& origin, const GetValueCallback& callback); |
| 45 void SetValue(const GURL& origin, |
| 46 const budget_service::Budget& budget, |
| 47 const SetValueCallback& callback); |
| 48 |
| 49 private: |
| 50 void OnDatabaseInit(bool success); |
| 51 |
| 52 // The database for storing budget information. |
| 53 std::unique_ptr<leveldb_proto::ProtoDatabase<budget_service::Budget>> db_; |
| 54 |
| 55 base::WeakPtrFactory<BudgetDatabase> weak_ptr_factory_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(BudgetDatabase); |
| 58 }; |
| 59 |
| 60 #endif // CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_ |
OLD | NEW |