| 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_file_thread.h" | 9 #include "components/leveldb/leveldb_file_thread.h" |
| 10 #include "components/leveldb/public/interfaces/leveldb.mojom.h" | 10 #include "components/leveldb/public/interfaces/leveldb.mojom.h" |
| 11 | 11 |
| 12 namespace mojo { |
| 13 class MessageLoopRef; |
| 14 } |
| 15 |
| 12 namespace leveldb { | 16 namespace leveldb { |
| 13 | 17 |
| 14 // Creates LevelDBDatabases based scoped to a |directory|/|dbname|. | 18 // Creates LevelDBDatabases based scoped to a |directory|/|dbname|. |
| 15 class LevelDBServiceImpl : public LevelDBService { | 19 class LevelDBServiceImpl : public LevelDBService { |
| 16 public: | 20 public: |
| 17 LevelDBServiceImpl(); | 21 explicit LevelDBServiceImpl(scoped_ptr<mojo::MessageLoopRef> ref); |
| 18 ~LevelDBServiceImpl() override; | 22 ~LevelDBServiceImpl() override; |
| 19 | 23 |
| 20 // Overridden from LevelDBService: | 24 // Overridden from LevelDBService: |
| 21 void Open(filesystem::DirectoryPtr directory, | 25 void Open(filesystem::DirectoryPtr directory, |
| 22 const mojo::String& dbname, | 26 const mojo::String& dbname, |
| 23 mojo::InterfaceRequest<LevelDBDatabase> database, | 27 mojo::InterfaceRequest<LevelDBDatabase> database, |
| 24 const OpenCallback& callback) override; | 28 const OpenCallback& callback) override; |
| 25 | 29 |
| 26 private: | 30 private: |
| 31 // Causes our application to quit when we go out of scope. |
| 32 scoped_ptr<mojo::MessageLoopRef> message_loop_ref_; |
| 33 |
| 27 // Thread to own the mojo message pipe. Because leveldb spawns multiple | 34 // Thread to own the mojo message pipe. Because leveldb spawns multiple |
| 28 // threads that want to call file stuff, we create a dedicated thread to send | 35 // threads that want to call file stuff, we create a dedicated thread to send |
| 29 // and receive mojo message calls. | 36 // and receive mojo message calls. |
| 30 scoped_refptr<LevelDBFileThread> thread_; | 37 scoped_refptr<LevelDBFileThread> thread_; |
| 31 | 38 |
| 32 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceImpl); | 39 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceImpl); |
| 33 }; | 40 }; |
| 34 | 41 |
| 35 } // namespace leveldb | 42 } // namespace leveldb |
| 36 | 43 |
| 37 #endif // COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ | 44 #endif // COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ |
| OLD | NEW |