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

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

Issue 141393002: Return a NULL histogram pointer on construction error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, git cl format 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
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (type == base::LINEAR_HISTOGRAM) { 132 if (type == base::LINEAR_HISTOGRAM) {
133 counter = base::LinearHistogram::FactoryGet( 133 counter = base::LinearHistogram::FactoryGet(
134 name, min, max, buckets, 134 name, min, max, buckets,
135 base::HistogramBase::kUmaTargetedHistogramFlag); 135 base::HistogramBase::kUmaTargetedHistogramFlag);
136 } else { 136 } else {
137 counter = base::Histogram::FactoryGet( 137 counter = base::Histogram::FactoryGet(
138 name, min, max, buckets, 138 name, min, max, buckets,
139 base::HistogramBase::kUmaTargetedHistogramFlag); 139 base::HistogramBase::kUmaTargetedHistogramFlag);
140 } 140 }
141 141
142 counter->Add(sample); 142 // The histogram can be NULL if it is constructed with bad arguments. Ignore
143 // that data for this API. An error message will be logged.
144 if (counter)
145 counter->Add(sample);
143 return true; 146 return true;
144 } 147 }
145 148
146 bool MetricsPrivateRecordValueFunction::RunImpl() { 149 bool MetricsPrivateRecordValueFunction::RunImpl() {
147 scoped_ptr<RecordValue::Params> params(RecordValue::Params::Create(*args_)); 150 scoped_ptr<RecordValue::Params> params(RecordValue::Params::Create(*args_));
148 EXTENSION_FUNCTION_VALIDATE(params.get()); 151 EXTENSION_FUNCTION_VALIDATE(params.get());
149 152
150 // Get the histogram parameters from the metric type object. 153 // Get the histogram parameters from the metric type object.
151 std::string type = api::metrics_private::MetricType::ToString( 154 std::string type = api::metrics_private::MetricType::ToString(
152 params->metric.type); 155 params->metric.type);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { 212 bool MetricsPrivateRecordLongTimeFunction::RunImpl() {
210 scoped_ptr<RecordLongTime::Params> params( 213 scoped_ptr<RecordLongTime::Params> params(
211 RecordLongTime::Params::Create(*args_)); 214 RecordLongTime::Params::Create(*args_));
212 EXTENSION_FUNCTION_VALIDATE(params.get()); 215 EXTENSION_FUNCTION_VALIDATE(params.get());
213 static const int kOneHourMs = 60 * 60 * 1000; 216 static const int kOneHourMs = 60 * 60 * 1000;
214 return RecordValue(params->metric_name, base::HISTOGRAM, 217 return RecordValue(params->metric_name, base::HISTOGRAM,
215 1, kOneHourMs, 50, params->value); 218 1, kOneHourMs, 50, params->value);
216 } 219 }
217 220
218 } // namespace extensions 221 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/metrics_private/metrics_apitest.cc ('k') | chrome/renderer/pepper/pepper_uma_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698