Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / indexed_db / leveldb / leveldb_iterator_impl.cc
blob46c99f4b60b3977cf5e39dbcbff933db86cf8269
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());
17 namespace content {
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();
28 if (!s.ok())
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();
38 CheckStatus();
39 return iterator_->status();
42 leveldb::Status LevelDBIteratorImpl::Seek(const base::StringPiece& target) {
43 iterator_->Seek(MakeSlice(target));
44 CheckStatus();
45 return iterator_->status();
48 leveldb::Status LevelDBIteratorImpl::Next() {
49 DCHECK(IsValid());
50 iterator_->Next();
51 CheckStatus();
52 return iterator_->status();
55 leveldb::Status LevelDBIteratorImpl::Prev() {
56 DCHECK(IsValid());
57 iterator_->Prev();
58 CheckStatus();
59 return iterator_->status();
62 base::StringPiece LevelDBIteratorImpl::Key() const {
63 DCHECK(IsValid());
64 return MakeStringPiece(iterator_->key());
67 base::StringPiece LevelDBIteratorImpl::Value() const {
68 DCHECK(IsValid());
69 return MakeStringPiece(iterator_->value());
72 } // namespace content