OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/leak_detector_remote_client.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/threading/thread_task_runner_handle.h" | |
9 #include "components/metrics/proto/memory_leak_report.pb.h" | |
10 #include "content/public/common/service_registry.h" | |
11 #include "content/public/renderer/render_thread.h" | |
12 #include "mojo/public/cpp/bindings/interface_request.h" | |
13 | |
14 LeakDetectorRemoteClient::LeakDetectorRemoteClient() { | |
15 // Connect to Mojo service. | |
16 content::RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService( | |
17 mojo::GetProxy(&remote_service_)); | |
18 | |
19 remote_service_->GetParams( | |
20 base::Bind(&LeakDetectorRemoteClient::OnParamsReceived, | |
21 base::Unretained(this))); | |
22 } | |
23 | |
24 LeakDetectorRemoteClient::~LeakDetectorRemoteClient() { | |
25 metrics::LeakDetector::GetInstance()->RemoveObserver(this); | |
Ilya Sherman
2016/06/16 18:14:20
Is it safe to call RemoveObserver() if AddObserver
Simon Que
2016/06/17 01:30:38
Yes, the observers are added to base::ObserverList
Ilya Sherman
2016/06/17 01:32:50
Okay. In that case, LGTM with the added documenta
| |
26 } | |
27 | |
28 void LeakDetectorRemoteClient::OnParamsReceived(mojo::String result) { | |
29 if (result.empty()) | |
30 return; | |
31 | |
32 metrics::MemoryLeakReportProto::Params params; | |
33 bool params_decoded = params.ParseFromString(result.get()); | |
34 DCHECK(params_decoded); | |
35 | |
36 metrics::LeakDetector* detector = metrics::LeakDetector::GetInstance(); | |
37 detector->AddObserver(this); | |
38 detector->Init(params, base::ThreadTaskRunnerHandle::Get()); | |
39 } | |
40 | |
41 void LeakDetectorRemoteClient::OnLeaksFound( | |
42 const std::vector<metrics::MemoryLeakReportProto>& reports) { | |
43 // TODO(sque): Handle reports. | |
44 } | |
OLD | NEW |