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

Side by Side Diff: chrome/browser/metrics/leak_detector/leak_detector_remote_controller.cc

Issue 2062743002: Randomly enable leak detector based on probability parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use RenderThreadObserver interface to shutdown remote client on same thread Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h " 5 #include "chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h "
6 6
7 #include "components/metrics/leak_detector/protobuf_to_mojo_converter.h" 7 #include "components/metrics/leak_detector/protobuf_to_mojo_converter.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 9
10 namespace metrics { 10 namespace metrics {
(...skipping 14 matching lines...) Expand all
25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
26 new LeakDetectorRemoteController(std::move(request)); 26 new LeakDetectorRemoteController(std::move(request));
27 } 27 }
28 28
29 void LeakDetectorRemoteController::GetParams( 29 void LeakDetectorRemoteController::GetParams(
30 const mojom::LeakDetector::GetParamsCallback& callback) { 30 const mojom::LeakDetector::GetParamsCallback& callback) {
31 // If no controller exists, send an empty param protobuf. The remote caller 31 // If no controller exists, send an empty param protobuf. The remote caller
32 // should not initialize anything if the params are empty. 32 // should not initialize anything if the params are empty.
33 MemoryLeakReportProto_Params params; 33 MemoryLeakReportProto_Params params;
34 if (g_local_controller) { 34 if (g_local_controller) {
35 params = g_local_controller->GetParams(); 35 params = g_local_controller->GetParamsAndRecordRequest();
36 // A non-zero sampling rate tells the remote process to enable the leak
37 // detector. Otherwise, the remote process will not initialize it.
38 leak_detector_enabled_on_remote_process_ = params.sampling_rate() > 0;
36 } 39 }
37 40
38 mojo::StructPtr<mojom::LeakDetectorParams> mojo_params = 41 mojo::StructPtr<mojom::LeakDetectorParams> mojo_params =
39 mojom::LeakDetectorParams::New(); 42 mojom::LeakDetectorParams::New();
40 leak_detector::protobuf_to_mojo_converter::ParamsToMojo(params, 43 leak_detector::protobuf_to_mojo_converter::ParamsToMojo(params,
41 mojo_params.get()); 44 mojo_params.get());
42 45
43 callback.Run(std::move(mojo_params)); 46 callback.Run(std::move(mojo_params));
44 } 47 }
45 48
46 void LeakDetectorRemoteController::SendLeakReports( 49 void LeakDetectorRemoteController::SendLeakReports(
47 std::vector<mojom::MemoryLeakReportPtr> reports) { 50 std::vector<mojom::MemoryLeakReportPtr> reports) {
48 std::vector<MemoryLeakReportProto> report_protos; 51 std::vector<MemoryLeakReportProto> report_protos;
49 report_protos.reserve(reports.size()); 52 report_protos.reserve(reports.size());
50 53
51 for (const mojom::MemoryLeakReportPtr& report : reports) { 54 for (const mojom::MemoryLeakReportPtr& report : reports) {
52 report_protos.push_back(MemoryLeakReportProto()); 55 report_protos.push_back(MemoryLeakReportProto());
53 MemoryLeakReportProto* proto = &report_protos.back(); 56 MemoryLeakReportProto* proto = &report_protos.back();
54 57
55 leak_detector::protobuf_to_mojo_converter::MojoToReport(*report, proto); 58 leak_detector::protobuf_to_mojo_converter::MojoToReport(*report, proto);
56 } 59 }
57 DCHECK(g_local_controller); 60 DCHECK(g_local_controller);
58 g_local_controller->SendLeakReports(report_protos); 61 g_local_controller->SendLeakReports(report_protos);
59 } 62 }
60 63
64 void LeakDetectorRemoteController::OnRemoteProcessShutdown() {
65 if (leak_detector_enabled_on_remote_process_) {
66 DCHECK(g_local_controller);
67 g_local_controller->OnRemoteProcessShutdown();
68 }
69 }
70
61 LeakDetectorRemoteController::LeakDetectorRemoteController( 71 LeakDetectorRemoteController::LeakDetectorRemoteController(
62 mojom::LeakDetectorRequest request) 72 mojom::LeakDetectorRequest request)
63 : binding_(this, std::move(request)) {} 73 : binding_(this, std::move(request)),
74 leak_detector_enabled_on_remote_process_(false) {
75 binding_.set_connection_error_handler(
76 base::Bind(&LeakDetectorRemoteController::OnRemoteProcessShutdown,
77 base::Unretained(this)));
78 }
64 79
65 // static 80 // static
66 void LeakDetectorRemoteController::SetLocalControllerInstance( 81 void LeakDetectorRemoteController::SetLocalControllerInstance(
67 LocalController* controller) { 82 LocalController* controller) {
68 g_local_controller = controller; 83 g_local_controller = controller;
69 } 84 }
70 85
71 } // namespace metrics 86 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698