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)); | |
Ilya Sherman
2016/06/17 22:18:20
I really wish that Mojo didn't use a pattern that
| |
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 mojo::StructPtr<LeakDetectorParams> mojo_params = LeakDetectorParams::New(); | |
38 mojo_params->sampling_rate = params.sampling_rate(); | |
39 mojo_params->max_stack_depth = params.max_stack_depth(); | |
40 mojo_params->analysis_interval_bytes = params.analysis_interval_bytes(); | |
41 mojo_params->size_suspicion_threshold = params.size_suspicion_threshold(); | |
42 mojo_params->call_stack_suspicion_threshold = | |
43 params.call_stack_suspicion_threshold(); | |
44 | |
45 callback.Run(std::move(mojo_params)); | |
46 } | |
47 | |
48 void LeakDetectorRemoteController::SendLeakReports( | |
49 mojo::Array<MemoryLeakReportPtr> reports) { | |
50 std::vector<MemoryLeakReportProto> report_protos; | |
51 report_protos.reserve(reports.size()); | |
52 | |
53 for (const MemoryLeakReportPtr& report : reports) { | |
54 report_protos.push_back(MemoryLeakReportProto()); | |
55 auto proto = report_protos.back(); | |
56 | |
57 proto.set_size_bytes(report->size_bytes); | |
58 for (auto call_stack_addr : report->call_stack) | |
59 proto.add_call_stack(call_stack_addr); | |
60 | |
61 for (const auto& history_entry : report->alloc_breakdown_history) { | |
62 auto proto_entry = proto.add_alloc_breakdown_history(); | |
63 for (auto count : history_entry->counts_by_size) { | |
64 proto_entry->add_counts_by_size(count); | |
65 } | |
66 proto_entry->set_count_for_call_stack( | |
67 history_entry->count_for_call_stack); | |
68 } | |
69 } | |
70 DCHECK(g_local_controller); | |
71 g_local_controller->SendLeakReports(report_protos); | |
72 } | |
73 | |
74 LeakDetectorRemoteController::LeakDetectorRemoteController( | |
75 LeakDetectorRemoteRequest request) | |
76 : binding_(this, std::move(request)) {} | |
77 | |
78 // static | |
79 void LeakDetectorRemoteController::SetLocalControllerInstance( | |
80 LocalController* controller) { | |
81 g_local_controller = controller; | |
82 } | |
83 | |
84 } // namespace metrics | |
OLD | NEW |