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

Unified Diff: chrome/renderer/leak_detector/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: Update ProtobufToMojoConverterTest Created 4 years, 5 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
« no previous file with comments | « chrome/renderer/leak_detector/leak_detector_remote_client.h ('k') | components/components_tests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/leak_detector/leak_detector_remote_client.cc
diff --git a/chrome/renderer/leak_detector/leak_detector_remote_client.cc b/chrome/renderer/leak_detector/leak_detector_remote_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f22f73211e76c949359fa435850a00bf6d6236ef
--- /dev/null
+++ b/chrome/renderer/leak_detector/leak_detector_remote_client.cc
@@ -0,0 +1,55 @@
+// 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/leak_detector_remote_client.h"
+
+#include "base/bind.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "components/metrics/leak_detector/protobuf_to_mojo_converter.h"
+#include "components/metrics/proto/memory_leak_report.pb.h"
+#include "content/public/renderer/render_thread.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+#include "services/shell/public/cpp/interface_provider.h"
+
+LeakDetectorRemoteClient::LeakDetectorRemoteClient() {
+ // Connect to Mojo service.
+ content::RenderThread::Get()->GetRemoteInterfaces()->GetInterface(
+ &remote_service_);
+
+ // It is safe to use "base::Unretained(this)" because |this| owns
+ // |remote_service_|. See example at:
+ // 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::mojom::LeakDetectorParams> result) {
+ metrics::MemoryLeakReportProto::Params params;
+ metrics::leak_detector::protobuf_to_mojo_converter::MojoToParams(*result,
+ &params);
+
+ metrics::LeakDetector* detector = metrics::LeakDetector::GetInstance();
+ detector->AddObserver(this);
+ detector->Init(params, base::ThreadTaskRunnerHandle::Get());
+}
+
+void LeakDetectorRemoteClient::OnLeaksFound(
+ const std::vector<metrics::MemoryLeakReportProto>& reports) {
+ std::vector<mojo::StructPtr<metrics::mojom::MemoryLeakReport>> result;
+
+ for (const metrics::MemoryLeakReportProto& report : reports) {
+ metrics::mojom::MemoryLeakReportPtr mojo_report =
+ metrics::mojom::MemoryLeakReport::New();
+ metrics::leak_detector::protobuf_to_mojo_converter::ReportToMojo(
+ report, mojo_report.get());
+ result.push_back(std::move(mojo_report));
+ }
+
+ remote_service_->SendLeakReports(std::move(result));
+}
« no previous file with comments | « chrome/renderer/leak_detector/leak_detector_remote_client.h ('k') | components/components_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698