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

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

Issue 252653002: Rename (Chrome)SyncExtensionFunction::RunImpl to RunSync so that the RunImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bookmarks Created 6 years, 7 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"
(...skipping 21 matching lines...) Expand all
32 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; 32 namespace RecordMediumTime = api::metrics_private::RecordMediumTime;
33 namespace RecordLongTime = api::metrics_private::RecordLongTime; 33 namespace RecordLongTime = api::metrics_private::RecordLongTime;
34 34
35 namespace { 35 namespace {
36 36
37 const size_t kMaxBuckets = 10000; // We don't ever want more than these many 37 const size_t kMaxBuckets = 10000; // We don't ever want more than these many
38 // buckets; there is no real need for them 38 // buckets; there is no real need for them
39 // and would cause crazy memory usage 39 // and would cause crazy memory usage
40 } // namespace 40 } // namespace
41 41
42 bool MetricsPrivateGetIsCrashReportingEnabledFunction::RunImpl() { 42 bool MetricsPrivateGetIsCrashReportingEnabledFunction::RunSync() {
43 SetResult(new base::FundamentalValue( 43 SetResult(new base::FundamentalValue(
44 MetricsServiceHelper::IsCrashReportingEnabled())); 44 MetricsServiceHelper::IsCrashReportingEnabled()));
45 return true; 45 return true;
46 } 46 }
47 47
48 bool MetricsPrivateGetFieldTrialFunction::RunImpl() { 48 bool MetricsPrivateGetFieldTrialFunction::RunSync() {
49 std::string name; 49 std::string name;
50 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); 50 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name));
51 51
52 SetResult(new base::StringValue(base::FieldTrialList::FindFullName(name))); 52 SetResult(new base::StringValue(base::FieldTrialList::FindFullName(name)));
53 return true; 53 return true;
54 } 54 }
55 55
56 bool MetricsPrivateGetVariationParamsFunction::RunImpl() { 56 bool MetricsPrivateGetVariationParamsFunction::RunSync() {
57 scoped_ptr<GetVariationParams::Params> params( 57 scoped_ptr<GetVariationParams::Params> params(
58 GetVariationParams::Params::Create(*args_)); 58 GetVariationParams::Params::Create(*args_));
59 EXTENSION_FUNCTION_VALIDATE(params.get()); 59 EXTENSION_FUNCTION_VALIDATE(params.get());
60 60
61 GetVariationParams::Results::Params result; 61 GetVariationParams::Results::Params result;
62 if (!chrome_variations::GetVariationParams( 62 if (!chrome_variations::GetVariationParams(
63 params->name, &result.additional_properties)) { 63 params->name, &result.additional_properties)) {
64 SetError("Variation parameters are unavailable."); 64 SetError("Variation parameters are unavailable.");
65 return false; 65 return false;
66 } 66 }
67 67
68 SetResult(result.ToValue().release()); 68 SetResult(result.ToValue().release());
69 return true; 69 return true;
70 } 70 }
71 71
72 bool MetricsPrivateRecordUserActionFunction::RunImpl() { 72 bool MetricsPrivateRecordUserActionFunction::RunSync() {
73 scoped_ptr<RecordUserAction::Params> params( 73 scoped_ptr<RecordUserAction::Params> params(
74 RecordUserAction::Params::Create(*args_)); 74 RecordUserAction::Params::Create(*args_));
75 EXTENSION_FUNCTION_VALIDATE(params.get()); 75 EXTENSION_FUNCTION_VALIDATE(params.get());
76 76
77 content::RecordComputedAction(params->name); 77 content::RecordComputedAction(params->name);
78 return true; 78 return true;
79 } 79 }
80 80
81 bool MetricsHistogramHelperFunction::RecordValue( 81 bool MetricsHistogramHelperFunction::RecordValue(
82 const std::string& name, 82 const std::string& name,
(...skipping 24 matching lines...) Expand all
107 base::HistogramBase::kUmaTargetedHistogramFlag); 107 base::HistogramBase::kUmaTargetedHistogramFlag);
108 } 108 }
109 109
110 // The histogram can be NULL if it is constructed with bad arguments. Ignore 110 // The histogram can be NULL if it is constructed with bad arguments. Ignore
111 // that data for this API. An error message will be logged. 111 // that data for this API. An error message will be logged.
112 if (counter) 112 if (counter)
113 counter->Add(sample); 113 counter->Add(sample);
114 return true; 114 return true;
115 } 115 }
116 116
117 bool MetricsPrivateRecordValueFunction::RunImpl() { 117 bool MetricsPrivateRecordValueFunction::RunSync() {
118 scoped_ptr<RecordValue::Params> params(RecordValue::Params::Create(*args_)); 118 scoped_ptr<RecordValue::Params> params(RecordValue::Params::Create(*args_));
119 EXTENSION_FUNCTION_VALIDATE(params.get()); 119 EXTENSION_FUNCTION_VALIDATE(params.get());
120 120
121 // Get the histogram parameters from the metric type object. 121 // Get the histogram parameters from the metric type object.
122 std::string type = api::metrics_private::MetricType::ToString( 122 std::string type = api::metrics_private::MetricType::ToString(
123 params->metric.type); 123 params->metric.type);
124 124
125 base::HistogramType histogram_type(type == "histogram-linear" ? 125 base::HistogramType histogram_type(type == "histogram-linear" ?
126 base::LINEAR_HISTOGRAM : base::HISTOGRAM); 126 base::LINEAR_HISTOGRAM : base::HISTOGRAM);
127 return RecordValue(params->metric.metric_name, histogram_type, 127 return RecordValue(params->metric.metric_name, histogram_type,
128 params->metric.min, params->metric.max, 128 params->metric.min, params->metric.max,
129 params->metric.buckets, params->value); 129 params->metric.buckets, params->value);
130 } 130 }
131 131
132 bool MetricsPrivateRecordSparseValueFunction::RunImpl() { 132 bool MetricsPrivateRecordSparseValueFunction::RunSync() {
133 scoped_ptr<RecordSparseValue::Params> params( 133 scoped_ptr<RecordSparseValue::Params> params(
134 RecordSparseValue::Params::Create(*args_)); 134 RecordSparseValue::Params::Create(*args_));
135 EXTENSION_FUNCTION_VALIDATE(params.get()); 135 EXTENSION_FUNCTION_VALIDATE(params.get());
136 // This particular UMA_HISTOGRAM_ macro is okay for 136 // This particular UMA_HISTOGRAM_ macro is okay for
137 // non-runtime-constant strings. 137 // non-runtime-constant strings.
138 UMA_HISTOGRAM_SPARSE_SLOWLY(params->metric_name, params->value); 138 UMA_HISTOGRAM_SPARSE_SLOWLY(params->metric_name, params->value);
139 return true; 139 return true;
140 } 140 }
141 141
142 bool MetricsPrivateRecordPercentageFunction::RunImpl() { 142 bool MetricsPrivateRecordPercentageFunction::RunSync() {
143 scoped_ptr<RecordPercentage::Params> params( 143 scoped_ptr<RecordPercentage::Params> params(
144 RecordPercentage::Params::Create(*args_)); 144 RecordPercentage::Params::Create(*args_));
145 EXTENSION_FUNCTION_VALIDATE(params.get()); 145 EXTENSION_FUNCTION_VALIDATE(params.get());
146 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM, 146 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM,
147 1, 101, 102, params->value); 147 1, 101, 102, params->value);
148 } 148 }
149 149
150 bool MetricsPrivateRecordCountFunction::RunImpl() { 150 bool MetricsPrivateRecordCountFunction::RunSync() {
151 scoped_ptr<RecordCount::Params> params(RecordCount::Params::Create(*args_)); 151 scoped_ptr<RecordCount::Params> params(RecordCount::Params::Create(*args_));
152 EXTENSION_FUNCTION_VALIDATE(params.get()); 152 EXTENSION_FUNCTION_VALIDATE(params.get());
153 return RecordValue(params->metric_name, base::HISTOGRAM, 153 return RecordValue(params->metric_name, base::HISTOGRAM,
154 1, 1000000, 50, params->value); 154 1, 1000000, 50, params->value);
155 } 155 }
156 156
157 bool MetricsPrivateRecordSmallCountFunction::RunImpl() { 157 bool MetricsPrivateRecordSmallCountFunction::RunSync() {
158 scoped_ptr<RecordSmallCount::Params> params( 158 scoped_ptr<RecordSmallCount::Params> params(
159 RecordSmallCount::Params::Create(*args_)); 159 RecordSmallCount::Params::Create(*args_));
160 EXTENSION_FUNCTION_VALIDATE(params.get()); 160 EXTENSION_FUNCTION_VALIDATE(params.get());
161 return RecordValue(params->metric_name, base::HISTOGRAM, 161 return RecordValue(params->metric_name, base::HISTOGRAM,
162 1, 100, 50, params->value); 162 1, 100, 50, params->value);
163 } 163 }
164 164
165 bool MetricsPrivateRecordMediumCountFunction::RunImpl() { 165 bool MetricsPrivateRecordMediumCountFunction::RunSync() {
166 scoped_ptr<RecordMediumCount::Params> params( 166 scoped_ptr<RecordMediumCount::Params> params(
167 RecordMediumCount::Params::Create(*args_)); 167 RecordMediumCount::Params::Create(*args_));
168 EXTENSION_FUNCTION_VALIDATE(params.get()); 168 EXTENSION_FUNCTION_VALIDATE(params.get());
169 return RecordValue(params->metric_name, base::HISTOGRAM, 169 return RecordValue(params->metric_name, base::HISTOGRAM,
170 1, 10000, 50, params->value); 170 1, 10000, 50, params->value);
171 } 171 }
172 172
173 bool MetricsPrivateRecordTimeFunction::RunImpl() { 173 bool MetricsPrivateRecordTimeFunction::RunSync() {
174 scoped_ptr<RecordTime::Params> params(RecordTime::Params::Create(*args_)); 174 scoped_ptr<RecordTime::Params> params(RecordTime::Params::Create(*args_));
175 EXTENSION_FUNCTION_VALIDATE(params.get()); 175 EXTENSION_FUNCTION_VALIDATE(params.get());
176 static const int kTenSecMs = 10 * 1000; 176 static const int kTenSecMs = 10 * 1000;
177 return RecordValue(params->metric_name, base::HISTOGRAM, 177 return RecordValue(params->metric_name, base::HISTOGRAM,
178 1, kTenSecMs, 50, params->value); 178 1, kTenSecMs, 50, params->value);
179 } 179 }
180 180
181 bool MetricsPrivateRecordMediumTimeFunction::RunImpl() { 181 bool MetricsPrivateRecordMediumTimeFunction::RunSync() {
182 scoped_ptr<RecordMediumTime::Params> params( 182 scoped_ptr<RecordMediumTime::Params> params(
183 RecordMediumTime::Params::Create(*args_)); 183 RecordMediumTime::Params::Create(*args_));
184 EXTENSION_FUNCTION_VALIDATE(params.get()); 184 EXTENSION_FUNCTION_VALIDATE(params.get());
185 static const int kThreeMinMs = 3 * 60 * 1000; 185 static const int kThreeMinMs = 3 * 60 * 1000;
186 return RecordValue(params->metric_name, base::HISTOGRAM, 186 return RecordValue(params->metric_name, base::HISTOGRAM,
187 1, kThreeMinMs, 50, params->value); 187 1, kThreeMinMs, 50, params->value);
188 } 188 }
189 189
190 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { 190 bool MetricsPrivateRecordLongTimeFunction::RunSync() {
191 scoped_ptr<RecordLongTime::Params> params( 191 scoped_ptr<RecordLongTime::Params> params(
192 RecordLongTime::Params::Create(*args_)); 192 RecordLongTime::Params::Create(*args_));
193 EXTENSION_FUNCTION_VALIDATE(params.get()); 193 EXTENSION_FUNCTION_VALIDATE(params.get());
194 static const int kOneHourMs = 60 * 60 * 1000; 194 static const int kOneHourMs = 60 * 60 * 1000;
195 return RecordValue(params->metric_name, base::HISTOGRAM, 195 return RecordValue(params->metric_name, base::HISTOGRAM,
196 1, kOneHourMs, 50, params->value); 196 1, kOneHourMs, 50, params->value);
197 } 197 }
198 198
199 } // namespace extensions 199 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/metrics_private/metrics_private_api.h ('k') | chrome/browser/extensions/api/module/module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698