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/memory/weak_ptr.h" |
| 12 #include "base/run_loop.h" |
| 13 #include "base/sequenced_task_runner.h" |
| 14 #include "components/leveldb_proto/proto_database.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace budget_service { |
| 18 class Budget; |
| 19 } |
| 20 |
| 21 // A class used to asynchronously read and write details of the budget |
| 22 // assigned to service workers. The class uses an underlying levelDB. |
| 23 class BudgetDatabase { |
| 24 public: |
| 25 // The database_dir specifies the location of the budget information on |
| 26 // disk. The task_runner is used by the ProtoDatabase to handle all blocking |
| 27 // calls and disk access. |
| 28 BudgetDatabase(const base::FilePath& database_dir, |
| 29 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 30 ~BudgetDatabase(); |
| 31 |
| 32 // Callback for the basic GetBudget call. |
| 33 using GetValueCallback = |
| 34 base::Callback<void(bool success, |
| 35 std::unique_ptr<budget_service::Budget>)>; |
| 36 |
| 37 // Callback for setting a budget value. |
| 38 using SetValueCallback = base::Callback<void(bool success)>; |
| 39 |
| 40 void GetValue(const GURL& origin, const GetValueCallback& callback); |
| 41 void SetValue(const GURL& origin, |
| 42 const budget_service::Budget& budget, |
| 43 const SetValueCallback& callback); |
| 44 |
| 45 private: |
| 46 void OnDatabaseInit(bool success); |
| 47 |
| 48 // The database for storing budget information. |
| 49 std::unique_ptr<leveldb_proto::ProtoDatabase<budget_service::Budget>> db_; |
| 50 |
| 51 base::WeakPtrFactory<BudgetDatabase> weak_ptr_factory_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(BudgetDatabase); |
| 54 }; |
| 55 |
| 56 #endif // CHROME_BROWSER_BUDGET_SERVICE_BUDGET_DATABASE_H_ |
OLD | NEW |