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

Side by Side Diff: components/leveldb/leveldb_app.cc

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 #include "components/leveldb/leveldb_app.h" 5 #include "components/leveldb/leveldb_app.h"
6 6
7 #include "base/debug/leak_annotations.h"
8 #include "components/leveldb/env_mojo.h"
7 #include "components/leveldb/leveldb_service_impl.h" 9 #include "components/leveldb/leveldb_service_impl.h"
8 #include "services/service_manager/public/cpp/service_context.h" 10 #include "services/service_manager/public/cpp/service_context.h"
9 11
10 namespace leveldb { 12 namespace leveldb {
11 13
12 LevelDBApp::LevelDBApp() : file_thread_("LevelDBFile") { 14 LevelDBApp::LevelDBApp()
15 : file_thread_("LevelDBFile"),
16 env_(nullptr) {
13 registry_.AddInterface<mojom::LevelDBService>(this); 17 registry_.AddInterface<mojom::LevelDBService>(this);
14 } 18 }
15 19
16 LevelDBApp::~LevelDBApp() {} 20 LevelDBApp::~LevelDBApp() {}
17 21
18 void LevelDBApp::OnStart() { 22 void LevelDBApp::OnStart() {
19 tracing_.Initialize(context()->connector(), context()->identity().name()); 23 tracing_.Initialize(context()->connector(), context()->identity().name());
20 } 24 }
21 25
22 void LevelDBApp::OnBindInterface( 26 void LevelDBApp::OnBindInterface(
23 const service_manager::ServiceInfo& source_info, 27 const service_manager::ServiceInfo& source_info,
24 const std::string& interface_name, 28 const std::string& interface_name,
25 mojo::ScopedMessagePipeHandle interface_pipe) { 29 mojo::ScopedMessagePipeHandle interface_pipe) {
26 registry_.BindInterface(source_info.identity, interface_name, 30 registry_.BindInterface(source_info.identity, interface_name,
27 std::move(interface_pipe)); 31 std::move(interface_pipe));
28 } 32 }
29 33
30 void LevelDBApp::Create(const service_manager::Identity& remote_identity, 34 void LevelDBApp::Create(const service_manager::Identity& remote_identity,
31 leveldb::mojom::LevelDBServiceRequest request) { 35 leveldb::mojom::LevelDBServiceRequest request) {
32 if (!service_) { 36 if (!service_) {
33 if (!file_thread_.IsRunning()) 37 if (!file_thread_.IsRunning())
34 file_thread_.Start(); 38 file_thread_.Start();
35 service_.reset( 39 if (!env_) {
36 new LevelDBServiceImpl(file_thread_.message_loop()->task_runner())); 40 env_ = new MojoEnv(file_thread_.message_loop()->task_runner());
41 ANNOTATE_LEAKING_OBJECT_PTR(env_);
42 }
43 service_.reset(new LevelDBServiceImpl(env_));
37 } 44 }
38 bindings_.AddBinding(service_.get(), std::move(request)); 45 bindings_.AddBinding(service_.get(), std::move(request));
39 } 46 }
40 47
41 } // namespace leveldb 48 } // namespace leveldb
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698