| 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" |
| 11 #include "components/variations/variations_associated_data.h" | 11 #include "components/variations/variations_associated_data.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 12 | 13 |
| 13 namespace metrics { | 14 namespace metrics { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // Reads parameters for the field trial variation. Any parameters not present in | 18 // Reads parameters for the field trial variation. Any parameters not present in |
| 18 // the variation info or that cannot be parsed will be filled in with default | 19 // the variation info or that cannot be parsed will be filled in with default |
| 19 // values. Returns a MemoryLeakReportProto with the parameter fields filled in. | 20 // values. Returns a MemoryLeakReportProto with the parameter fields filled in. |
| 20 MemoryLeakReportProto::Params GetVariationParameters() { | 21 MemoryLeakReportProto::Params GetVariationParameters() { |
| 21 // Variation parameter names. | 22 // Variation parameter names. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace | 89 } // namespace |
| 89 | 90 |
| 90 LeakDetectorController::LeakDetectorController() | 91 LeakDetectorController::LeakDetectorController() |
| 91 : params_(GetVariationParameters()) { | 92 : params_(GetVariationParameters()) { |
| 92 LeakDetector* detector = LeakDetector::GetInstance(); | 93 LeakDetector* detector = LeakDetector::GetInstance(); |
| 93 detector->AddObserver(this); | 94 detector->AddObserver(this); |
| 94 | 95 |
| 95 // Leak detector parameters are stored in |params_|. | 96 // Leak detector parameters are stored in |params_|. |
| 96 detector->Init(params_); | 97 detector->Init(params_, content::BrowserThread::GetMessageLoopProxyForThread( |
| 98 content::BrowserThread::UI)); |
| 97 } | 99 } |
| 98 | 100 |
| 99 LeakDetectorController::~LeakDetectorController() { | 101 LeakDetectorController::~LeakDetectorController() { |
| 100 DCHECK(thread_checker_.CalledOnValidThread()); | 102 DCHECK(thread_checker_.CalledOnValidThread()); |
| 101 LeakDetector::GetInstance()->RemoveObserver(this); | 103 LeakDetector::GetInstance()->RemoveObserver(this); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void LeakDetectorController::OnLeaksFound( | 106 void LeakDetectorController::OnLeaksFound( |
| 105 const std::vector<MemoryLeakReportProto>& reports) { | 107 const std::vector<MemoryLeakReportProto>& reports) { |
| 106 DCHECK(thread_checker_.CalledOnValidThread()); | 108 DCHECK(thread_checker_.CalledOnValidThread()); |
| 107 | 109 |
| 108 for (const auto& report : reports) { | 110 for (const auto& report : reports) { |
| 109 // Store the report and insert stored parameters. | 111 // Store the report and insert stored parameters. |
| 110 stored_reports_.push_back(report); | 112 stored_reports_.push_back(report); |
| 111 stored_reports_.back().mutable_params()->CopyFrom(params_); | 113 stored_reports_.back().mutable_params()->CopyFrom(params_); |
| 112 } | 114 } |
| 113 } | 115 } |
| 114 | 116 |
| 115 void LeakDetectorController::GetLeakReports( | 117 void LeakDetectorController::GetLeakReports( |
| 116 std::vector<MemoryLeakReportProto>* reports) { | 118 std::vector<MemoryLeakReportProto>* reports) { |
| 117 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
| 118 *reports = std::move(stored_reports_); | 120 *reports = std::move(stored_reports_); |
| 119 } | 121 } |
| 120 | 122 |
| 121 } // namespace metrics | 123 } // namespace metrics |
| OLD | NEW |