Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2822)

Unified Diff: chrome/renderer/leak_detector_remote_client.cc

Issue 2064463002: Mojo interface/service for Leak Detector on remote process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment about unretained binding; Decompose protobufs into mojo structs Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/leak_detector_remote_client.cc
diff --git a/chrome/renderer/leak_detector_remote_client.cc b/chrome/renderer/leak_detector_remote_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..62f2526466c5d7c02cf6cc87c16392379d93517b
--- /dev/null
+++ b/chrome/renderer/leak_detector_remote_client.cc
@@ -0,0 +1,68 @@
+// 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/renderer/leak_detector_remote_client.h"
+
+#include "base/bind.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "components/metrics/proto/memory_leak_report.pb.h"
+#include "content/public/common/service_registry.h"
+#include "content/public/renderer/render_thread.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+
+LeakDetectorRemoteClient::LeakDetectorRemoteClient() {
+ // Connect to Mojo service.
+ content::RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
+ mojo::GetProxy(&remote_service_));
+
+ // It is safe to use base::Unretained(this). See example at:
Ilya Sherman 2016/06/17 22:18:20 nit: For the first sentence, I'd add ", because |t
Simon Que 2016/06/18 04:17:53 Done.
+ // https://www.chromium.org/developers/design-documents/mojo/validation
+ remote_service_->GetParams(base::Bind(
+ &LeakDetectorRemoteClient::OnParamsReceived, base::Unretained(this)));
+}
+
+LeakDetectorRemoteClient::~LeakDetectorRemoteClient() {
+ metrics::LeakDetector::GetInstance()->RemoveObserver(this);
+}
+
+void LeakDetectorRemoteClient::OnParamsReceived(
+ mojo::StructPtr<metrics::LeakDetectorParams> result) {
+ metrics::MemoryLeakReportProto::Params params;
+ params.set_sampling_rate(result->sampling_rate);
+ params.set_max_stack_depth(result->max_stack_depth);
+ params.set_analysis_interval_bytes(result->analysis_interval_bytes);
+ params.set_size_suspicion_threshold(result->size_suspicion_threshold);
+ params.set_call_stack_suspicion_threshold(
+ result->call_stack_suspicion_threshold);
Ilya Sherman 2016/06/17 22:18:20 It's kind of a shame that Mojo can't pass protocol
+
+ metrics::LeakDetector* detector = metrics::LeakDetector::GetInstance();
+ detector->AddObserver(this);
+ detector->Init(params, base::ThreadTaskRunnerHandle::Get());
+}
+
+void LeakDetectorRemoteClient::OnLeaksFound(
+ const std::vector<metrics::MemoryLeakReportProto>& reports) {
+ mojo::Array<mojo::StructPtr<metrics::MemoryLeakReport>> result;
+
+ for (const metrics::MemoryLeakReportProto& report : reports) {
+ metrics::MemoryLeakReportPtr mojo_report = metrics::MemoryLeakReport::New();
+ mojo_report->size_bytes = report.size_bytes();
+ for (auto call_stack_value : report.call_stack()) {
+ mojo_report->call_stack.push_back(call_stack_value);
+ }
+ for (const auto& history_entry : report.alloc_breakdown_history()) {
+ metrics::AllocationBreakdownPtr mojo_entry =
+ metrics::AllocationBreakdown::New();
+ for (auto count : history_entry.counts_by_size()) {
+ mojo_entry->counts_by_size.push_back(count);
+ }
+ mojo_entry->count_for_call_stack = history_entry.count_for_call_stack();
+
+ mojo_report->alloc_breakdown_history.push_back(std::move(mojo_entry));
+ }
+ result.push_back(std::move(mojo_report));
+ }
+
+ remote_service_->SendLeakReports(std::move(result));
+}

Powered by Google App Engine
This is Rietveld 408576698