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

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: Rebase; add comments to CHECK() 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 // A shared block cache for all IndexedDB instances across all renderers. 149 // A shared block cache for all IndexedDB instances across all renderers.
150 // See also components/leveldb_proto/leveldb_database.cc, which has 150 // See also components/leveldb_proto/leveldb_database.cc, which has
151 // its own block cache for a different (internal use-cases) set of LevelDB 151 // its own block cache for a different (internal use-cases) set of LevelDB
152 // instances. 152 // instances.
153 static leveldb::Cache* default_block_cache = 153 static leveldb::Cache* default_block_cache =
154 leveldb::NewLRUCache(DefaultBlockCacheSize()); 154 leveldb::NewLRUCache(DefaultBlockCacheSize());
155 options.block_cache = default_block_cache; 155 options.block_cache = default_block_cache;
156 156
157 // ChromiumEnv assumes UTF8, converts back to FilePath before using. 157 // ChromiumEnv assumes UTF8, converts back to FilePath before using.
158 leveldb::DB* db_ptr = nullptr; 158 return leveldb_env::OpenDB(options, path.AsUTF8Unsafe(), db);
159 leveldb::Status s = leveldb::DB::Open(options, path.AsUTF8Unsafe(), &db_ptr);
160 db->reset(db_ptr);
161
162 return s;
163 } 159 }
164 160
165 leveldb::Status LevelDBDatabase::Destroy(const base::FilePath& file_name) { 161 leveldb::Status LevelDBDatabase::Destroy(const base::FilePath& file_name) {
166 leveldb::Options options; 162 leveldb::Options options;
167 options.env = LevelDBEnv::Get(); 163 options.env = LevelDBEnv::Get();
168 // ChromiumEnv assumes UTF8, converts back to FilePath before using. 164 // ChromiumEnv assumes UTF8, converts back to FilePath before using.
169 return leveldb::DestroyDB(file_name.AsUTF8Unsafe(), options); 165 return leveldb::DestroyDB(file_name.AsUTF8Unsafe(), options);
170 } 166 }
171 167
172 namespace { 168 namespace {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 495
500 // Dumps in BACKGROUND mode cannot have strings or edges in order to minimize 496 // Dumps in BACKGROUND mode cannot have strings or edges in order to minimize
501 // trace size and instrumentation overhead. 497 // trace size and instrumentation overhead.
502 if (args.level_of_detail == 498 if (args.level_of_detail ==
503 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { 499 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
504 return true; 500 return true;
505 } 501 }
506 502
507 dump->AddString("file_name", "", file_name_for_tracing); 503 dump->AddString("file_name", "", file_name_for_tracing);
508 504
509 // Memory is allocated from system allocator (malloc). 505 // All leveldb databases are already dumped by leveldb_env::DBTracker. Add
506 // an edge to avoid double counting.
510 pmd->AddSuballocation(dump->guid(), 507 pmd->AddSuballocation(dump->guid(),
511 base::trace_event::MemoryDumpManager::GetInstance() 508 leveldb_env::DBTracker::GetMemoryDumpName(db_.get()));
512 ->system_allocator_pool_name()); 509
513 return true; 510 return true;
514 } 511 }
515 512
516 std::unique_ptr<leveldb::Iterator> LevelDBDatabase::CreateLevelDBIterator( 513 std::unique_ptr<leveldb::Iterator> LevelDBDatabase::CreateLevelDBIterator(
517 const leveldb::Snapshot* snapshot) { 514 const leveldb::Snapshot* snapshot) {
518 leveldb::ReadOptions read_options; 515 leveldb::ReadOptions read_options;
519 read_options.verify_checksums = true; 516 read_options.verify_checksums = true;
520 read_options.snapshot = snapshot; 517 read_options.snapshot = snapshot;
521 return std::unique_ptr<leveldb::Iterator>(db_->NewIterator(read_options)); 518 return std::unique_ptr<leveldb::Iterator>(db_->NewIterator(read_options));
522 } 519 }
(...skipping 14 matching lines...) Expand all
537 void LevelDBDatabase::OnIteratorDestroyed(LevelDBIterator* iter) { 534 void LevelDBDatabase::OnIteratorDestroyed(LevelDBIterator* iter) {
538 DCHECK_GT(num_iterators_, 0u); 535 DCHECK_GT(num_iterators_, 0u);
539 --num_iterators_; 536 --num_iterators_;
540 auto it = iterator_lru_.Peek(iter); 537 auto it = iterator_lru_.Peek(iter);
541 if (it == iterator_lru_.end()) 538 if (it == iterator_lru_.end())
542 return; 539 return;
543 iterator_lru_.Erase(it); 540 iterator_lru_.Erase(it);
544 } 541 }
545 542
546 } // namespace content 543 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/session_storage_database.cc ('k') | content/browser/notifications/notification_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698