| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 19 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 19 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
| 20 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 20 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" | 21 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" |
| 21 #include "content/browser/indexed_db/leveldb/leveldb_env.h" | 22 #include "content/browser/indexed_db/leveldb/leveldb_env.h" |
| 22 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" | 23 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" |
| 23 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" | 24 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" |
| 24 #include "third_party/leveldatabase/env_chromium.h" | 25 #include "third_party/leveldatabase/env_chromium.h" |
| 25 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" | 26 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
| 26 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 27 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 27 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 28 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
| 28 #include "third_party/leveldatabase/src/include/leveldb/filter_policy.h" | 29 #include "third_party/leveldatabase/src/include/leveldb/filter_policy.h" |
| 29 #include "third_party/leveldatabase/src/include/leveldb/slice.h" | 30 #include "third_party/leveldatabase/src/include/leveldb/slice.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 if (s.IsIOError()) | 267 if (s.IsIOError()) |
| 267 ParseAndHistogramIOErrorDetails(histogram_name, s); | 268 ParseAndHistogramIOErrorDetails(histogram_name, s); |
| 268 else | 269 else |
| 269 ParseAndHistogramCorruptionDetails(histogram_name, s); | 270 ParseAndHistogramCorruptionDetails(histogram_name, s); |
| 270 } | 271 } |
| 271 | 272 |
| 272 leveldb::Status LevelDBDatabase::Open(const base::FilePath& file_name, | 273 leveldb::Status LevelDBDatabase::Open(const base::FilePath& file_name, |
| 273 const LevelDBComparator* comparator, | 274 const LevelDBComparator* comparator, |
| 274 scoped_ptr<LevelDBDatabase>* result, | 275 scoped_ptr<LevelDBDatabase>* result, |
| 275 bool* is_disk_full) { | 276 bool* is_disk_full) { |
| 277 IDB_TRACE("LevelDBDatabase::Open"); |
| 276 base::TimeTicks begin_time = base::TimeTicks::Now(); | 278 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 277 | 279 |
| 278 scoped_ptr<ComparatorAdapter> comparator_adapter( | 280 scoped_ptr<ComparatorAdapter> comparator_adapter( |
| 279 new ComparatorAdapter(comparator)); | 281 new ComparatorAdapter(comparator)); |
| 280 | 282 |
| 281 leveldb::DB* db; | 283 leveldb::DB* db; |
| 282 scoped_ptr<const leveldb::FilterPolicy> filter_policy; | 284 scoped_ptr<const leveldb::FilterPolicy> filter_policy; |
| 283 const leveldb::Status s = OpenDB(comparator_adapter.get(), LevelDBEnv::Get(), | 285 const leveldb::Status s = OpenDB(comparator_adapter.get(), LevelDBEnv::Get(), |
| 284 file_name, &db, &filter_policy); | 286 file_name, &db, &filter_policy); |
| 285 | 287 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 return scoped_ptr<LevelDBIterator>( | 418 return scoped_ptr<LevelDBIterator>( |
| 417 IndexedDBClassFactory::Get()->CreateIteratorImpl(i.Pass())); | 419 IndexedDBClassFactory::Get()->CreateIteratorImpl(i.Pass())); |
| 418 } | 420 } |
| 419 | 421 |
| 420 const LevelDBComparator* LevelDBDatabase::Comparator() const { | 422 const LevelDBComparator* LevelDBDatabase::Comparator() const { |
| 421 return comparator_; | 423 return comparator_; |
| 422 } | 424 } |
| 423 | 425 |
| 424 void LevelDBDatabase::Compact(const base::StringPiece& start, | 426 void LevelDBDatabase::Compact(const base::StringPiece& start, |
| 425 const base::StringPiece& stop) { | 427 const base::StringPiece& stop) { |
| 428 IDB_TRACE("LevelDBDatabase::Compact"); |
| 426 const leveldb::Slice start_slice = MakeSlice(start); | 429 const leveldb::Slice start_slice = MakeSlice(start); |
| 427 const leveldb::Slice stop_slice = MakeSlice(stop); | 430 const leveldb::Slice stop_slice = MakeSlice(stop); |
| 428 // NULL batch means just wait for earlier writes to be done | 431 // NULL batch means just wait for earlier writes to be done |
| 429 db_->Write(leveldb::WriteOptions(), NULL); | 432 db_->Write(leveldb::WriteOptions(), NULL); |
| 430 db_->CompactRange(&start_slice, &stop_slice); | 433 db_->CompactRange(&start_slice, &stop_slice); |
| 431 } | 434 } |
| 432 | 435 |
| 433 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } | 436 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } |
| 434 | 437 |
| 435 } // namespace content | 438 } // namespace content |
| OLD | NEW |