Chromium Code Reviews| 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_controller.h" | 5 #include "chrome/browser/metrics/leak_detector_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 proto.analysis_interval_bytes(), | 98 proto.analysis_interval_bytes(), |
| 99 proto.size_suspicion_threshold(), | 99 proto.size_suspicion_threshold(), |
| 100 proto.call_stack_suspicion_threshold()); | 100 proto.call_stack_suspicion_threshold()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 LeakDetectorController::~LeakDetectorController() { | 103 LeakDetectorController::~LeakDetectorController() { |
| 104 DCHECK(thread_checker_.CalledOnValidThread()); | 104 DCHECK(thread_checker_.CalledOnValidThread()); |
| 105 LeakDetector::GetInstance()->RemoveObserver(this); | 105 LeakDetector::GetInstance()->RemoveObserver(this); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void LeakDetectorController::OnLeakFound( | 108 void LeakDetectorController::OnLeaksFound( |
| 109 const LeakDetector::LeakReport& report) { | 109 const std::vector<MemoryLeakReportProto>& reports) { |
| 110 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
| 111 | 111 |
| 112 // Initialize the new report with the protobuf template, which contains some | 112 for (const auto& report : reports) { |
| 113 // pre-filled data (parameter values). | 113 // Initialize the new report with the protobuf template, which contains some |
| 114 stored_reports_.push_back(leak_report_proto_template_); | 114 // pre-filled data (parameter values). |
| 115 MemoryLeakReportProto* proto = &stored_reports_.back(); | 115 stored_reports_.push_back(leak_report_proto_template_); |
| 116 MemoryLeakReportProto* proto = &stored_reports_.back(); | |
| 116 | 117 |
| 117 // Fill in the remaining fields of the protobuf with data from |report|. | 118 // Merge in the other fields. |
| 118 proto->set_size_bytes(report.alloc_size_bytes); | 119 proto->CheckTypeAndMergeFrom(report); |
|
Ilya Sherman
2016/04/14 01:08:45
Hmm, is the "CheckTypeAnd" prefix necessary? That
Simon Que
2016/04/14 01:24:30
I thought it was not available because MemoryLeakR
Ilya Sherman
2016/04/14 02:30:04
Yeah, the API docs on that site are not the cleare
| |
| 119 proto->mutable_call_stack()->Reserve(report.call_stack.size()); | 120 } |
| 120 for (uintptr_t call_stack_entry : report.call_stack) | |
| 121 proto->mutable_call_stack()->Add(call_stack_entry); | |
| 122 } | 121 } |
| 123 | 122 |
| 124 void LeakDetectorController::GetLeakReports( | 123 void LeakDetectorController::GetLeakReports( |
| 125 std::vector<MemoryLeakReportProto>* reports) { | 124 std::vector<MemoryLeakReportProto>* reports) { |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 125 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 *reports = std::move(stored_reports_); | 126 *reports = std::move(stored_reports_); |
| 128 } | 127 } |
| 129 | 128 |
| 130 } // namespace metrics | 129 } // namespace metrics |
| OLD | NEW |