| 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::Get(const std::string& key, bool* found, std::string* entry) { |
| 127 DFAKE_SCOPED_LOCK(thread_checker_); |
| 128 if (!db_) |
| 129 return false; |
| 130 |
| 131 leveldb::ReadOptions options; |
| 132 leveldb::Status status = db_->Get(options, key, entry); |
| 133 if (status.ok()) { |
| 134 *found = true; |
| 135 return true; |
| 136 } |
| 137 if (status.IsNotFound()) { |
| 138 *found = false; |
| 139 return true; |
| 140 } |
| 141 |
| 142 DLOG(WARNING) << "Failed loading leveldb_proto entry with key \"" << key |
| 143 << "\": " << status.ToString(); |
| 144 return false; |
| 145 } |
| 146 |
| 126 } // namespace leveldb_proto | 147 } // namespace leveldb_proto |
| OLD | NEW |