| 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 #ifndef COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ | 5 #ifndef COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ |
| 6 #define COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ | 6 #define COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "components/leveldb/leveldb_mojo_proxy.h" | 9 #include "components/leveldb/leveldb_mojo_proxy.h" |
| 10 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 10 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
| 11 #include "mojo/public/cpp/bindings/binding_set.h" | 11 #include "mojo/public/cpp/bindings/binding_set.h" |
| 12 | 12 |
| 13 namespace leveldb { | 13 namespace leveldb { |
| 14 | 14 |
| 15 // Creates LevelDBDatabases based scoped to a |directory|/|dbname|. | 15 // Creates LevelDBDatabases based scoped to a |directory|/|dbname|. |
| 16 class LevelDBServiceImpl : public mojom::LevelDBService { | 16 class LevelDBServiceImpl : public mojom::LevelDBService { |
| 17 public: | 17 public: |
| 18 // The |file_task_runner| is used to run tasks to interact with the | 18 // The |file_task_runner| is used to run tasks to interact with the |
| 19 // file_service. Specifically this task runner must NOT be the same as the | 19 // file_service. Specifically this task runner must NOT be the same as the |
| 20 // task runner this implementation runs on, or deadlock might occur. | 20 // task runner this implementation runs on, or deadlock might occur. |
| 21 LevelDBServiceImpl( | 21 LevelDBServiceImpl( |
| 22 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | 22 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
| 23 ~LevelDBServiceImpl() override; | 23 ~LevelDBServiceImpl() override; |
| 24 | 24 |
| 25 // Overridden from LevelDBService: | 25 // Overridden from LevelDBService: |
| 26 void SetEnvironmentName(const std::string& name) override; | |
| 27 void Open(filesystem::mojom::DirectoryPtr directory, | 26 void Open(filesystem::mojom::DirectoryPtr directory, |
| 28 const std::string& dbname, | 27 const std::string& dbname, |
| 29 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, | 28 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, |
| 30 const OpenCallback& callback) override; | 29 const OpenCallback& callback) override; |
| 31 void OpenWithOptions( | 30 void OpenWithOptions( |
| 32 leveldb::mojom::OpenOptionsPtr open_options, | 31 leveldb::mojom::OpenOptionsPtr open_options, |
| 33 filesystem::mojom::DirectoryPtr directory, | 32 filesystem::mojom::DirectoryPtr directory, |
| 34 const std::string& dbname, | 33 const std::string& dbname, |
| 35 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, | 34 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, |
| 36 const OpenCallback& callback) override; | 35 const OpenCallback& callback) override; |
| 37 void OpenInMemory(leveldb::mojom::LevelDBDatabaseAssociatedRequest database, | 36 void OpenInMemory(leveldb::mojom::LevelDBDatabaseAssociatedRequest database, |
| 38 const OpenInMemoryCallback& callback) override; | 37 const OpenInMemoryCallback& callback) override; |
| 39 void Destroy(filesystem::mojom::DirectoryPtr directory, | 38 void Destroy(filesystem::mojom::DirectoryPtr directory, |
| 40 const std::string& dbname, | 39 const std::string& dbname, |
| 41 const DestroyCallback& callback) override; | 40 const DestroyCallback& callback) override; |
| 42 | 41 |
| 43 private: | 42 private: |
| 44 // Thread to own the mojo message pipe. Because leveldb spawns multiple | 43 // Thread to own the mojo message pipe. Because leveldb spawns multiple |
| 45 // threads that want to call file stuff, we create a dedicated thread to send | 44 // threads that want to call file stuff, we create a dedicated thread to send |
| 46 // and receive mojo message calls. | 45 // and receive mojo message calls. |
| 47 scoped_refptr<LevelDBMojoProxy> thread_; | 46 scoped_refptr<LevelDBMojoProxy> thread_; |
| 48 | 47 |
| 49 std::string environment_name_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceImpl); | 48 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceImpl); |
| 52 }; | 49 }; |
| 53 | 50 |
| 54 } // namespace leveldb | 51 } // namespace leveldb |
| 55 | 52 |
| 56 #endif // COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ | 53 #endif // COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ |
| OLD | NEW |