| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | |
| 9 #include <cerrno> | 8 #include <cerrno> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 return s; | 301 return s; |
| 302 } | 302 } |
| 303 | 303 |
| 304 UMA_HISTOGRAM_MEDIUM_TIMES("WebCore.IndexedDB.LevelDB.OpenTime", | 304 UMA_HISTOGRAM_MEDIUM_TIMES("WebCore.IndexedDB.LevelDB.OpenTime", |
| 305 base::TimeTicks::Now() - begin_time); | 305 base::TimeTicks::Now() - begin_time); |
| 306 | 306 |
| 307 CheckFreeSpace("Success", file_name); | 307 CheckFreeSpace("Success", file_name); |
| 308 | 308 |
| 309 (*result).reset(new LevelDBDatabase); | 309 (*result).reset(new LevelDBDatabase); |
| 310 (*result)->db_ = make_scoped_ptr(db); | 310 (*result)->db_ = make_scoped_ptr(db); |
| 311 (*result)->comparator_adapter_ = comparator_adapter.Pass(); | 311 (*result)->comparator_adapter_ = std::move(comparator_adapter); |
| 312 (*result)->comparator_ = comparator; | 312 (*result)->comparator_ = comparator; |
| 313 (*result)->filter_policy_ = filter_policy.Pass(); | 313 (*result)->filter_policy_ = std::move(filter_policy); |
| 314 | 314 |
| 315 return s; | 315 return s; |
| 316 } | 316 } |
| 317 | 317 |
| 318 scoped_ptr<LevelDBDatabase> LevelDBDatabase::OpenInMemory( | 318 scoped_ptr<LevelDBDatabase> LevelDBDatabase::OpenInMemory( |
| 319 const LevelDBComparator* comparator) { | 319 const LevelDBComparator* comparator) { |
| 320 scoped_ptr<ComparatorAdapter> comparator_adapter( | 320 scoped_ptr<ComparatorAdapter> comparator_adapter( |
| 321 new ComparatorAdapter(comparator)); | 321 new ComparatorAdapter(comparator)); |
| 322 scoped_ptr<leveldb::Env> in_memory_env(leveldb::NewMemEnv(LevelDBEnv::Get())); | 322 scoped_ptr<leveldb::Env> in_memory_env(leveldb::NewMemEnv(LevelDBEnv::Get())); |
| 323 | 323 |
| 324 leveldb::DB* db; | 324 leveldb::DB* db; |
| 325 scoped_ptr<const leveldb::FilterPolicy> filter_policy; | 325 scoped_ptr<const leveldb::FilterPolicy> filter_policy; |
| 326 const leveldb::Status s = OpenDB(comparator_adapter.get(), | 326 const leveldb::Status s = OpenDB(comparator_adapter.get(), |
| 327 in_memory_env.get(), | 327 in_memory_env.get(), |
| 328 base::FilePath(), | 328 base::FilePath(), |
| 329 &db, | 329 &db, |
| 330 &filter_policy); | 330 &filter_policy); |
| 331 | 331 |
| 332 if (!s.ok()) { | 332 if (!s.ok()) { |
| 333 LOG(ERROR) << "Failed to open in-memory LevelDB database: " << s.ToString(); | 333 LOG(ERROR) << "Failed to open in-memory LevelDB database: " << s.ToString(); |
| 334 return scoped_ptr<LevelDBDatabase>(); | 334 return scoped_ptr<LevelDBDatabase>(); |
| 335 } | 335 } |
| 336 | 336 |
| 337 scoped_ptr<LevelDBDatabase> result(new LevelDBDatabase); | 337 scoped_ptr<LevelDBDatabase> result(new LevelDBDatabase); |
| 338 result->env_ = in_memory_env.Pass(); | 338 result->env_ = std::move(in_memory_env); |
| 339 result->db_ = make_scoped_ptr(db); | 339 result->db_ = make_scoped_ptr(db); |
| 340 result->comparator_adapter_ = comparator_adapter.Pass(); | 340 result->comparator_adapter_ = std::move(comparator_adapter); |
| 341 result->comparator_ = comparator; | 341 result->comparator_ = comparator; |
| 342 result->filter_policy_ = filter_policy.Pass(); | 342 result->filter_policy_ = std::move(filter_policy); |
| 343 | 343 |
| 344 return result.Pass(); | 344 return result; |
| 345 } | 345 } |
| 346 | 346 |
| 347 leveldb::Status LevelDBDatabase::Put(const StringPiece& key, | 347 leveldb::Status LevelDBDatabase::Put(const StringPiece& key, |
| 348 std::string* value) { | 348 std::string* value) { |
| 349 base::TimeTicks begin_time = base::TimeTicks::Now(); | 349 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 350 | 350 |
| 351 leveldb::WriteOptions write_options; | 351 leveldb::WriteOptions write_options; |
| 352 write_options.sync = kSyncWrites; | 352 write_options.sync = kSyncWrites; |
| 353 | 353 |
| 354 const leveldb::Status s = | 354 const leveldb::Status s = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 412 |
| 413 scoped_ptr<LevelDBIterator> LevelDBDatabase::CreateIterator( | 413 scoped_ptr<LevelDBIterator> LevelDBDatabase::CreateIterator( |
| 414 const LevelDBSnapshot* snapshot) { | 414 const LevelDBSnapshot* snapshot) { |
| 415 leveldb::ReadOptions read_options; | 415 leveldb::ReadOptions read_options; |
| 416 read_options.verify_checksums = true; // TODO(jsbell): Disable this if the | 416 read_options.verify_checksums = true; // TODO(jsbell): Disable this if the |
| 417 // performance impact is too great. | 417 // performance impact is too great. |
| 418 read_options.snapshot = snapshot ? snapshot->snapshot_ : 0; | 418 read_options.snapshot = snapshot ? snapshot->snapshot_ : 0; |
| 419 | 419 |
| 420 scoped_ptr<leveldb::Iterator> i(db_->NewIterator(read_options)); | 420 scoped_ptr<leveldb::Iterator> i(db_->NewIterator(read_options)); |
| 421 return scoped_ptr<LevelDBIterator>( | 421 return scoped_ptr<LevelDBIterator>( |
| 422 IndexedDBClassFactory::Get()->CreateIteratorImpl(i.Pass())); | 422 IndexedDBClassFactory::Get()->CreateIteratorImpl(std::move(i))); |
| 423 } | 423 } |
| 424 | 424 |
| 425 const LevelDBComparator* LevelDBDatabase::Comparator() const { | 425 const LevelDBComparator* LevelDBDatabase::Comparator() const { |
| 426 return comparator_; | 426 return comparator_; |
| 427 } | 427 } |
| 428 | 428 |
| 429 void LevelDBDatabase::Compact(const base::StringPiece& start, | 429 void LevelDBDatabase::Compact(const base::StringPiece& start, |
| 430 const base::StringPiece& stop) { | 430 const base::StringPiece& stop) { |
| 431 IDB_TRACE("LevelDBDatabase::Compact"); | 431 IDB_TRACE("LevelDBDatabase::Compact"); |
| 432 const leveldb::Slice start_slice = MakeSlice(start); | 432 const leveldb::Slice start_slice = MakeSlice(start); |
| 433 const leveldb::Slice stop_slice = MakeSlice(stop); | 433 const leveldb::Slice stop_slice = MakeSlice(stop); |
| 434 // NULL batch means just wait for earlier writes to be done | 434 // NULL batch means just wait for earlier writes to be done |
| 435 db_->Write(leveldb::WriteOptions(), NULL); | 435 db_->Write(leveldb::WriteOptions(), NULL); |
| 436 db_->CompactRange(&start_slice, &stop_slice); | 436 db_->CompactRange(&start_slice, &stop_slice); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } | 439 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } |
| 440 | 440 |
| 441 } // namespace content | 441 } // namespace content |
| OLD | NEW |