| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/indexed_db/leveldb/leveldb_database.h" | 5 #include "content/browser/indexed_db/leveldb/leveldb_database.h" |
| 6 | 6 |
| 7 #include <cerrno> | 7 #include <cerrno> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 371 } |
| 372 return s; | 372 return s; |
| 373 } | 373 } |
| 374 | 374 |
| 375 namespace { | 375 namespace { |
| 376 class IteratorImpl : public LevelDBIterator { | 376 class IteratorImpl : public LevelDBIterator { |
| 377 public: | 377 public: |
| 378 virtual ~IteratorImpl() {} | 378 virtual ~IteratorImpl() {} |
| 379 | 379 |
| 380 virtual bool IsValid() const OVERRIDE; | 380 virtual bool IsValid() const OVERRIDE; |
| 381 virtual void SeekToLast() OVERRIDE; | 381 virtual leveldb::Status SeekToLast() OVERRIDE; |
| 382 virtual void Seek(const StringPiece& target) OVERRIDE; | 382 virtual leveldb::Status Seek(const StringPiece& target) OVERRIDE; |
| 383 virtual void Next() OVERRIDE; | 383 virtual leveldb::Status Next() OVERRIDE; |
| 384 virtual void Prev() OVERRIDE; | 384 virtual leveldb::Status Prev() OVERRIDE; |
| 385 virtual StringPiece Key() const OVERRIDE; | 385 virtual StringPiece Key() const OVERRIDE; |
| 386 virtual StringPiece Value() const OVERRIDE; | 386 virtual StringPiece Value() const OVERRIDE; |
| 387 | 387 |
| 388 private: | 388 private: |
| 389 friend class content::LevelDBDatabase; | 389 friend class content::LevelDBDatabase; |
| 390 explicit IteratorImpl(scoped_ptr<leveldb::Iterator> iterator); | 390 explicit IteratorImpl(scoped_ptr<leveldb::Iterator> iterator); |
| 391 void CheckStatus(); | 391 void CheckStatus(); |
| 392 | 392 |
| 393 scoped_ptr<leveldb::Iterator> iterator_; | 393 scoped_ptr<leveldb::Iterator> iterator_; |
| 394 }; | 394 }; |
| 395 } | 395 } |
| 396 | 396 |
| 397 IteratorImpl::IteratorImpl(scoped_ptr<leveldb::Iterator> it) | 397 IteratorImpl::IteratorImpl(scoped_ptr<leveldb::Iterator> it) |
| 398 : iterator_(it.Pass()) {} | 398 : iterator_(it.Pass()) {} |
| 399 | 399 |
| 400 void IteratorImpl::CheckStatus() { | 400 void IteratorImpl::CheckStatus() { |
| 401 const leveldb::Status s = iterator_->status(); | 401 const leveldb::Status& s = iterator_->status(); |
| 402 if (!s.ok()) | 402 if (!s.ok()) |
| 403 LOG(ERROR) << "LevelDB iterator error: " << s.ToString(); | 403 LOG(ERROR) << "LevelDB iterator error: " << s.ToString(); |
| 404 } | 404 } |
| 405 | 405 |
| 406 bool IteratorImpl::IsValid() const { return iterator_->Valid(); } | 406 bool IteratorImpl::IsValid() const { return iterator_->Valid(); } |
| 407 | 407 |
| 408 void IteratorImpl::SeekToLast() { | 408 leveldb::Status IteratorImpl::SeekToLast() { |
| 409 iterator_->SeekToLast(); | 409 iterator_->SeekToLast(); |
| 410 CheckStatus(); | 410 CheckStatus(); |
| 411 return iterator_->status(); |
| 411 } | 412 } |
| 412 | 413 |
| 413 void IteratorImpl::Seek(const StringPiece& target) { | 414 leveldb::Status IteratorImpl::Seek(const StringPiece& target) { |
| 414 iterator_->Seek(MakeSlice(target)); | 415 iterator_->Seek(MakeSlice(target)); |
| 415 CheckStatus(); | 416 CheckStatus(); |
| 417 return iterator_->status(); |
| 416 } | 418 } |
| 417 | 419 |
| 418 void IteratorImpl::Next() { | 420 leveldb::Status IteratorImpl::Next() { |
| 419 DCHECK(IsValid()); | 421 DCHECK(IsValid()); |
| 420 iterator_->Next(); | 422 iterator_->Next(); |
| 421 CheckStatus(); | 423 CheckStatus(); |
| 424 return iterator_->status(); |
| 422 } | 425 } |
| 423 | 426 |
| 424 void IteratorImpl::Prev() { | 427 leveldb::Status IteratorImpl::Prev() { |
| 425 DCHECK(IsValid()); | 428 DCHECK(IsValid()); |
| 426 iterator_->Prev(); | 429 iterator_->Prev(); |
| 427 CheckStatus(); | 430 CheckStatus(); |
| 431 return iterator_->status(); |
| 428 } | 432 } |
| 429 | 433 |
| 430 StringPiece IteratorImpl::Key() const { | 434 StringPiece IteratorImpl::Key() const { |
| 431 DCHECK(IsValid()); | 435 DCHECK(IsValid()); |
| 432 return MakeStringPiece(iterator_->key()); | 436 return MakeStringPiece(iterator_->key()); |
| 433 } | 437 } |
| 434 | 438 |
| 435 StringPiece IteratorImpl::Value() const { | 439 StringPiece IteratorImpl::Value() const { |
| 436 DCHECK(IsValid()); | 440 DCHECK(IsValid()); |
| 437 return MakeStringPiece(iterator_->value()); | 441 return MakeStringPiece(iterator_->value()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 455 void LevelDBDatabase::Compact(const base::StringPiece& start, | 459 void LevelDBDatabase::Compact(const base::StringPiece& start, |
| 456 const base::StringPiece& stop) { | 460 const base::StringPiece& stop) { |
| 457 const leveldb::Slice start_slice = MakeSlice(start); | 461 const leveldb::Slice start_slice = MakeSlice(start); |
| 458 const leveldb::Slice stop_slice = MakeSlice(stop); | 462 const leveldb::Slice stop_slice = MakeSlice(stop); |
| 459 db_->CompactRange(&start_slice, &stop_slice); | 463 db_->CompactRange(&start_slice, &stop_slice); |
| 460 } | 464 } |
| 461 | 465 |
| 462 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } | 466 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } |
| 463 | 467 |
| 464 } // namespace content | 468 } // namespace content |
| OLD | NEW |