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

Side by Side Diff: components/leveldb/leveldb_service_impl.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/leveldb/leveldb_service_impl.h" 5 #include "components/leveldb/leveldb_service_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 LevelDBMojoProxy::OpaqueDir* dir = 61 LevelDBMojoProxy::OpaqueDir* dir =
62 thread_->RegisterDirectory(std::move(directory)); 62 thread_->RegisterDirectory(std::move(directory));
63 63
64 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); 64 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir));
65 options.env = env_mojo.get(); 65 options.env = env_mojo.get();
66 66
67 std::unique_ptr<leveldb::Cache> cache( 67 std::unique_ptr<leveldb::Cache> cache(
68 leveldb::NewLRUCache(open_options->block_cache_size)); 68 leveldb::NewLRUCache(open_options->block_cache_size));
69 options.block_cache = cache.get(); 69 options.block_cache = cache.get();
70 70
71 leveldb::DB* db = nullptr; 71 std::unique_ptr<leveldb::DB> db;
72 leveldb::Status s = leveldb::DB::Open(options, dbname, &db); 72 leveldb::Status s = leveldb_env::OpenDB(options, dbname, &db);
73 73
74 if (s.ok()) { 74 if (s.ok()) {
75 mojo::MakeStrongAssociatedBinding( 75 mojo::MakeStrongAssociatedBinding(base::MakeUnique<LevelDBDatabaseImpl>(
76 base::MakeUnique<LevelDBDatabaseImpl>(std::move(env_mojo), 76 std::move(env_mojo), std::move(db),
77 base::WrapUnique(db), 77 std::move(cache), memory_dump_id),
78 std::move(cache), memory_dump_id), 78 std::move(database));
79 std::move(database));
80 } 79 }
81 80
82 std::move(callback).Run(LeveldbStatusToError(s)); 81 std::move(callback).Run(LeveldbStatusToError(s));
83 } 82 }
84 83
85 void LevelDBServiceImpl::OpenInMemory( 84 void LevelDBServiceImpl::OpenInMemory(
86 const base::Optional<base::trace_event::MemoryAllocatorDumpGuid>& 85 const base::Optional<base::trace_event::MemoryAllocatorDumpGuid>&
87 memory_dump_id, 86 memory_dump_id,
88 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, 87 leveldb::mojom::LevelDBDatabaseAssociatedRequest database,
89 OpenCallback callback) { 88 OpenCallback callback) {
90 leveldb::Options options; 89 leveldb::Options options;
91 options.create_if_missing = true; 90 options.create_if_missing = true;
92 options.max_open_files = 0; // Use minimum. 91 options.max_open_files = 0; // Use minimum.
93 92
94 std::unique_ptr<leveldb::Env> env( 93 std::unique_ptr<leveldb::Env> env(
95 leveldb::NewMemEnv(leveldb::Env::Default())); 94 leveldb::NewMemEnv(leveldb::Env::Default()));
96 options.env = env.get(); 95 options.env = env.get();
97 96
98 leveldb::DB* db = nullptr; 97 std::unique_ptr<leveldb::DB> db;
99 leveldb::Status s = leveldb::DB::Open(options, "", &db); 98 leveldb::Status s = leveldb_env::OpenDB(options, "", &db);
100 99
101 if (s.ok()) { 100 if (s.ok()) {
102 mojo::MakeStrongAssociatedBinding( 101 mojo::MakeStrongAssociatedBinding(
103 base::MakeUnique<LevelDBDatabaseImpl>( 102 base::MakeUnique<LevelDBDatabaseImpl>(std::move(env), std::move(db),
104 std::move(env), base::WrapUnique(db), nullptr, memory_dump_id), 103 nullptr, memory_dump_id),
105 std::move(database)); 104 std::move(database));
106 } 105 }
107 106
108 std::move(callback).Run(LeveldbStatusToError(s)); 107 std::move(callback).Run(LeveldbStatusToError(s));
109 } 108 }
110 109
111 void LevelDBServiceImpl::Destroy(filesystem::mojom::DirectoryPtr directory, 110 void LevelDBServiceImpl::Destroy(filesystem::mojom::DirectoryPtr directory,
112 const std::string& dbname, 111 const std::string& dbname,
113 DestroyCallback callback) { 112 DestroyCallback callback) {
114 leveldb::Options options; 113 leveldb::Options options;
115 // Register our directory with the file thread. 114 // Register our directory with the file thread.
116 LevelDBMojoProxy::OpaqueDir* dir = 115 LevelDBMojoProxy::OpaqueDir* dir =
117 thread_->RegisterDirectory(std::move(directory)); 116 thread_->RegisterDirectory(std::move(directory));
118 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); 117 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir));
119 options.env = env_mojo.get(); 118 options.env = env_mojo.get();
120 std::move(callback).Run( 119 std::move(callback).Run(
121 LeveldbStatusToError(leveldb::DestroyDB(dbname, options))); 120 LeveldbStatusToError(leveldb::DestroyDB(dbname, options)));
122 } 121 }
123 122
124 } // namespace leveldb 123 } // namespace leveldb
OLDNEW
« no previous file with comments | « components/leveldb/leveldb_database_impl.cc ('k') | components/leveldb_proto/leveldb_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698