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

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

Issue 12461008: Modify metrics_private extensions api to use JSON Schema Compiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "chrome/common/extensions/api/metrics_private.h"
10 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
11 #include "content/public/browser/user_metrics.h" 12 #include "content/public/browser/user_metrics.h"
12 13
14 namespace RecordUserAction = extensions::api::metrics_private::RecordUserAction;
cduvall 2013/03/05 21:13:42 Move these into the namespace extensions block.
Aaron Jacobs 2013/03/05 22:28:36 Done.
15 namespace RecordValue = extensions::api::metrics_private::RecordValue;
16 namespace RecordPercentage = extensions::api::metrics_private::RecordPercentage;
17 namespace RecordCount = extensions::api::metrics_private::RecordCount;
18 namespace RecordSmallCount = extensions::api::metrics_private::RecordSmallCount;
19 namespace RecordMediumCount =
20 extensions::api::metrics_private::RecordMediumCount;
21 namespace RecordTime = extensions::api::metrics_private::RecordTime;
22 namespace RecordMediumTime = extensions::api::metrics_private::RecordMediumTime;
23 namespace RecordLongTime = extensions::api::metrics_private::RecordLongTime;
24
13 namespace extensions { 25 namespace extensions {
14 26
15 namespace { 27 namespace {
16 28
17 const size_t kMaxBuckets = 10000; // We don't ever want more than these many 29 const size_t kMaxBuckets = 10000; // We don't ever want more than these many
18 // buckets; there is no real need for them 30 // buckets; there is no real need for them
19 // and would cause crazy memory usage 31 // and would cause crazy memory usage
20 } // namespace 32 } // namespace
21 33
22 bool MetricsPrivateRecordUserActionFunction::RunImpl() { 34 bool MetricsPrivateRecordUserActionFunction::RunImpl() {
23 std::string name; 35 scoped_ptr<RecordUserAction::Params> params(
24 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); 36 RecordUserAction::Params::Create(*args_));
37 EXTENSION_FUNCTION_VALIDATE(params.get());
25 38
26 content::RecordComputedAction(name); 39 content::RecordComputedAction(params->name);
27 return true; 40 return true;
28 } 41 }
29 42
30 bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name, 43 bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name,
31 int* sample) { 44 int* sample) {
32 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, name)); 45 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, name));
33 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, sample)); 46 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, sample));
34 return true; 47 return true;
35 } 48 }
36 49
(...skipping 24 matching lines...) Expand all
61 counter = base::Histogram::FactoryGet( 74 counter = base::Histogram::FactoryGet(
62 name, min, max, buckets, 75 name, min, max, buckets,
63 base::HistogramBase::kUmaTargetedHistogramFlag); 76 base::HistogramBase::kUmaTargetedHistogramFlag);
64 } 77 }
65 78
66 counter->Add(sample); 79 counter->Add(sample);
67 return true; 80 return true;
68 } 81 }
69 82
70 bool MetricsPrivateRecordValueFunction::RunImpl() { 83 bool MetricsPrivateRecordValueFunction::RunImpl() {
71 int sample; 84 scoped_ptr<RecordValue::Params> params(RecordValue::Params::Create(*args_));
72 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &sample)); 85 EXTENSION_FUNCTION_VALIDATE(params.get());
73 86
74 // Get the histogram parameters from the metric type object. 87 // Get the histogram parameters from the metric type object.
75 DictionaryValue* metric_type; 88 std::string type = api::metrics_private::MetricType::ToString(
76 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &metric_type)); 89 params->metric.type);
77
78 std::string name;
79 std::string type;
80 int min;
81 int max;
82 int buckets;
83 EXTENSION_FUNCTION_VALIDATE(metric_type->GetString("metricName", &name));
84 EXTENSION_FUNCTION_VALIDATE(metric_type->GetString("type", &type));
85 EXTENSION_FUNCTION_VALIDATE(metric_type->GetInteger("min", &min));
86 EXTENSION_FUNCTION_VALIDATE(metric_type->GetInteger("max", &max));
87 EXTENSION_FUNCTION_VALIDATE(metric_type->GetInteger("buckets", &buckets));
88 90
89 base::HistogramType histogram_type(type == "histogram-linear" ? 91 base::HistogramType histogram_type(type == "histogram-linear" ?
90 base::LINEAR_HISTOGRAM : base::HISTOGRAM); 92 base::LINEAR_HISTOGRAM : base::HISTOGRAM);
91 return RecordValue(name, histogram_type, min, max, buckets, sample); 93 return RecordValue(params->metric.metric_name, histogram_type,
94 params->metric.min, params->metric.max,
95 params->metric.buckets, params->value);
92 } 96 }
93 97
94 bool MetricsPrivateRecordPercentageFunction::RunImpl() { 98 bool MetricsPrivateRecordPercentageFunction::RunImpl() {
95 std::string name; 99 scoped_ptr<RecordPercentage::Params> params(
96 int sample; 100 RecordPercentage::Params::Create(*args_));
97 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); 101 EXTENSION_FUNCTION_VALIDATE(params.get());
98 return RecordValue(name, base::LINEAR_HISTOGRAM, 1, 101, 102, sample); 102 return RecordValue(params->metric_name, base::LINEAR_HISTOGRAM,
103 1, 101, 102, params->value);
99 } 104 }
100 105
101 bool MetricsPrivateRecordCountFunction::RunImpl() { 106 bool MetricsPrivateRecordCountFunction::RunImpl() {
102 std::string name; 107 scoped_ptr<RecordCount::Params> params(RecordCount::Params::Create(*args_));
103 int sample; 108 EXTENSION_FUNCTION_VALIDATE(params.get());
104 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); 109 return RecordValue(params->metric_name, base::HISTOGRAM,
105 return RecordValue(name, base::HISTOGRAM, 1, 1000000, 50, sample); 110 1, 1000000, 50, params->value);
106 } 111 }
107 112
108 bool MetricsPrivateRecordSmallCountFunction::RunImpl() { 113 bool MetricsPrivateRecordSmallCountFunction::RunImpl() {
109 std::string name; 114 scoped_ptr<RecordSmallCount::Params> params(
110 int sample; 115 RecordSmallCount::Params::Create(*args_));
111 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); 116 EXTENSION_FUNCTION_VALIDATE(params.get());
112 return RecordValue(name, base::HISTOGRAM, 1, 100, 50, sample); 117 return RecordValue(params->metric_name, base::HISTOGRAM,
118 1, 100, 50, params->value);
113 } 119 }
114 120
115 bool MetricsPrivateRecordMediumCountFunction::RunImpl() { 121 bool MetricsPrivateRecordMediumCountFunction::RunImpl() {
116 std::string name; 122 scoped_ptr<RecordMediumCount::Params> params(
117 int sample; 123 RecordMediumCount::Params::Create(*args_));
118 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); 124 EXTENSION_FUNCTION_VALIDATE(params.get());
119 return RecordValue(name, base::HISTOGRAM, 1, 10000, 50, sample); 125 return RecordValue(params->metric_name, base::HISTOGRAM,
126 1, 10000, 50, params->value);
120 } 127 }
121 128
122 bool MetricsPrivateRecordTimeFunction::RunImpl() { 129 bool MetricsPrivateRecordTimeFunction::RunImpl() {
123 std::string name; 130 scoped_ptr<RecordTime::Params> params(RecordTime::Params::Create(*args_));
124 int sample; 131 EXTENSION_FUNCTION_VALIDATE(params.get());
125 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample));
126 static const int kTenSecMs = 10 * 1000; 132 static const int kTenSecMs = 10 * 1000;
127 return RecordValue(name, base::HISTOGRAM, 1, kTenSecMs, 50, sample); 133 return RecordValue(params->metric_name, base::HISTOGRAM,
134 1, kTenSecMs, 50, params->value);
128 } 135 }
129 136
130 bool MetricsPrivateRecordMediumTimeFunction::RunImpl() { 137 bool MetricsPrivateRecordMediumTimeFunction::RunImpl() {
131 std::string name; 138 scoped_ptr<RecordMediumTime::Params> params(
132 int sample; 139 RecordMediumTime::Params::Create(*args_));
133 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); 140 EXTENSION_FUNCTION_VALIDATE(params.get());
134 static const int kThreeMinMs = 3 * 60 * 1000; 141 static const int kThreeMinMs = 3 * 60 * 1000;
135 return RecordValue(name, base::HISTOGRAM, 1, kThreeMinMs, 50, sample); 142 return RecordValue(params->metric_name, base::HISTOGRAM,
143 1, kThreeMinMs, 50, params->value);
136 } 144 }
137 145
138 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { 146 bool MetricsPrivateRecordLongTimeFunction::RunImpl() {
139 std::string name; 147 scoped_ptr<RecordLongTime::Params> params(
140 int sample; 148 RecordLongTime::Params::Create(*args_));
141 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); 149 EXTENSION_FUNCTION_VALIDATE(params.get());
142 static const int kOneHourMs = 60 * 60 * 1000; 150 static const int kOneHourMs = 60 * 60 * 1000;
143 return RecordValue(name, base::HISTOGRAM, 1, kOneHourMs, 50, sample); 151 return RecordValue(params->metric_name, base::HISTOGRAM,
152 1, kOneHourMs, 50, params->value);
144 } 153 }
145 154
146 } // namespace extensions 155 } // namespace extensions
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698