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_APP_H_ | 5 #ifndef COMPONENTS_LEVELDB_LEVELDB_APP_H_ |
6 #define COMPONENTS_LEVELDB_LEVELDB_APP_H_ | 6 #define COMPONENTS_LEVELDB_LEVELDB_APP_H_ |
7 | 7 |
| 8 #include "components/leveldb/leveldb_file_thread.h" |
8 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 9 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
9 #include "mojo/public/cpp/bindings/weak_binding_set.h" | 10 #include "mojo/public/cpp/bindings/weak_binding_set.h" |
10 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 11 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
11 #include "mojo/shell/public/cpp/interface_factory.h" | 12 #include "mojo/shell/public/cpp/interface_factory.h" |
12 #include "mojo/shell/public/cpp/shell_client.h" | 13 #include "mojo/shell/public/cpp/shell_client.h" |
13 | 14 |
14 namespace leveldb { | 15 namespace leveldb { |
15 | 16 |
16 class LevelDBApp : public mojo::ShellClient, | 17 class LevelDBApp : public mojo::ShellClient, |
17 public mojo::InterfaceFactory<LevelDBService> { | 18 public mojo::InterfaceFactory<LevelDBService>, |
| 19 public LevelDBService { |
18 public: | 20 public: |
19 LevelDBApp(); | 21 LevelDBApp(); |
20 ~LevelDBApp() override; | 22 ~LevelDBApp() override; |
21 | 23 |
22 private: | 24 private: |
23 // |ShellClient| override: | 25 // |ShellClient| override: |
24 void Initialize(mojo::Shell* shell, | 26 void Initialize(mojo::Shell* shell, |
25 const std::string& url, | 27 const std::string& url, |
26 uint32_t id) override; | 28 uint32_t id) override; |
27 bool AcceptConnection(mojo::Connection* connection) override; | 29 bool AcceptConnection(mojo::Connection* connection) override; |
28 | 30 |
29 // TODO(erg): What do we have to do on shell error? | 31 // TODO(erg): What do we have to do on shell error? |
30 // bool OnShellConnectionError() override; | 32 // bool OnShellConnectionError() override; |
31 | 33 |
32 // |InterfaceFactory<LevelDBService>| implementation: | 34 // |InterfaceFactory<LevelDBService>| implementation: |
33 void Create(mojo::Connection* connection, | 35 void Create(mojo::Connection* connection, |
34 mojo::InterfaceRequest<LevelDBService> request) override; | 36 mojo::InterfaceRequest<LevelDBService> request) override; |
35 | 37 |
| 38 // Overridden from LevelDBService: |
| 39 void Open(filesystem::DirectoryPtr directory, |
| 40 const mojo::String& dbname, |
| 41 mojo::InterfaceRequest<LevelDBDatabase> database, |
| 42 const OpenCallback& callback) override; |
| 43 |
36 mojo::TracingImpl tracing_; | 44 mojo::TracingImpl tracing_; |
37 scoped_ptr<LevelDBService> service_; | |
38 mojo::WeakBindingSet<LevelDBService> bindings_; | 45 mojo::WeakBindingSet<LevelDBService> bindings_; |
39 | 46 |
| 47 // Thread to own the mojo message pipe. Because leveldb spawns multiple |
| 48 // threads that want to call file stuff, we create a dedicated thread to send |
| 49 // and receive mojo message calls. |
| 50 scoped_refptr<LevelDBFileThread> thread_; |
| 51 |
40 DISALLOW_COPY_AND_ASSIGN(LevelDBApp); | 52 DISALLOW_COPY_AND_ASSIGN(LevelDBApp); |
41 }; | 53 }; |
42 | 54 |
43 } // namespace leveldb | 55 } // namespace leveldb |
44 | 56 |
45 #endif // COMPONENTS_LEVELDB_LEVELDB_APP_H_ | 57 #endif // COMPONENTS_LEVELDB_LEVELDB_APP_H_ |
OLD | NEW |