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 "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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 std::vector<mojom::MemoryLeakReportPtr> reports) { | 50 std::vector<mojom::MemoryLeakReportPtr> reports) { |
51 std::vector<MemoryLeakReportProto> report_protos; | 51 std::vector<MemoryLeakReportProto> report_protos; |
52 report_protos.reserve(reports.size()); | 52 report_protos.reserve(reports.size()); |
53 | 53 |
54 for (const mojom::MemoryLeakReportPtr& report : reports) { | 54 for (const mojom::MemoryLeakReportPtr& report : reports) { |
55 report_protos.push_back(MemoryLeakReportProto()); | 55 report_protos.push_back(MemoryLeakReportProto()); |
56 MemoryLeakReportProto* proto = &report_protos.back(); | 56 MemoryLeakReportProto* proto = &report_protos.back(); |
57 | 57 |
58 leak_detector::protobuf_to_mojo_converter::MojoToReport(*report, proto); | 58 leak_detector::protobuf_to_mojo_converter::MojoToReport(*report, proto); |
59 } | 59 } |
60 DCHECK(g_local_controller); | 60 if (g_local_controller) { |
61 g_local_controller->SendLeakReports(report_protos); | 61 g_local_controller->SendLeakReports(report_protos); |
| 62 } |
62 } | 63 } |
63 | 64 |
64 void LeakDetectorRemoteController::OnRemoteProcessShutdown() { | 65 void LeakDetectorRemoteController::OnRemoteProcessShutdown() { |
65 if (leak_detector_enabled_on_remote_process_) { | 66 if (leak_detector_enabled_on_remote_process_ && g_local_controller) { |
66 DCHECK(g_local_controller); | |
67 g_local_controller->OnRemoteProcessShutdown(); | 67 g_local_controller->OnRemoteProcessShutdown(); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 LeakDetectorRemoteController::LeakDetectorRemoteController( | 71 LeakDetectorRemoteController::LeakDetectorRemoteController( |
72 mojom::LeakDetectorRequest request) | 72 mojom::LeakDetectorRequest request) |
73 : binding_(this, std::move(request)), | 73 : binding_(this, std::move(request)), |
74 leak_detector_enabled_on_remote_process_(false) { | 74 leak_detector_enabled_on_remote_process_(false) { |
75 binding_.set_connection_error_handler( | 75 binding_.set_connection_error_handler( |
76 base::Bind(&LeakDetectorRemoteController::OnRemoteProcessShutdown, | 76 base::Bind(&LeakDetectorRemoteController::OnRemoteProcessShutdown, |
77 base::Unretained(this))); | 77 base::Unretained(this))); |
78 } | 78 } |
79 | 79 |
80 // static | 80 // static |
81 void LeakDetectorRemoteController::SetLocalControllerInstance( | 81 void LeakDetectorRemoteController::SetLocalControllerInstance( |
82 LocalController* controller) { | 82 LocalController* controller) { |
| 83 // This must be on the same thread as the Mojo-based functions of this class, |
| 84 // to avoid race conditions on |g_local_controller|. |
| 85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
83 g_local_controller = controller; | 86 g_local_controller = controller; |
84 } | 87 } |
85 | 88 |
86 } // namespace metrics | 89 } // namespace metrics |
OLD | NEW |