| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/external_metrics.h" | 5 #include "chrome/browser/chromeos/external_metrics.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/bind.h" | 14 #include "base/bind.h" |
| 13 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/metrics/statistics_recorder.h" | 17 #include "base/metrics/statistics_recorder.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/metrics/chromeos_metrics_provider.h" | 20 #include "chrome/browser/metrics/chromeos_metrics_provider.h" |
| 19 #include "components/metrics/metrics_service.h" | 21 #include "components/metrics/metrics_service.h" |
| 20 #include "components/metrics/serialization/metric_sample.h" | 22 #include "components/metrics/serialization/metric_sample.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 128 |
| 127 void ExternalMetrics::RecordSparseHistogram( | 129 void ExternalMetrics::RecordSparseHistogram( |
| 128 const metrics::MetricSample& sample) { | 130 const metrics::MetricSample& sample) { |
| 129 CHECK_EQ(metrics::MetricSample::SPARSE_HISTOGRAM, sample.type()); | 131 CHECK_EQ(metrics::MetricSample::SPARSE_HISTOGRAM, sample.type()); |
| 130 base::HistogramBase* counter = base::SparseHistogram::FactoryGet( | 132 base::HistogramBase* counter = base::SparseHistogram::FactoryGet( |
| 131 sample.name(), base::HistogramBase::kUmaTargetedHistogramFlag); | 133 sample.name(), base::HistogramBase::kUmaTargetedHistogramFlag); |
| 132 counter->Add(sample.sample()); | 134 counter->Add(sample.sample()); |
| 133 } | 135 } |
| 134 | 136 |
| 135 int ExternalMetrics::CollectEvents() { | 137 int ExternalMetrics::CollectEvents() { |
| 136 ScopedVector<metrics::MetricSample> samples; | 138 std::vector<std::unique_ptr<metrics::MetricSample>> samples; |
| 137 metrics::SerializationUtils::ReadAndTruncateMetricsFromFile(uma_events_file_, | 139 metrics::SerializationUtils::ReadAndTruncateMetricsFromFile(uma_events_file_, |
| 138 &samples); | 140 &samples); |
| 139 | 141 |
| 140 for (ScopedVector<metrics::MetricSample>::iterator it = samples.begin(); | 142 for (auto it = samples.begin(); it != samples.end(); ++it) { |
| 141 it != samples.end(); | |
| 142 ++it) { | |
| 143 const metrics::MetricSample& sample = **it; | 143 const metrics::MetricSample& sample = **it; |
| 144 | 144 |
| 145 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram | 145 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram |
| 146 // instance and thus only work if |sample.name()| is constant. | 146 // instance and thus only work if |sample.name()| is constant. |
| 147 switch (sample.type()) { | 147 switch (sample.type()) { |
| 148 case metrics::MetricSample::CRASH: | 148 case metrics::MetricSample::CRASH: |
| 149 RecordCrash(sample.name()); | 149 RecordCrash(sample.name()); |
| 150 break; | 150 break; |
| 151 case metrics::MetricSample::USER_ACTION: | 151 case metrics::MetricSample::USER_ACTION: |
| 152 RecordAction(sample.name()); | 152 RecordAction(sample.name()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 173 | 173 |
| 174 void ExternalMetrics::ScheduleCollector() { | 174 void ExternalMetrics::ScheduleCollector() { |
| 175 bool result = BrowserThread::GetBlockingPool()->PostDelayedWorkerTask( | 175 bool result = BrowserThread::GetBlockingPool()->PostDelayedWorkerTask( |
| 176 FROM_HERE, | 176 FROM_HERE, |
| 177 base::Bind(&chromeos::ExternalMetrics::CollectEventsAndReschedule, this), | 177 base::Bind(&chromeos::ExternalMetrics::CollectEventsAndReschedule, this), |
| 178 base::TimeDelta::FromSeconds(kExternalMetricsCollectionIntervalSeconds)); | 178 base::TimeDelta::FromSeconds(kExternalMetricsCollectionIntervalSeconds)); |
| 179 DCHECK(result); | 179 DCHECK(result); |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace chromeos | 182 } // namespace chromeos |
| OLD | NEW |