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
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h"
9 static leveldb::Slice
MakeSlice(const base::StringPiece
& s
) {
10 return leveldb::Slice(s
.begin(), s
.size());
13 static base::StringPiece
MakeStringPiece(const leveldb::Slice
& s
) {
14 return base::StringPiece(s
.data(), s
.size());
19 LevelDBIteratorImpl::~LevelDBIteratorImpl() {
22 LevelDBIteratorImpl::LevelDBIteratorImpl(scoped_ptr
<leveldb::Iterator
> it
)
23 : iterator_(it
.Pass()) {
26 void LevelDBIteratorImpl::CheckStatus() {
27 const leveldb::Status
& s
= iterator_
->status();
29 LOG(ERROR
) << "LevelDB iterator error: " << s
.ToString();
32 bool LevelDBIteratorImpl::IsValid() const {
33 return iterator_
->Valid();
36 leveldb::Status
LevelDBIteratorImpl::SeekToLast() {
37 iterator_
->SeekToLast();
39 return iterator_
->status();
42 leveldb::Status
LevelDBIteratorImpl::Seek(const base::StringPiece
& target
) {
43 iterator_
->Seek(MakeSlice(target
));
45 return iterator_
->status();
48 leveldb::Status
LevelDBIteratorImpl::Next() {
52 return iterator_
->status();
55 leveldb::Status
LevelDBIteratorImpl::Prev() {
59 return iterator_
->status();
62 base::StringPiece
LevelDBIteratorImpl::Key() const {
64 return MakeStringPiece(iterator_
->key());
67 base::StringPiece
LevelDBIteratorImpl::Value() const {
69 return MakeStringPiece(iterator_
->value());
72 } // namespace content