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/browser/metrics/leak_detector/leak_detector_remote_controller.h
" | |
6 | |
7 #include "components/metrics/leak_detector/protobuf_to_mojo_converter.h" | |
8 #include "content/public/browser/browser_thread.h" | |
9 | |
10 namespace metrics { | |
11 | |
12 namespace { | |
13 | |
14 // All instances of LeakDetectorRemoteController will need to reference a single | |
15 // LocalController instance, referenced by this pointer. All remote LeakDetector | |
16 // clients will get their params from and send leak reports to this instance. | |
17 LeakDetectorRemoteController::LocalController* g_local_controller = nullptr; | |
18 | |
19 } // namespace | |
20 | |
21 LeakDetectorRemoteController::~LeakDetectorRemoteController() {} | |
22 | |
23 // static | |
24 void LeakDetectorRemoteController::Create(mojom::LeakDetectorRequest request) { | |
25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
26 new LeakDetectorRemoteController(std::move(request)); | |
27 } | |
28 | |
29 void LeakDetectorRemoteController::GetParams( | |
30 const mojom::LeakDetector::GetParamsCallback& callback) { | |
31 // If no controller exists, send an empty param protobuf. The remote caller | |
32 // should not initialize anything if the params are empty. | |
33 MemoryLeakReportProto_Params params; | |
34 if (g_local_controller) { | |
35 params = g_local_controller->GetParams(); | |
36 } | |
37 | |
38 mojo::StructPtr<mojom::LeakDetectorParams> mojo_params = | |
39 mojom::LeakDetectorParams::New(); | |
40 leak_detector::protobuf_to_mojo_converter::ParamsToMojo(params, | |
41 mojo_params.get()); | |
42 | |
43 callback.Run(std::move(mojo_params)); | |
44 } | |
45 | |
46 void LeakDetectorRemoteController::SendLeakReports( | |
47 std::vector<mojom::MemoryLeakReportPtr> reports) { | |
48 std::vector<MemoryLeakReportProto> report_protos; | |
49 report_protos.reserve(reports.size()); | |
50 | |
51 for (const mojom::MemoryLeakReportPtr& report : reports) { | |
52 report_protos.push_back(MemoryLeakReportProto()); | |
53 MemoryLeakReportProto* proto = &report_protos.back(); | |
54 | |
55 leak_detector::protobuf_to_mojo_converter::MojoToReport(*report, proto); | |
56 } | |
57 DCHECK(g_local_controller); | |
58 g_local_controller->SendLeakReports(report_protos); | |
59 } | |
60 | |
61 LeakDetectorRemoteController::LeakDetectorRemoteController( | |
62 mojom::LeakDetectorRequest request) | |
63 : binding_(this, std::move(request)) {} | |
64 | |
65 // static | |
66 void LeakDetectorRemoteController::SetLocalControllerInstance( | |
67 LocalController* controller) { | |
68 g_local_controller = controller; | |
69 } | |
70 | |
71 } // namespace metrics | |
OLD | NEW |