Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: components/leveldb/leveldb_service_impl.h

Issue 2722293002: Fix lifetime of leveldb::MojoEnv instances. (Closed)
Patch Set: annotate leaks Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 class MojoEnv;
16
15 // Creates LevelDBDatabases based scoped to a |directory|/|dbname|. 17 // Creates LevelDBDatabases based scoped to a |directory|/|dbname|.
16 class LevelDBServiceImpl : public mojom::LevelDBService { 18 class LevelDBServiceImpl : public mojom::LevelDBService {
17 public: 19 public:
18 // The |file_task_runner| is used to run tasks to interact with the 20 // 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 21 // file_service. Specifically this task runner must NOT be the same as the
20 // task runner this implementation runs on, or deadlock might occur. 22 // task runner this implementation runs on, or deadlock might occur.
21 LevelDBServiceImpl( 23 explicit LevelDBServiceImpl(MojoEnv* env);
22 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
23 ~LevelDBServiceImpl() override; 24 ~LevelDBServiceImpl() override;
24 25
25 // Overridden from LevelDBService: 26 // Overridden from LevelDBService:
26 void SetEnvironmentName(const std::string& name) override;
27 void Open(filesystem::mojom::DirectoryPtr directory, 27 void Open(filesystem::mojom::DirectoryPtr directory,
28 const std::string& dbname, 28 const std::string& dbname,
29 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, 29 leveldb::mojom::LevelDBDatabaseAssociatedRequest database,
30 const OpenCallback& callback) override; 30 const OpenCallback& callback) override;
31 void OpenWithOptions( 31 void OpenWithOptions(
32 leveldb::mojom::OpenOptionsPtr open_options, 32 leveldb::mojom::OpenOptionsPtr open_options,
33 filesystem::mojom::DirectoryPtr directory, 33 filesystem::mojom::DirectoryPtr directory,
34 const std::string& dbname, 34 const std::string& dbname,
35 leveldb::mojom::LevelDBDatabaseAssociatedRequest database, 35 leveldb::mojom::LevelDBDatabaseAssociatedRequest database,
36 const OpenCallback& callback) override; 36 const OpenCallback& callback) override;
37 void OpenInMemory(leveldb::mojom::LevelDBDatabaseAssociatedRequest database, 37 void OpenInMemory(leveldb::mojom::LevelDBDatabaseAssociatedRequest database,
38 const OpenInMemoryCallback& callback) override; 38 const OpenInMemoryCallback& callback) override;
39 void Destroy(filesystem::mojom::DirectoryPtr directory, 39 void Destroy(filesystem::mojom::DirectoryPtr directory,
40 const std::string& dbname, 40 const std::string& dbname,
41 const DestroyCallback& callback) override; 41 const DestroyCallback& callback) override;
42 42
43 private: 43 private:
44 // Thread to own the mojo message pipe. Because leveldb spawns multiple 44 MojoEnv* env_;
45 // threads that want to call file stuff, we create a dedicated thread to send
46 // and receive mojo message calls.
47 scoped_refptr<LevelDBMojoProxy> thread_;
48
49 std::string environment_name_;
50 45
51 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceImpl); 46 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceImpl);
52 }; 47 };
53 48
54 } // namespace leveldb 49 } // namespace leveldb
55 50
56 #endif // COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_ 51 #endif // COMPONENTS_LEVELDB_LEVELDB_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698