| 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> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 7 #include "components/leveldb/env_mojo.h" | 10 #include "components/leveldb/env_mojo.h" |
| 8 #include "components/leveldb/leveldb_database_impl.h" | 11 #include "components/leveldb/leveldb_database_impl.h" |
| 9 #include "components/leveldb/public/cpp/util.h" | 12 #include "components/leveldb/public/cpp/util.h" |
| 10 #include "third_party/leveldatabase/env_chromium.h" | 13 #include "third_party/leveldatabase/env_chromium.h" |
| 11 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" | 14 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
| 12 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 15 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 13 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 16 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
| 14 #include "third_party/leveldatabase/src/include/leveldb/filter_policy.h" | 17 #include "third_party/leveldatabase/src/include/leveldb/filter_policy.h" |
| 15 #include "third_party/leveldatabase/src/include/leveldb/slice.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/slice.h" |
| 16 | 19 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 43 options.write_buffer_size = open_options->write_buffer_size; | 46 options.write_buffer_size = open_options->write_buffer_size; |
| 44 options.max_open_files = open_options->max_open_files; | 47 options.max_open_files = open_options->max_open_files; |
| 45 | 48 |
| 46 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; | 49 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
| 47 options.compression = leveldb::kSnappyCompression; | 50 options.compression = leveldb::kSnappyCompression; |
| 48 | 51 |
| 49 // Register our directory with the file thread. | 52 // Register our directory with the file thread. |
| 50 LevelDBMojoProxy::OpaqueDir* dir = | 53 LevelDBMojoProxy::OpaqueDir* dir = |
| 51 thread_->RegisterDirectory(std::move(directory)); | 54 thread_->RegisterDirectory(std::move(directory)); |
| 52 | 55 |
| 53 scoped_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); | 56 std::unique_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); |
| 54 options.env = env_mojo.get(); | 57 options.env = env_mojo.get(); |
| 55 | 58 |
| 56 leveldb::DB* db = nullptr; | 59 leveldb::DB* db = nullptr; |
| 57 leveldb::Status s = leveldb::DB::Open(options, dbname.To<std::string>(), &db); | 60 leveldb::Status s = leveldb::DB::Open(options, dbname.To<std::string>(), &db); |
| 58 | 61 |
| 59 if (s.ok()) { | 62 if (s.ok()) { |
| 60 new LevelDBDatabaseImpl(std::move(database), std::move(env_mojo), | 63 new LevelDBDatabaseImpl(std::move(database), std::move(env_mojo), |
| 61 scoped_ptr<leveldb::DB>(db)); | 64 base::WrapUnique(db)); |
| 62 } | 65 } |
| 63 | 66 |
| 64 callback.Run(LeveldbStatusToError(s)); | 67 callback.Run(LeveldbStatusToError(s)); |
| 65 } | 68 } |
| 66 | 69 |
| 67 void LevelDBServiceImpl::OpenInMemory(leveldb::LevelDBDatabaseRequest database, | 70 void LevelDBServiceImpl::OpenInMemory(leveldb::LevelDBDatabaseRequest database, |
| 68 const OpenCallback& callback) { | 71 const OpenCallback& callback) { |
| 69 leveldb::Options options; | 72 leveldb::Options options; |
| 70 options.create_if_missing = true; | 73 options.create_if_missing = true; |
| 71 options.max_open_files = 0; // Use minimum. | 74 options.max_open_files = 0; // Use minimum. |
| 72 | 75 |
| 73 scoped_ptr<leveldb::Env> env(leveldb::NewMemEnv(leveldb::Env::Default())); | 76 std::unique_ptr<leveldb::Env> env( |
| 77 leveldb::NewMemEnv(leveldb::Env::Default())); |
| 74 options.env = env.get(); | 78 options.env = env.get(); |
| 75 | 79 |
| 76 leveldb::DB* db = nullptr; | 80 leveldb::DB* db = nullptr; |
| 77 leveldb::Status s = leveldb::DB::Open(options, "", &db); | 81 leveldb::Status s = leveldb::DB::Open(options, "", &db); |
| 78 | 82 |
| 79 if (s.ok()) { | 83 if (s.ok()) { |
| 80 new LevelDBDatabaseImpl(std::move(database), std::move(env), | 84 new LevelDBDatabaseImpl(std::move(database), std::move(env), |
| 81 scoped_ptr<leveldb::DB>(db)); | 85 base::WrapUnique(db)); |
| 82 } | 86 } |
| 83 | 87 |
| 84 callback.Run(LeveldbStatusToError(s)); | 88 callback.Run(LeveldbStatusToError(s)); |
| 85 } | 89 } |
| 86 | 90 |
| 87 } // namespace leveldb | 91 } // namespace leveldb |
| OLD | NEW |