| OLD | NEW |
| 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 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/leveldb/env_mojo.h" | 10 #include "components/leveldb/env_mojo.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 options.compression = leveldb::kSnappyCompression; | 52 options.compression = leveldb::kSnappyCompression; |
| 53 | 53 |
| 54 // Register our directory with the file thread. | 54 // Register our directory with the file thread. |
| 55 LevelDBMojoProxy::OpaqueDir* dir = | 55 LevelDBMojoProxy::OpaqueDir* dir = |
| 56 thread_->RegisterDirectory(std::move(directory)); | 56 thread_->RegisterDirectory(std::move(directory)); |
| 57 | 57 |
| 58 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); | 58 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); |
| 59 options.env = env_mojo.get(); | 59 options.env = env_mojo.get(); |
| 60 | 60 |
| 61 leveldb::DB* db = nullptr; | 61 leveldb::DB* db = nullptr; |
| 62 leveldb::Status s = leveldb::DB::Open(options, dbname, &db); | 62 leveldb::Status s = leveldb_env::DBRegistry::Open(options, dbname, &db); |
| 63 | 63 |
| 64 if (s.ok()) { | 64 if (s.ok()) { |
| 65 mojo::MakeStrongAssociatedBinding( | 65 mojo::MakeStrongAssociatedBinding( |
| 66 base::MakeUnique<LevelDBDatabaseImpl>(std::move(env_mojo), | 66 base::MakeUnique<LevelDBDatabaseImpl>(std::move(env_mojo), |
| 67 base::WrapUnique(db)), | 67 base::WrapUnique(db)), |
| 68 std::move(database)); | 68 std::move(database)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 callback.Run(LeveldbStatusToError(s)); | 71 callback.Run(LeveldbStatusToError(s)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void LevelDBServiceImpl::OpenInMemory( | 74 void LevelDBServiceImpl::OpenInMemory( |
| 75 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, | 75 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, |
| 76 const OpenCallback& callback) { | 76 const OpenCallback& callback) { |
| 77 leveldb::Options options; | 77 leveldb::Options options; |
| 78 options.create_if_missing = true; | 78 options.create_if_missing = true; |
| 79 options.max_open_files = 0; // Use minimum. | 79 options.max_open_files = 0; // Use minimum. |
| 80 | 80 |
| 81 std::unique_ptr<leveldb::Env> env( | 81 std::unique_ptr<leveldb::Env> env( |
| 82 leveldb::NewMemEnv(leveldb::Env::Default())); | 82 leveldb::NewMemEnv(leveldb::Env::Default())); |
| 83 options.env = env.get(); | 83 options.env = env.get(); |
| 84 | 84 |
| 85 leveldb::DB* db = nullptr; | 85 leveldb::DB* db = nullptr; |
| 86 leveldb::Status s = leveldb::DB::Open(options, "", &db); | 86 leveldb::Status s = leveldb_env::DBRegistry::Open(options, "", &db); |
| 87 | 87 |
| 88 if (s.ok()) { | 88 if (s.ok()) { |
| 89 mojo::MakeStrongAssociatedBinding(base::MakeUnique<LevelDBDatabaseImpl>( | 89 mojo::MakeStrongAssociatedBinding(base::MakeUnique<LevelDBDatabaseImpl>( |
| 90 std::move(env), base::WrapUnique(db)), | 90 std::move(env), base::WrapUnique(db)), |
| 91 std::move(database)); | 91 std::move(database)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 callback.Run(LeveldbStatusToError(s)); | 94 callback.Run(LeveldbStatusToError(s)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void LevelDBServiceImpl::Destroy(filesystem::mojom::DirectoryPtr directory, | 97 void LevelDBServiceImpl::Destroy(filesystem::mojom::DirectoryPtr directory, |
| 98 const std::string& dbname, | 98 const std::string& dbname, |
| 99 const DestroyCallback& callback) { | 99 const DestroyCallback& callback) { |
| 100 leveldb::Options options; | 100 leveldb::Options options; |
| 101 // Register our directory with the file thread. | 101 // Register our directory with the file thread. |
| 102 LevelDBMojoProxy::OpaqueDir* dir = | 102 LevelDBMojoProxy::OpaqueDir* dir = |
| 103 thread_->RegisterDirectory(std::move(directory)); | 103 thread_->RegisterDirectory(std::move(directory)); |
| 104 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); | 104 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); |
| 105 options.env = env_mojo.get(); | 105 options.env = env_mojo.get(); |
| 106 callback.Run(LeveldbStatusToError(leveldb::DestroyDB(dbname, options))); | 106 callback.Run(LeveldbStatusToError(leveldb::DestroyDB(dbname, options))); |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace leveldb | 109 } // namespace leveldb |
| OLD | NEW |