OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_IMPL_H_ | 5 #ifndef COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_IMPL_H_ |
6 #define COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_IMPL_H_ | 6 #define COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 // When the ProtoDatabaseImpl instance is deleted, in-progress asynchronous | 28 // When the ProtoDatabaseImpl instance is deleted, in-progress asynchronous |
29 // operations will be completed and the corresponding callbacks will be called. | 29 // operations will be completed and the corresponding callbacks will be called. |
30 // Construction/calls/destruction should all happen on the same thread. | 30 // Construction/calls/destruction should all happen on the same thread. |
31 template <typename T> | 31 template <typename T> |
32 class ProtoDatabaseImpl : public ProtoDatabase<T> { | 32 class ProtoDatabaseImpl : public ProtoDatabase<T> { |
33 public: | 33 public: |
34 // All blocking calls/disk access will happen on the provided |task_runner|. | 34 // All blocking calls/disk access will happen on the provided |task_runner|. |
35 explicit ProtoDatabaseImpl( | 35 explicit ProtoDatabaseImpl( |
36 scoped_refptr<base::SequencedTaskRunner> task_runner); | 36 scoped_refptr<base::SequencedTaskRunner> task_runner); |
37 | 37 |
38 virtual ~ProtoDatabaseImpl(); | 38 ~ProtoDatabaseImpl() override; |
39 | 39 |
40 // ProtoDatabase implementation. | 40 // ProtoDatabase implementation. |
41 // TODO(cjhopman): Perhaps Init() shouldn't be exposed to users and not just | 41 // TODO(cjhopman): Perhaps Init() shouldn't be exposed to users and not just |
42 // part of the constructor | 42 // part of the constructor |
43 virtual void Init(const base::FilePath& database_dir, | 43 void Init(const base::FilePath& database_dir, |
44 typename ProtoDatabase<T>::InitCallback callback) override; | 44 typename ProtoDatabase<T>::InitCallback callback) override; |
45 virtual void UpdateEntries( | 45 void UpdateEntries( |
46 scoped_ptr<typename ProtoDatabase<T>::KeyEntryVector> entries_to_save, | 46 scoped_ptr<typename ProtoDatabase<T>::KeyEntryVector> entries_to_save, |
47 scoped_ptr<KeyVector> keys_to_remove, | 47 scoped_ptr<KeyVector> keys_to_remove, |
48 typename ProtoDatabase<T>::UpdateCallback callback) override; | 48 typename ProtoDatabase<T>::UpdateCallback callback) override; |
49 virtual void LoadEntries( | 49 void LoadEntries(typename ProtoDatabase<T>::LoadCallback callback) override; |
50 typename ProtoDatabase<T>::LoadCallback callback) override; | |
51 | 50 |
52 // Allow callers to provide their own Database implementation. | 51 // Allow callers to provide their own Database implementation. |
53 void InitWithDatabase(scoped_ptr<LevelDB> database, | 52 void InitWithDatabase(scoped_ptr<LevelDB> database, |
54 const base::FilePath& database_dir, | 53 const base::FilePath& database_dir, |
55 typename ProtoDatabase<T>::InitCallback callback); | 54 typename ProtoDatabase<T>::InitCallback callback); |
56 | 55 |
57 private: | 56 private: |
58 base::ThreadChecker thread_checker_; | 57 base::ThreadChecker thread_checker_; |
59 | 58 |
60 // Used to run blocking tasks in-order. | 59 // Used to run blocking tasks in-order. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 task_runner_->PostTaskAndReply( | 195 task_runner_->PostTaskAndReply( |
197 FROM_HERE, base::Bind(LoadEntriesFromTaskRunner<T>, | 196 FROM_HERE, base::Bind(LoadEntriesFromTaskRunner<T>, |
198 base::Unretained(db_.get()), entries_ptr, success), | 197 base::Unretained(db_.get()), entries_ptr, success), |
199 base::Bind(RunLoadCallback<T>, callback, base::Owned(success), | 198 base::Bind(RunLoadCallback<T>, callback, base::Owned(success), |
200 base::Passed(&entries))); | 199 base::Passed(&entries))); |
201 } | 200 } |
202 | 201 |
203 } // namespace leveldb_proto | 202 } // namespace leveldb_proto |
204 | 203 |
205 #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_IMPL_H_ | 204 #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_IMPL_H_ |
OLD | NEW |