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 #include "components/leveldb_proto/leveldb_database.h" | 5 #include "components/leveldb_proto/leveldb_database.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 leveldb::ReadOptions options; | 116 leveldb::ReadOptions options; |
117 std::unique_ptr<leveldb::Iterator> db_iterator(db_->NewIterator(options)); | 117 std::unique_ptr<leveldb::Iterator> db_iterator(db_->NewIterator(options)); |
118 for (db_iterator->SeekToFirst(); db_iterator->Valid(); db_iterator->Next()) { | 118 for (db_iterator->SeekToFirst(); db_iterator->Valid(); db_iterator->Next()) { |
119 leveldb::Slice value_slice = db_iterator->value(); | 119 leveldb::Slice value_slice = db_iterator->value(); |
120 std::string entry(value_slice.data(), value_slice.size()); | 120 std::string entry(value_slice.data(), value_slice.size()); |
121 entries->push_back(entry); | 121 entries->push_back(entry); |
122 } | 122 } |
123 return true; | 123 return true; |
124 } | 124 } |
125 | 125 |
| 126 bool LevelDB::LoadKeys(std::vector<std::string>* keys) { |
| 127 DFAKE_SCOPED_LOCK(thread_checker_); |
| 128 if (!db_) |
| 129 return false; |
| 130 |
| 131 leveldb::ReadOptions options; |
| 132 options.fill_cache = false; |
| 133 std::unique_ptr<leveldb::Iterator> db_iterator(db_->NewIterator(options)); |
| 134 for (db_iterator->SeekToFirst(); db_iterator->Valid(); db_iterator->Next()) { |
| 135 leveldb::Slice key_slice = db_iterator->key(); |
| 136 keys->push_back(std::string(key_slice.data(), key_slice.size())); |
| 137 } |
| 138 return true; |
| 139 } |
| 140 |
126 bool LevelDB::Get(const std::string& key, bool* found, std::string* entry) { | 141 bool LevelDB::Get(const std::string& key, bool* found, std::string* entry) { |
127 DFAKE_SCOPED_LOCK(thread_checker_); | 142 DFAKE_SCOPED_LOCK(thread_checker_); |
128 if (!db_) | 143 if (!db_) |
129 return false; | 144 return false; |
130 | 145 |
131 leveldb::ReadOptions options; | 146 leveldb::ReadOptions options; |
132 leveldb::Status status = db_->Get(options, key, entry); | 147 leveldb::Status status = db_->Get(options, key, entry); |
133 if (status.ok()) { | 148 if (status.ok()) { |
134 *found = true; | 149 *found = true; |
135 return true; | 150 return true; |
136 } | 151 } |
137 if (status.IsNotFound()) { | 152 if (status.IsNotFound()) { |
138 *found = false; | 153 *found = false; |
139 return true; | 154 return true; |
140 } | 155 } |
141 | 156 |
142 DLOG(WARNING) << "Failed loading leveldb_proto entry with key \"" << key | 157 DLOG(WARNING) << "Failed loading leveldb_proto entry with key \"" << key |
143 << "\": " << status.ToString(); | 158 << "\": " << status.ToString(); |
144 return false; | 159 return false; |
145 } | 160 } |
146 | 161 |
147 } // namespace leveldb_proto | 162 } // namespace leveldb_proto |
OLD | NEW |