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