| 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/extensions/api/metrics_private/metrics_private_api.h" | 5 #include "chrome/browser/extensions/api/metrics_private/metrics_private_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/sparse_histogram.h" |
| 11 #include "chrome/browser/metrics/metrics_service.h" | 12 #include "chrome/browser/metrics/metrics_service.h" |
| 12 #include "chrome/common/extensions/api/metrics_private.h" | 13 #include "chrome/common/extensions/api/metrics_private.h" |
| 13 #include "components/variations/variations_associated_data.h" | 14 #include "components/variations/variations_associated_data.h" |
| 14 #include "content/public/browser/user_metrics.h" | 15 #include "content/public/browser/user_metrics.h" |
| 15 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 namespace GetIsCrashReportingEnabled = | 20 namespace GetIsCrashReportingEnabled = |
| 20 api::metrics_private::GetIsCrashReportingEnabled; | 21 api::metrics_private::GetIsCrashReportingEnabled; |
| 21 namespace GetVariationParams = api::metrics_private::GetVariationParams; | 22 namespace GetVariationParams = api::metrics_private::GetVariationParams; |
| 22 namespace GetFieldTrial = api::metrics_private::GetFieldTrial; | 23 namespace GetFieldTrial = api::metrics_private::GetFieldTrial; |
| 23 namespace RecordUserAction = api::metrics_private::RecordUserAction; | 24 namespace RecordUserAction = api::metrics_private::RecordUserAction; |
| 24 namespace RecordValue = api::metrics_private::RecordValue; | 25 namespace RecordValue = api::metrics_private::RecordValue; |
| 26 namespace RecordSparseValue = api::metrics_private::RecordSparseValue; |
| 25 namespace RecordPercentage = api::metrics_private::RecordPercentage; | 27 namespace RecordPercentage = api::metrics_private::RecordPercentage; |
| 26 namespace RecordCount = api::metrics_private::RecordCount; | 28 namespace RecordCount = api::metrics_private::RecordCount; |
| 27 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; | 29 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; |
| 28 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; | 30 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; |
| 29 namespace RecordTime = api::metrics_private::RecordTime; | 31 namespace RecordTime = api::metrics_private::RecordTime; |
| 30 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; | 32 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; |
| 31 namespace RecordLongTime = api::metrics_private::RecordLongTime; | 33 namespace RecordLongTime = api::metrics_private::RecordLongTime; |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 std::string type = api::metrics_private::MetricType::ToString( | 122 std::string type = api::metrics_private::MetricType::ToString( |
| 121 params->metric.type); | 123 params->metric.type); |
| 122 | 124 |
| 123 base::HistogramType histogram_type(type == "histogram-linear" ? | 125 base::HistogramType histogram_type(type == "histogram-linear" ? |
| 124 base::LINEAR_HISTOGRAM : base::HISTOGRAM); | 126 base::LINEAR_HISTOGRAM : base::HISTOGRAM); |
| 125 return RecordValue(params->metric.metric_name, histogram_type, | 127 return RecordValue(params->metric.metric_name, histogram_type, |
| 126 params->metric.min, params->metric.max, | 128 params->metric.min, params->metric.max, |
| 127 params->metric.buckets, params->value); | 129 params->metric.buckets, params->value); |
| 128 } | 130 } |
| 129 | 131 |
| 132 bool MetricsPrivateRecordSparseValueFunction::RunImpl() { |
| 133 scoped_ptr<RecordSparseValue::Params> params( |
| 134 RecordSparseValue::Params::Create(*args_)); |
| 135 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 136 // This particular UMA_HISTOGRAM_ macro is okay for |
| 137 // non-runtime-constant strings. |
| 138 UMA_HISTOGRAM_SPARSE_SLOWLY(params->metric_name, params->value); |
| 139 return true; |
| 140 } |
| 141 |
| 130 bool MetricsPrivateRecordPercentageFunction::RunImpl() { | 142 bool MetricsPrivateRecordPercentageFunction::RunImpl() { |
| 131 scoped_ptr<RecordPercentage::Params> params( | 143 scoped_ptr<RecordPercentage::Params> params( |
| 132 RecordPercentage::Params::Create(*args_)); | 144 RecordPercentage::Params::Create(*args_)); |
| 133 EXTENSION_FUNCTION_VALIDATE(params.get()); | 145 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 134 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM, | 146 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM, |
| 135 1, 101, 102, params->value); | 147 1, 101, 102, params->value); |
| 136 } | 148 } |
| 137 | 149 |
| 138 bool MetricsPrivateRecordCountFunction::RunImpl() { | 150 bool MetricsPrivateRecordCountFunction::RunImpl() { |
| 139 scoped_ptr<RecordCount::Params> params(RecordCount::Params::Create(*args_)); | 151 scoped_ptr<RecordCount::Params> params(RecordCount::Params::Create(*args_)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { | 190 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { |
| 179 scoped_ptr<RecordLongTime::Params> params( | 191 scoped_ptr<RecordLongTime::Params> params( |
| 180 RecordLongTime::Params::Create(*args_)); | 192 RecordLongTime::Params::Create(*args_)); |
| 181 EXTENSION_FUNCTION_VALIDATE(params.get()); | 193 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 182 static const int kOneHourMs = 60 * 60 * 1000; | 194 static const int kOneHourMs = 60 * 60 * 1000; |
| 183 return RecordValue(params->metric_name, base::HISTOGRAM, | 195 return RecordValue(params->metric_name, base::HISTOGRAM, |
| 184 1, kOneHourMs, 50, params->value); | 196 1, kOneHourMs, 50, params->value); |
| 185 } | 197 } |
| 186 | 198 |
| 187 } // namespace extensions | 199 } // namespace extensions |
| OLD | NEW |