| Index: chrome/browser/metrics/leak_detector/leak_detector_remote_controller.cc
|
| diff --git a/chrome/browser/metrics/leak_detector/leak_detector_remote_controller.cc b/chrome/browser/metrics/leak_detector/leak_detector_remote_controller.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cdf5f7f9e0875b4e89977543f6b18ad35f4d38e2
|
| --- /dev/null
|
| +++ b/chrome/browser/metrics/leak_detector/leak_detector_remote_controller.cc
|
| @@ -0,0 +1,85 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h"
|
| +
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +namespace metrics {
|
| +
|
| +namespace {
|
| +
|
| +// All instances of LeakDetectorRemoteController will need to reference a single
|
| +// LocalController instance, referenced by this pointer. All remote LeakDetector
|
| +// clients will get their params from and send leak reports to this instance.
|
| +LeakDetectorRemoteController::LocalController* g_local_controller = nullptr;
|
| +
|
| +} // namespace
|
| +
|
| +LeakDetectorRemoteController::~LeakDetectorRemoteController() {}
|
| +
|
| +// static
|
| +void LeakDetectorRemoteController::Create(mojom::LeakDetectorRequest request) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + new LeakDetectorRemoteController(std::move(request));
|
| +}
|
| +
|
| +void LeakDetectorRemoteController::GetParams(
|
| + const mojom::LeakDetector::GetParamsCallback& callback) {
|
| + // If no controller exists, send an empty param protobuf. The remote caller
|
| + // should not initialize anything if the params are empty.
|
| + MemoryLeakReportProto_Params params;
|
| + if (g_local_controller) {
|
| + params = g_local_controller->GetParams();
|
| + }
|
| +
|
| + mojo::StructPtr<mojom::LeakDetectorParams> mojo_params =
|
| + mojom::LeakDetectorParams::New();
|
| + mojo_params->sampling_rate = params.sampling_rate();
|
| + mojo_params->max_stack_depth = params.max_stack_depth();
|
| + mojo_params->analysis_interval_bytes = params.analysis_interval_bytes();
|
| + mojo_params->size_suspicion_threshold = params.size_suspicion_threshold();
|
| + mojo_params->call_stack_suspicion_threshold =
|
| + params.call_stack_suspicion_threshold();
|
| +
|
| + callback.Run(std::move(mojo_params));
|
| +}
|
| +
|
| +void LeakDetectorRemoteController::SendLeakReports(
|
| + mojo::Array<mojom::MemoryLeakReportPtr> reports) {
|
| + std::vector<MemoryLeakReportProto> report_protos;
|
| + report_protos.reserve(reports.size());
|
| +
|
| + for (const mojom::MemoryLeakReportPtr& report : reports) {
|
| + report_protos.push_back(MemoryLeakReportProto());
|
| + auto proto = report_protos.back();
|
| +
|
| + proto.set_size_bytes(report->size_bytes);
|
| + for (auto call_stack_addr : report->call_stack)
|
| + proto.add_call_stack(call_stack_addr);
|
| +
|
| + for (const auto& history_entry : report->alloc_breakdown_history) {
|
| + auto proto_entry = proto.add_alloc_breakdown_history();
|
| + for (auto count : history_entry->counts_by_size) {
|
| + proto_entry->add_counts_by_size(count);
|
| + }
|
| + proto_entry->set_count_for_call_stack(
|
| + history_entry->count_for_call_stack);
|
| + }
|
| + }
|
| + DCHECK(g_local_controller);
|
| + g_local_controller->SendLeakReports(report_protos);
|
| +}
|
| +
|
| +LeakDetectorRemoteController::LeakDetectorRemoteController(
|
| + mojom::LeakDetectorRequest request)
|
| + : binding_(this, std::move(request)) {}
|
| +
|
| +// static
|
| +void LeakDetectorRemoteController::SetLocalControllerInstance(
|
| + LocalController* controller) {
|
| + g_local_controller = controller;
|
| +}
|
| +
|
| +} // namespace metrics
|
|
|