Index: components/leveldb/leveldb_service_impl.cc |
diff --git a/components/leveldb/leveldb_service_impl.cc b/components/leveldb/leveldb_service_impl.cc |
index e3fd368af1777e58c2940ed07b90d3e322ff5090..c23f91ae2b38eb60f730c118f6c3bcbbff33b9d8 100644 |
--- a/components/leveldb/leveldb_service_impl.cc |
+++ b/components/leveldb/leveldb_service_impl.cc |
@@ -22,15 +22,10 @@ namespace leveldb { |
LevelDBServiceImpl::LevelDBServiceImpl( |
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) |
- : thread_(new LevelDBMojoProxy(std::move(file_task_runner))), |
- environment_name_("LevelDBEnv") {} |
+ : env_(MojoEnv::Get(std::move(file_task_runner))) {} |
LevelDBServiceImpl::~LevelDBServiceImpl() {} |
michaeln
2017/03/27 20:24:11
should UnregisterDirectory happen in this class?
Marijn Kruisselbrink
2017/03/31 23:26:24
All the open directories should be owned by some L
|
-void LevelDBServiceImpl::SetEnvironmentName(const std::string& name) { |
- environment_name_ = name; |
-} |
- |
void LevelDBServiceImpl::Open( |
filesystem::mojom::DirectoryPtr directory, |
const std::string& dbname, |
@@ -56,20 +51,15 @@ void LevelDBServiceImpl::OpenWithOptions( |
options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
options.compression = leveldb::kSnappyCompression; |
- // Register our directory with the file thread. |
- LevelDBMojoProxy::OpaqueDir* dir = |
- thread_->RegisterDirectory(std::move(directory)); |
- |
- std::unique_ptr<MojoEnv> env_mojo( |
- new MojoEnv(environment_name_, thread_, dir)); |
- options.env = env_mojo.get(); |
+ std::string prefix = env_->RegisterDirectory(std::move(directory)); |
+ options.env = env_; |
leveldb::DB* db = nullptr; |
- leveldb::Status s = leveldb::DB::Open(options, dbname, &db); |
+ leveldb::Status s = leveldb::DB::Open(options, prefix + dbname, &db); |
if (s.ok()) { |
mojo::MakeStrongAssociatedBinding( |
- base::MakeUnique<LevelDBDatabaseImpl>(std::move(env_mojo), |
+ base::MakeUnique<LevelDBDatabaseImpl>(env_, std::move(prefix), |
base::WrapUnique(db)), |
std::move(database)); |
} |
@@ -104,13 +94,10 @@ void LevelDBServiceImpl::Destroy(filesystem::mojom::DirectoryPtr directory, |
const std::string& dbname, |
const DestroyCallback& callback) { |
leveldb::Options options; |
- // Register our directory with the file thread. |
- LevelDBMojoProxy::OpaqueDir* dir = |
- thread_->RegisterDirectory(std::move(directory)); |
- std::unique_ptr<MojoEnv> env_mojo( |
- new MojoEnv(environment_name_, thread_, dir)); |
- options.env = env_mojo.get(); |
- callback.Run(LeveldbStatusToError(leveldb::DestroyDB(dbname, options))); |
+ std::string prefix = env_->RegisterDirectory(std::move(directory)); |
michaeln
2017/03/27 20:24:10
Does this leak a directory registration? Wdyt abou
Marijn Kruisselbrink
2017/03/31 23:26:24
Yeah, definitely agree that it would be nice to no
|
+ options.env = env_; |
+ callback.Run( |
+ LeveldbStatusToError(leveldb::DestroyDB(prefix + dbname, options))); |
} |
} // namespace leveldb |