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 "components/leveldb/env_mojo.h" | 7 #include "components/leveldb/env_mojo.h" |
8 #include "components/leveldb/leveldb_database_impl.h" | 8 #include "components/leveldb/leveldb_database_impl.h" |
9 #include "components/leveldb/util.h" | 9 #include "components/leveldb/util.h" |
10 #include "third_party/leveldatabase/env_chromium.h" | 10 #include "third_party/leveldatabase/env_chromium.h" |
11 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" | 11 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
12 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 12 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
13 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 13 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
14 #include "third_party/leveldatabase/src/include/leveldb/filter_policy.h" | 14 #include "third_party/leveldatabase/src/include/leveldb/filter_policy.h" |
15 #include "third_party/leveldatabase/src/include/leveldb/slice.h" | 15 #include "third_party/leveldatabase/src/include/leveldb/slice.h" |
16 | 16 |
17 namespace leveldb { | 17 namespace leveldb { |
18 | 18 |
19 LevelDBServiceImpl::LevelDBServiceImpl() : thread_(new LevelDBFileThread) {} | 19 LevelDBServiceImpl::LevelDBServiceImpl( |
| 20 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 21 : thread_(new LevelDBMojoProxy(std::move(task_runner))) {} |
20 | 22 |
21 LevelDBServiceImpl::~LevelDBServiceImpl() {} | 23 LevelDBServiceImpl::~LevelDBServiceImpl() {} |
22 | 24 |
23 void LevelDBServiceImpl::Open(filesystem::DirectoryPtr directory, | 25 void LevelDBServiceImpl::Open(filesystem::DirectoryPtr directory, |
24 const mojo::String& dbname, | 26 const mojo::String& dbname, |
25 leveldb::LevelDBDatabaseRequest database, | 27 leveldb::LevelDBDatabaseRequest database, |
26 const OpenCallback& callback) { | 28 const OpenCallback& callback) { |
27 // This is the place where we open a database. | 29 // This is the place where we open a database. |
28 leveldb::Options options; | 30 leveldb::Options options; |
29 options.create_if_missing = true; | 31 options.create_if_missing = true; |
30 options.paranoid_checks = true; | 32 options.paranoid_checks = true; |
31 // TODO(erg): Do we need a filter policy? | 33 // TODO(erg): Do we need a filter policy? |
32 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; | 34 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
33 options.compression = leveldb::kSnappyCompression; | 35 options.compression = leveldb::kSnappyCompression; |
34 | 36 |
35 // For info about the troubles we've run into with this parameter, see: | 37 // For info about the troubles we've run into with this parameter, see: |
36 // https://code.google.com/p/chromium/issues/detail?id=227313#c11 | 38 // https://code.google.com/p/chromium/issues/detail?id=227313#c11 |
37 options.max_open_files = 80; | 39 options.max_open_files = 80; |
38 | 40 |
39 // Register our directory with the file thread. | 41 // Register our directory with the file thread. |
40 LevelDBFileThread::OpaqueDir* dir = | 42 LevelDBMojoProxy::OpaqueDir* dir = |
41 thread_->RegisterDirectory(std::move(directory)); | 43 thread_->RegisterDirectory(std::move(directory)); |
42 | 44 |
43 scoped_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); | 45 scoped_ptr<MojoEnv> env_mojo(new MojoEnv(thread_, dir)); |
44 options.env = env_mojo.get(); | 46 options.env = env_mojo.get(); |
45 | 47 |
46 leveldb::DB* db = nullptr; | 48 leveldb::DB* db = nullptr; |
47 leveldb::Status s = leveldb::DB::Open(options, dbname.To<std::string>(), &db); | 49 leveldb::Status s = leveldb::DB::Open(options, dbname.To<std::string>(), &db); |
48 | 50 |
49 if (s.ok()) { | 51 if (s.ok()) { |
50 new LevelDBDatabaseImpl(std::move(database), std::move(env_mojo), | 52 new LevelDBDatabaseImpl(std::move(database), std::move(env_mojo), |
(...skipping 18 matching lines...) Expand all Loading... |
69 | 71 |
70 if (s.ok()) { | 72 if (s.ok()) { |
71 new LevelDBDatabaseImpl(std::move(database), std::move(env), | 73 new LevelDBDatabaseImpl(std::move(database), std::move(env), |
72 scoped_ptr<leveldb::DB>(db)); | 74 scoped_ptr<leveldb::DB>(db)); |
73 } | 75 } |
74 | 76 |
75 callback.Run(LeveldbStatusToError(s)); | 77 callback.Run(LeveldbStatusToError(s)); |
76 } | 78 } |
77 | 79 |
78 } // namespace leveldb | 80 } // namespace leveldb |
OLD | NEW |