OLD | NEW |
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 <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
10 #include "components/metrics/leak_detector/protobuf_to_mojo_converter.h" | 12 #include "components/metrics/leak_detector/protobuf_to_mojo_converter.h" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "mojo/public/cpp/bindings/strong_binding.h" | 14 #include "mojo/public/cpp/bindings/strong_binding.h" |
13 | 15 |
14 namespace metrics { | 16 namespace metrics { |
15 | 17 |
16 namespace { | 18 namespace { |
(...skipping 16 matching lines...) Expand all Loading... |
33 base::WrapUnique(new LeakDetectorRemoteController); | 35 base::WrapUnique(new LeakDetectorRemoteController); |
34 base::Closure error_handler = | 36 base::Closure error_handler = |
35 base::Bind(&LeakDetectorRemoteController::OnRemoteProcessShutdown, | 37 base::Bind(&LeakDetectorRemoteController::OnRemoteProcessShutdown, |
36 base::Unretained(controller.get())); | 38 base::Unretained(controller.get())); |
37 auto binding = | 39 auto binding = |
38 mojo::MakeStrongBinding(std::move(controller), std::move(request)); | 40 mojo::MakeStrongBinding(std::move(controller), std::move(request)); |
39 binding->set_connection_error_handler(error_handler); | 41 binding->set_connection_error_handler(error_handler); |
40 } | 42 } |
41 | 43 |
42 void LeakDetectorRemoteController::GetParams( | 44 void LeakDetectorRemoteController::GetParams( |
43 const mojom::LeakDetector::GetParamsCallback& callback) { | 45 mojom::LeakDetector::GetParamsCallback callback) { |
44 // If no controller exists, send an empty param protobuf. The remote caller | 46 // If no controller exists, send an empty param protobuf. The remote caller |
45 // should not initialize anything if the params are empty. | 47 // should not initialize anything if the params are empty. |
46 MemoryLeakReportProto_Params params; | 48 MemoryLeakReportProto_Params params; |
47 if (g_local_controller) { | 49 if (g_local_controller) { |
48 params = g_local_controller->GetParamsAndRecordRequest(); | 50 params = g_local_controller->GetParamsAndRecordRequest(); |
49 // A non-zero sampling rate tells the remote process to enable the leak | 51 // A non-zero sampling rate tells the remote process to enable the leak |
50 // detector. Otherwise, the remote process will not initialize it. | 52 // detector. Otherwise, the remote process will not initialize it. |
51 leak_detector_enabled_on_remote_process_ = params.sampling_rate() > 0; | 53 leak_detector_enabled_on_remote_process_ = params.sampling_rate() > 0; |
52 } | 54 } |
53 | 55 |
54 mojo::StructPtr<mojom::LeakDetectorParams> mojo_params = | 56 mojo::StructPtr<mojom::LeakDetectorParams> mojo_params = |
55 mojom::LeakDetectorParams::New(); | 57 mojom::LeakDetectorParams::New(); |
56 leak_detector::protobuf_to_mojo_converter::ParamsToMojo(params, | 58 leak_detector::protobuf_to_mojo_converter::ParamsToMojo(params, |
57 mojo_params.get()); | 59 mojo_params.get()); |
58 | 60 |
59 callback.Run(std::move(mojo_params)); | 61 std::move(callback).Run(std::move(mojo_params)); |
60 } | 62 } |
61 | 63 |
62 void LeakDetectorRemoteController::SendLeakReports( | 64 void LeakDetectorRemoteController::SendLeakReports( |
63 std::vector<mojom::MemoryLeakReportPtr> reports) { | 65 std::vector<mojom::MemoryLeakReportPtr> reports) { |
64 std::vector<MemoryLeakReportProto> report_protos; | 66 std::vector<MemoryLeakReportProto> report_protos; |
65 report_protos.reserve(reports.size()); | 67 report_protos.reserve(reports.size()); |
66 | 68 |
67 for (const mojom::MemoryLeakReportPtr& report : reports) { | 69 for (const mojom::MemoryLeakReportPtr& report : reports) { |
68 report_protos.push_back(MemoryLeakReportProto()); | 70 report_protos.push_back(MemoryLeakReportProto()); |
69 MemoryLeakReportProto* proto = &report_protos.back(); | 71 MemoryLeakReportProto* proto = &report_protos.back(); |
(...skipping 17 matching lines...) Expand all Loading... |
87 // static | 89 // static |
88 void LeakDetectorRemoteController::SetLocalControllerInstance( | 90 void LeakDetectorRemoteController::SetLocalControllerInstance( |
89 LocalController* controller) { | 91 LocalController* controller) { |
90 // This must be on the same thread as the Mojo-based functions of this class, | 92 // This must be on the same thread as the Mojo-based functions of this class, |
91 // to avoid race conditions on |g_local_controller|. | 93 // to avoid race conditions on |g_local_controller|. |
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
93 g_local_controller = controller; | 95 g_local_controller = controller; |
94 } | 96 } |
95 | 97 |
96 } // namespace metrics | 98 } // namespace metrics |
OLD | NEW |