Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: components/leveldb_proto/leveldb_database.cc

Issue 2049573003: Implement ProtoDatabase::GetEntry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, 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 return true;
135 if (status.IsNotFound())
136 return false;
137
138 DLOG(WARNING) << "Failed loading leveldb_proto entry with key \"" << key
139 << "\": " << status.ToString();
140 return false;
141 }
142
126 } // namespace leveldb_proto 143 } // namespace leveldb_proto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698