| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 namespace { | 118 namespace { |
| 119 class LockImpl : public LevelDBLock { | 119 class LockImpl : public LevelDBLock { |
| 120 public: | 120 public: |
| 121 explicit LockImpl(leveldb::Env* env, leveldb::FileLock* lock) | 121 explicit LockImpl(leveldb::Env* env, leveldb::FileLock* lock) |
| 122 : env_(env), lock_(lock) {} | 122 : env_(env), lock_(lock) {} |
| 123 virtual ~LockImpl() { env_->UnlockFile(lock_); } | 123 virtual ~LockImpl() { env_->UnlockFile(lock_); } |
| 124 private: | 124 private: |
| 125 leveldb::Env* env_; | 125 leveldb::Env* env_; |
| 126 leveldb::FileLock* lock_; | 126 leveldb::FileLock* lock_; |
| 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(LockImpl); |
| 127 }; | 129 }; |
| 128 } | 130 } |
| 129 | 131 |
| 130 scoped_ptr<LevelDBLock> LevelDBDatabase::LockForTesting( | 132 scoped_ptr<LevelDBLock> LevelDBDatabase::LockForTesting( |
| 131 const base::FilePath& file_name) { | 133 const base::FilePath& file_name) { |
| 132 leveldb::Env* env = leveldb::IDBEnv(); | 134 leveldb::Env* env = leveldb::IDBEnv(); |
| 133 base::FilePath lock_path = file_name.AppendASCII("LOCK"); | 135 base::FilePath lock_path = file_name.AppendASCII("LOCK"); |
| 134 leveldb::FileLock* lock = NULL; | 136 leveldb::FileLock* lock = NULL; |
| 135 leveldb::Status status = env->LockFile(lock_path.AsUTF8Unsafe(), &lock); | 137 leveldb::Status status = env->LockFile(lock_path.AsUTF8Unsafe(), &lock); |
| 136 if (!status.ok()) | 138 if (!status.ok()) |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 virtual leveldb::Status Prev() OVERRIDE; | 386 virtual leveldb::Status Prev() OVERRIDE; |
| 385 virtual StringPiece Key() const OVERRIDE; | 387 virtual StringPiece Key() const OVERRIDE; |
| 386 virtual StringPiece Value() const OVERRIDE; | 388 virtual StringPiece Value() const OVERRIDE; |
| 387 | 389 |
| 388 private: | 390 private: |
| 389 friend class content::LevelDBDatabase; | 391 friend class content::LevelDBDatabase; |
| 390 explicit IteratorImpl(scoped_ptr<leveldb::Iterator> iterator); | 392 explicit IteratorImpl(scoped_ptr<leveldb::Iterator> iterator); |
| 391 void CheckStatus(); | 393 void CheckStatus(); |
| 392 | 394 |
| 393 scoped_ptr<leveldb::Iterator> iterator_; | 395 scoped_ptr<leveldb::Iterator> iterator_; |
| 396 |
| 397 DISALLOW_COPY_AND_ASSIGN(IteratorImpl); |
| 394 }; | 398 }; |
| 395 } | 399 } |
| 396 | 400 |
| 397 IteratorImpl::IteratorImpl(scoped_ptr<leveldb::Iterator> it) | 401 IteratorImpl::IteratorImpl(scoped_ptr<leveldb::Iterator> it) |
| 398 : iterator_(it.Pass()) {} | 402 : iterator_(it.Pass()) {} |
| 399 | 403 |
| 400 void IteratorImpl::CheckStatus() { | 404 void IteratorImpl::CheckStatus() { |
| 401 const leveldb::Status& s = iterator_->status(); | 405 const leveldb::Status& s = iterator_->status(); |
| 402 if (!s.ok()) | 406 if (!s.ok()) |
| 403 LOG(ERROR) << "LevelDB iterator error: " << s.ToString(); | 407 LOG(ERROR) << "LevelDB iterator error: " << s.ToString(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 void LevelDBDatabase::Compact(const base::StringPiece& start, | 463 void LevelDBDatabase::Compact(const base::StringPiece& start, |
| 460 const base::StringPiece& stop) { | 464 const base::StringPiece& stop) { |
| 461 const leveldb::Slice start_slice = MakeSlice(start); | 465 const leveldb::Slice start_slice = MakeSlice(start); |
| 462 const leveldb::Slice stop_slice = MakeSlice(stop); | 466 const leveldb::Slice stop_slice = MakeSlice(stop); |
| 463 db_->CompactRange(&start_slice, &stop_slice); | 467 db_->CompactRange(&start_slice, &stop_slice); |
| 464 } | 468 } |
| 465 | 469 |
| 466 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } | 470 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } |
| 467 | 471 |
| 468 } // namespace content | 472 } // namespace content |
| OLD | NEW |