Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: chrome/browser/extensions/api/metrics_private/metrics_private_api.cc

Issue 213433003: Add Sparse Histogram Support to metricsPrivate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR Feedback Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_* is okay for runtime strings.
Ilya Sherman 2014/03/26 23:52:13 nit: "runtime strings" -> "non-runtime-constant st
Ilya Sherman 2014/03/26 23:52:13 nit: "UMA_HISTOGRAM_*" -> "UMA_HISTOGRAM_ macro"
robliao 2014/03/27 00:02:44 Done.
137 UMA_HISTOGRAM_SPARSE_SLOWLY(params->metric_name, params->value);
138 return true;
139 }
140
130 bool MetricsPrivateRecordPercentageFunction::RunImpl() { 141 bool MetricsPrivateRecordPercentageFunction::RunImpl() {
131 scoped_ptr<RecordPercentage::Params> params( 142 scoped_ptr<RecordPercentage::Params> params(
132 RecordPercentage::Params::Create(*args_)); 143 RecordPercentage::Params::Create(*args_));
133 EXTENSION_FUNCTION_VALIDATE(params.get()); 144 EXTENSION_FUNCTION_VALIDATE(params.get());
134 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM, 145 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM,
135 1, 101, 102, params->value); 146 1, 101, 102, params->value);
136 } 147 }
137 148
138 bool MetricsPrivateRecordCountFunction::RunImpl() { 149 bool MetricsPrivateRecordCountFunction::RunImpl() {
139 scoped_ptr<RecordCount::Params> params(RecordCount::Params::Create(*args_)); 150 scoped_ptr<RecordCount::Params> params(RecordCount::Params::Create(*args_));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { 189 bool MetricsPrivateRecordLongTimeFunction::RunImpl() {
179 scoped_ptr<RecordLongTime::Params> params( 190 scoped_ptr<RecordLongTime::Params> params(
180 RecordLongTime::Params::Create(*args_)); 191 RecordLongTime::Params::Create(*args_));
181 EXTENSION_FUNCTION_VALIDATE(params.get()); 192 EXTENSION_FUNCTION_VALIDATE(params.get());
182 static const int kOneHourMs = 60 * 60 * 1000; 193 static const int kOneHourMs = 60 * 60 * 1000;
183 return RecordValue(params->metric_name, base::HISTOGRAM, 194 return RecordValue(params->metric_name, base::HISTOGRAM,
184 1, kOneHourMs, 50, params->value); 195 1, kOneHourMs, 50, params->value);
185 } 196 }
186 197
187 } // namespace extensions 198 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698