| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 bool MetricsPrivateGetFieldTrialFunction::RunSync() { | 50 bool MetricsPrivateGetFieldTrialFunction::RunSync() { |
| 51 std::string name; | 51 std::string name; |
| 52 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); | 52 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); |
| 53 | 53 |
| 54 SetResult(new base::StringValue(base::FieldTrialList::FindFullName(name))); | 54 SetResult(new base::StringValue(base::FieldTrialList::FindFullName(name))); |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool MetricsPrivateGetVariationParamsFunction::RunSync() { | 58 bool MetricsPrivateGetVariationParamsFunction::RunSync() { |
| 59 scoped_ptr<GetVariationParams::Params> params( | 59 std::unique_ptr<GetVariationParams::Params> params( |
| 60 GetVariationParams::Params::Create(*args_)); | 60 GetVariationParams::Params::Create(*args_)); |
| 61 EXTENSION_FUNCTION_VALIDATE(params.get()); | 61 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 62 | 62 |
| 63 GetVariationParams::Results::Params result; | 63 GetVariationParams::Results::Params result; |
| 64 if (variations::GetVariationParams(params->name, | 64 if (variations::GetVariationParams(params->name, |
| 65 &result.additional_properties)) { | 65 &result.additional_properties)) { |
| 66 SetResult(result.ToValue().release()); | 66 SetResult(result.ToValue().release()); |
| 67 } | 67 } |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool MetricsPrivateRecordUserActionFunction::RunSync() { | 71 bool MetricsPrivateRecordUserActionFunction::RunSync() { |
| 72 scoped_ptr<RecordUserAction::Params> params( | 72 std::unique_ptr<RecordUserAction::Params> params( |
| 73 RecordUserAction::Params::Create(*args_)); | 73 RecordUserAction::Params::Create(*args_)); |
| 74 EXTENSION_FUNCTION_VALIDATE(params.get()); | 74 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 75 | 75 |
| 76 content::RecordComputedAction(params->name); | 76 content::RecordComputedAction(params->name); |
| 77 return true; | 77 return true; |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool MetricsHistogramHelperFunction::RecordValue( | 80 bool MetricsHistogramHelperFunction::RecordValue( |
| 81 const std::string& name, | 81 const std::string& name, |
| 82 base::HistogramType type, | 82 base::HistogramType type, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 // The histogram can be NULL if it is constructed with bad arguments. Ignore | 109 // The histogram can be NULL if it is constructed with bad arguments. Ignore |
| 110 // that data for this API. An error message will be logged. | 110 // that data for this API. An error message will be logged. |
| 111 if (counter) | 111 if (counter) |
| 112 counter->Add(sample); | 112 counter->Add(sample); |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool MetricsPrivateRecordValueFunction::RunSync() { | 116 bool MetricsPrivateRecordValueFunction::RunSync() { |
| 117 scoped_ptr<RecordValue::Params> params(RecordValue::Params::Create(*args_)); | 117 std::unique_ptr<RecordValue::Params> params( |
| 118 RecordValue::Params::Create(*args_)); |
| 118 EXTENSION_FUNCTION_VALIDATE(params.get()); | 119 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 119 | 120 |
| 120 // Get the histogram parameters from the metric type object. | 121 // Get the histogram parameters from the metric type object. |
| 121 std::string type = api::metrics_private::ToString(params->metric.type); | 122 std::string type = api::metrics_private::ToString(params->metric.type); |
| 122 | 123 |
| 123 base::HistogramType histogram_type(type == "histogram-linear" ? | 124 base::HistogramType histogram_type(type == "histogram-linear" ? |
| 124 base::LINEAR_HISTOGRAM : base::HISTOGRAM); | 125 base::LINEAR_HISTOGRAM : base::HISTOGRAM); |
| 125 return RecordValue(params->metric.metric_name, histogram_type, | 126 return RecordValue(params->metric.metric_name, histogram_type, |
| 126 params->metric.min, params->metric.max, | 127 params->metric.min, params->metric.max, |
| 127 params->metric.buckets, params->value); | 128 params->metric.buckets, params->value); |
| 128 } | 129 } |
| 129 | 130 |
| 130 bool MetricsPrivateRecordSparseValueFunction::RunSync() { | 131 bool MetricsPrivateRecordSparseValueFunction::RunSync() { |
| 131 scoped_ptr<RecordSparseValue::Params> params( | 132 std::unique_ptr<RecordSparseValue::Params> params( |
| 132 RecordSparseValue::Params::Create(*args_)); | 133 RecordSparseValue::Params::Create(*args_)); |
| 133 EXTENSION_FUNCTION_VALIDATE(params.get()); | 134 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 134 // This particular UMA_HISTOGRAM_ macro is okay for | 135 // This particular UMA_HISTOGRAM_ macro is okay for |
| 135 // non-runtime-constant strings. | 136 // non-runtime-constant strings. |
| 136 UMA_HISTOGRAM_SPARSE_SLOWLY(params->metric_name, params->value); | 137 UMA_HISTOGRAM_SPARSE_SLOWLY(params->metric_name, params->value); |
| 137 return true; | 138 return true; |
| 138 } | 139 } |
| 139 | 140 |
| 140 bool MetricsPrivateRecordPercentageFunction::RunSync() { | 141 bool MetricsPrivateRecordPercentageFunction::RunSync() { |
| 141 scoped_ptr<RecordPercentage::Params> params( | 142 std::unique_ptr<RecordPercentage::Params> params( |
| 142 RecordPercentage::Params::Create(*args_)); | 143 RecordPercentage::Params::Create(*args_)); |
| 143 EXTENSION_FUNCTION_VALIDATE(params.get()); | 144 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 144 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM, | 145 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM, |
| 145 1, 101, 102, params->value); | 146 1, 101, 102, params->value); |
| 146 } | 147 } |
| 147 | 148 |
| 148 bool MetricsPrivateRecordCountFunction::RunSync() { | 149 bool MetricsPrivateRecordCountFunction::RunSync() { |
| 149 scoped_ptr<RecordCount::Params> params(RecordCount::Params::Create(*args_)); | 150 std::unique_ptr<RecordCount::Params> params( |
| 151 RecordCount::Params::Create(*args_)); |
| 150 EXTENSION_FUNCTION_VALIDATE(params.get()); | 152 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 151 return RecordValue(params->metric_name, base::HISTOGRAM, | 153 return RecordValue(params->metric_name, base::HISTOGRAM, |
| 152 1, 1000000, 50, params->value); | 154 1, 1000000, 50, params->value); |
| 153 } | 155 } |
| 154 | 156 |
| 155 bool MetricsPrivateRecordSmallCountFunction::RunSync() { | 157 bool MetricsPrivateRecordSmallCountFunction::RunSync() { |
| 156 scoped_ptr<RecordSmallCount::Params> params( | 158 std::unique_ptr<RecordSmallCount::Params> params( |
| 157 RecordSmallCount::Params::Create(*args_)); | 159 RecordSmallCount::Params::Create(*args_)); |
| 158 EXTENSION_FUNCTION_VALIDATE(params.get()); | 160 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 159 return RecordValue(params->metric_name, base::HISTOGRAM, | 161 return RecordValue(params->metric_name, base::HISTOGRAM, |
| 160 1, 100, 50, params->value); | 162 1, 100, 50, params->value); |
| 161 } | 163 } |
| 162 | 164 |
| 163 bool MetricsPrivateRecordMediumCountFunction::RunSync() { | 165 bool MetricsPrivateRecordMediumCountFunction::RunSync() { |
| 164 scoped_ptr<RecordMediumCount::Params> params( | 166 std::unique_ptr<RecordMediumCount::Params> params( |
| 165 RecordMediumCount::Params::Create(*args_)); | 167 RecordMediumCount::Params::Create(*args_)); |
| 166 EXTENSION_FUNCTION_VALIDATE(params.get()); | 168 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 167 return RecordValue(params->metric_name, base::HISTOGRAM, | 169 return RecordValue(params->metric_name, base::HISTOGRAM, |
| 168 1, 10000, 50, params->value); | 170 1, 10000, 50, params->value); |
| 169 } | 171 } |
| 170 | 172 |
| 171 bool MetricsPrivateRecordTimeFunction::RunSync() { | 173 bool MetricsPrivateRecordTimeFunction::RunSync() { |
| 172 scoped_ptr<RecordTime::Params> params(RecordTime::Params::Create(*args_)); | 174 std::unique_ptr<RecordTime::Params> params( |
| 175 RecordTime::Params::Create(*args_)); |
| 173 EXTENSION_FUNCTION_VALIDATE(params.get()); | 176 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 174 static const int kTenSecMs = 10 * 1000; | 177 static const int kTenSecMs = 10 * 1000; |
| 175 return RecordValue(params->metric_name, base::HISTOGRAM, | 178 return RecordValue(params->metric_name, base::HISTOGRAM, |
| 176 1, kTenSecMs, 50, params->value); | 179 1, kTenSecMs, 50, params->value); |
| 177 } | 180 } |
| 178 | 181 |
| 179 bool MetricsPrivateRecordMediumTimeFunction::RunSync() { | 182 bool MetricsPrivateRecordMediumTimeFunction::RunSync() { |
| 180 scoped_ptr<RecordMediumTime::Params> params( | 183 std::unique_ptr<RecordMediumTime::Params> params( |
| 181 RecordMediumTime::Params::Create(*args_)); | 184 RecordMediumTime::Params::Create(*args_)); |
| 182 EXTENSION_FUNCTION_VALIDATE(params.get()); | 185 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 183 static const int kThreeMinMs = 3 * 60 * 1000; | 186 static const int kThreeMinMs = 3 * 60 * 1000; |
| 184 return RecordValue(params->metric_name, base::HISTOGRAM, | 187 return RecordValue(params->metric_name, base::HISTOGRAM, |
| 185 1, kThreeMinMs, 50, params->value); | 188 1, kThreeMinMs, 50, params->value); |
| 186 } | 189 } |
| 187 | 190 |
| 188 bool MetricsPrivateRecordLongTimeFunction::RunSync() { | 191 bool MetricsPrivateRecordLongTimeFunction::RunSync() { |
| 189 scoped_ptr<RecordLongTime::Params> params( | 192 std::unique_ptr<RecordLongTime::Params> params( |
| 190 RecordLongTime::Params::Create(*args_)); | 193 RecordLongTime::Params::Create(*args_)); |
| 191 EXTENSION_FUNCTION_VALIDATE(params.get()); | 194 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 192 static const int kOneHourMs = 60 * 60 * 1000; | 195 static const int kOneHourMs = 60 * 60 * 1000; |
| 193 return RecordValue(params->metric_name, base::HISTOGRAM, | 196 return RecordValue(params->metric_name, base::HISTOGRAM, |
| 194 1, kOneHourMs, 50, params->value); | 197 1, kOneHourMs, 50, params->value); |
| 195 } | 198 } |
| 196 | 199 |
| 197 } // namespace extensions | 200 } // namespace extensions |
| OLD | NEW |