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