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_TESTING_FAKE_DB_H_ | 5 #ifndef COMPONENTS_LEVELDB_PROTO_TESTING_FAKE_DB_H_ |
6 #define COMPONENTS_LEVELDB_PROTO_TESTING_FAKE_DB_H_ | 6 #define COMPONENTS_LEVELDB_PROTO_TESTING_FAKE_DB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "components/leveldb_proto/proto_database.h" | 15 #include "components/leveldb_proto/proto_database.h" |
16 | 16 |
17 namespace leveldb_proto { | 17 namespace leveldb_proto { |
18 namespace test { | 18 namespace test { |
19 | 19 |
20 template <typename T> | 20 template <typename T> |
21 class FakeDB : public ProtoDatabase<T> { | 21 class FakeDB : public ProtoDatabase<T> { |
22 typedef base::Callback<void(bool)> Callback; | 22 typedef base::Callback<void(bool)> Callback; |
23 | 23 |
24 public: | 24 public: |
25 typedef typename base::hash_map<std::string, T> EntryMap; | 25 typedef typename base::hash_map<std::string, T> EntryMap; |
26 | 26 |
27 explicit FakeDB(EntryMap* db); | 27 explicit FakeDB(EntryMap* db); |
28 virtual ~FakeDB(); | 28 ~FakeDB() override; |
29 | 29 |
30 virtual void Init(const base::FilePath& database_dir, | 30 void Init(const base::FilePath& database_dir, |
31 typename ProtoDatabase<T>::InitCallback callback) | 31 typename ProtoDatabase<T>::InitCallback callback) override; |
32 override; | |
33 | 32 |
34 virtual void UpdateEntries( | 33 void UpdateEntries( |
35 scoped_ptr<typename ProtoDatabase<T>::KeyEntryVector> entries_to_save, | 34 scoped_ptr<typename ProtoDatabase<T>::KeyEntryVector> entries_to_save, |
36 scoped_ptr<std::vector<std::string> > keys_to_remove, | 35 scoped_ptr<std::vector<std::string> > keys_to_remove, |
37 typename ProtoDatabase<T>::UpdateCallback callback) override; | 36 typename ProtoDatabase<T>::UpdateCallback callback) override; |
38 | 37 |
39 virtual void LoadEntries(typename ProtoDatabase<T>::LoadCallback callback) | 38 void LoadEntries(typename ProtoDatabase<T>::LoadCallback callback) override; |
40 override; | |
41 base::FilePath& GetDirectory(); | 39 base::FilePath& GetDirectory(); |
42 | 40 |
43 void InitCallback(bool success); | 41 void InitCallback(bool success); |
44 | 42 |
45 void LoadCallback(bool success); | 43 void LoadCallback(bool success); |
46 | 44 |
47 void UpdateCallback(bool success); | 45 void UpdateCallback(bool success); |
48 | 46 |
49 static base::FilePath DirectoryForTestDB(); | 47 static base::FilePath DirectoryForTestDB(); |
50 | 48 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // static | 135 // static |
138 template <typename T> | 136 template <typename T> |
139 base::FilePath FakeDB<T>::DirectoryForTestDB() { | 137 base::FilePath FakeDB<T>::DirectoryForTestDB() { |
140 return base::FilePath(FILE_PATH_LITERAL("/fake/path")); | 138 return base::FilePath(FILE_PATH_LITERAL("/fake/path")); |
141 } | 139 } |
142 | 140 |
143 } // namespace test | 141 } // namespace test |
144 } // namespace leveldb_proto | 142 } // namespace leveldb_proto |
145 | 143 |
146 #endif // COMPONENTS_LEVELDB_PROTO_TESTING_FAKE_DB_H_ | 144 #endif // COMPONENTS_LEVELDB_PROTO_TESTING_FAKE_DB_H_ |
OLD | NEW |