Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: content/browser/indexed_db/leveldb/leveldb_database.cc

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Use OpenDB in unittests; add allocation edges Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <inttypes.h> 7 #include <inttypes.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cerrno> 10 #include <cerrno>
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 options.compression = leveldb::kSnappyCompression; 133 options.compression = leveldb::kSnappyCompression;
134 options.write_buffer_size = 134 options.write_buffer_size =
135 leveldb_env::WriteBufferSize(base::SysInfo::AmountOfTotalDiskSpace(path)); 135 leveldb_env::WriteBufferSize(base::SysInfo::AmountOfTotalDiskSpace(path));
136 136
137 // For info about the troubles we've run into with this parameter, see: 137 // For info about the troubles we've run into with this parameter, see:
138 // https://code.google.com/p/chromium/issues/detail?id=227313#c11 138 // https://code.google.com/p/chromium/issues/detail?id=227313#c11
139 options.max_open_files = 80; 139 options.max_open_files = 80;
140 options.env = env; 140 options.env = env;
141 141
142 // ChromiumEnv assumes UTF8, converts back to FilePath before using. 142 // ChromiumEnv assumes UTF8, converts back to FilePath before using.
143 leveldb::DB* db_ptr = nullptr; 143 return leveldb_env::OpenDB(options, path.AsUTF8Unsafe(), db);
144 leveldb::Status s = leveldb::DB::Open(options, path.AsUTF8Unsafe(), &db_ptr);
145 db->reset(db_ptr);
146
147 return s;
148 } 144 }
149 145
150 leveldb::Status LevelDBDatabase::Destroy(const base::FilePath& file_name) { 146 leveldb::Status LevelDBDatabase::Destroy(const base::FilePath& file_name) {
151 leveldb::Options options; 147 leveldb::Options options;
152 options.env = LevelDBEnv::Get(); 148 options.env = LevelDBEnv::Get();
153 // ChromiumEnv assumes UTF8, converts back to FilePath before using. 149 // ChromiumEnv assumes UTF8, converts back to FilePath before using.
154 return leveldb::DestroyDB(file_name.AsUTF8Unsafe(), options); 150 return leveldb::DestroyDB(file_name.AsUTF8Unsafe(), options);
155 } 151 }
156 152
157 namespace { 153 namespace {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 480
485 // Dumps in BACKGROUND mode cannot have strings or edges in order to minimize 481 // Dumps in BACKGROUND mode cannot have strings or edges in order to minimize
486 // trace size and instrumentation overhead. 482 // trace size and instrumentation overhead.
487 if (args.level_of_detail == 483 if (args.level_of_detail ==
488 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { 484 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
489 return true; 485 return true;
490 } 486 }
491 487
492 dump->AddString("file_name", "", file_name_for_tracing); 488 dump->AddString("file_name", "", file_name_for_tracing);
493 489
494 // Memory is allocated from system allocator (malloc). 490 // All leveldb databases are already dumped by leveldb_env::DBTracker. Add
491 // an edge to avoid double counting.
495 pmd->AddSuballocation(dump->guid(), 492 pmd->AddSuballocation(dump->guid(),
496 base::trace_event::MemoryDumpManager::GetInstance() 493 leveldb_env::DBTracker::GetMemoryDumpName(db_.get()));
497 ->system_allocator_pool_name()); 494
498 return true; 495 return true;
499 } 496 }
500 497
501 std::unique_ptr<leveldb::Iterator> LevelDBDatabase::CreateLevelDBIterator( 498 std::unique_ptr<leveldb::Iterator> LevelDBDatabase::CreateLevelDBIterator(
502 const leveldb::Snapshot* snapshot) { 499 const leveldb::Snapshot* snapshot) {
503 leveldb::ReadOptions read_options; 500 leveldb::ReadOptions read_options;
504 read_options.verify_checksums = true; 501 read_options.verify_checksums = true;
505 read_options.snapshot = snapshot; 502 read_options.snapshot = snapshot;
506 return std::unique_ptr<leveldb::Iterator>(db_->NewIterator(read_options)); 503 return std::unique_ptr<leveldb::Iterator>(db_->NewIterator(read_options));
507 } 504 }
(...skipping 14 matching lines...) Expand all
522 void LevelDBDatabase::OnIteratorDestroyed(LevelDBIterator* iter) { 519 void LevelDBDatabase::OnIteratorDestroyed(LevelDBIterator* iter) {
523 DCHECK_GT(num_iterators_, 0u); 520 DCHECK_GT(num_iterators_, 0u);
524 --num_iterators_; 521 --num_iterators_;
525 auto it = iterator_lru_.Peek(iter); 522 auto it = iterator_lru_.Peek(iter);
526 if (it == iterator_lru_.end()) 523 if (it == iterator_lru_.end())
527 return; 524 return;
528 iterator_lru_.Erase(it); 525 iterator_lru_.Erase(it);
529 } 526 }
530 527
531 } // namespace content 528 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698