OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/pepper/pepper_uma_host.h" | 5 #include "chrome/renderer/pepper/pepper_uma_host.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 105 } |
106 RETURN_IF_BAD_ARGS(min, max, bucket_count); | 106 RETURN_IF_BAD_ARGS(min, max, bucket_count); |
107 | 107 |
108 base::HistogramBase* counter = | 108 base::HistogramBase* counter = |
109 base::Histogram::FactoryTimeGet( | 109 base::Histogram::FactoryTimeGet( |
110 name, | 110 name, |
111 base::TimeDelta::FromMilliseconds(min), | 111 base::TimeDelta::FromMilliseconds(min), |
112 base::TimeDelta::FromMilliseconds(max), | 112 base::TimeDelta::FromMilliseconds(max), |
113 bucket_count, | 113 bucket_count, |
114 base::HistogramBase::kUmaTargetedHistogramFlag); | 114 base::HistogramBase::kUmaTargetedHistogramFlag); |
115 counter->AddTime(base::TimeDelta::FromMilliseconds(sample)); | 115 // The histogram can be NULL if it is constructed with bad arguments. Ignore |
| 116 // that data for this API. An error message will be logged. |
| 117 if (counter) |
| 118 counter->AddTime(base::TimeDelta::FromMilliseconds(sample)); |
116 return PP_OK; | 119 return PP_OK; |
117 } | 120 } |
118 | 121 |
119 int32_t PepperUMAHost::OnHistogramCustomCounts( | 122 int32_t PepperUMAHost::OnHistogramCustomCounts( |
120 ppapi::host::HostMessageContext* context, | 123 ppapi::host::HostMessageContext* context, |
121 const std::string& name, | 124 const std::string& name, |
122 int32_t sample, | 125 int32_t sample, |
123 int32_t min, | 126 int32_t min, |
124 int32_t max, | 127 int32_t max, |
125 uint32_t bucket_count) { | 128 uint32_t bucket_count) { |
126 if (!IsHistogramAllowed(name)) { | 129 if (!IsHistogramAllowed(name)) { |
127 return PP_ERROR_NOACCESS; | 130 return PP_ERROR_NOACCESS; |
128 } | 131 } |
129 RETURN_IF_BAD_ARGS(min, max, bucket_count); | 132 RETURN_IF_BAD_ARGS(min, max, bucket_count); |
130 | 133 |
131 base::HistogramBase* counter = | 134 base::HistogramBase* counter = |
132 base::Histogram::FactoryGet( | 135 base::Histogram::FactoryGet( |
133 name, | 136 name, |
134 min, | 137 min, |
135 max, | 138 max, |
136 bucket_count, | 139 bucket_count, |
137 base::HistogramBase::kUmaTargetedHistogramFlag); | 140 base::HistogramBase::kUmaTargetedHistogramFlag); |
138 counter->Add(sample); | 141 // The histogram can be NULL if it is constructed with bad arguments. Ignore |
| 142 // that data for this API. An error message will be logged. |
| 143 if (counter) |
| 144 counter->Add(sample); |
139 return PP_OK; | 145 return PP_OK; |
140 } | 146 } |
141 | 147 |
142 int32_t PepperUMAHost::OnHistogramEnumeration( | 148 int32_t PepperUMAHost::OnHistogramEnumeration( |
143 ppapi::host::HostMessageContext* context, | 149 ppapi::host::HostMessageContext* context, |
144 const std::string& name, | 150 const std::string& name, |
145 int32_t sample, | 151 int32_t sample, |
146 int32_t boundary_value) { | 152 int32_t boundary_value) { |
147 if (!IsHistogramAllowed(name)) { | 153 if (!IsHistogramAllowed(name)) { |
148 return PP_ERROR_NOACCESS; | 154 return PP_ERROR_NOACCESS; |
149 } | 155 } |
150 RETURN_IF_BAD_ARGS(0, boundary_value, boundary_value + 1); | 156 RETURN_IF_BAD_ARGS(0, boundary_value, boundary_value + 1); |
151 | 157 |
152 base::HistogramBase* counter = | 158 base::HistogramBase* counter = |
153 base::LinearHistogram::FactoryGet( | 159 base::LinearHistogram::FactoryGet( |
154 name, | 160 name, |
155 1, | 161 1, |
156 boundary_value, | 162 boundary_value, |
157 boundary_value + 1, | 163 boundary_value + 1, |
158 base::HistogramBase::kUmaTargetedHistogramFlag); | 164 base::HistogramBase::kUmaTargetedHistogramFlag); |
159 counter->Add(sample); | 165 // The histogram can be NULL if it is constructed with bad arguments. Ignore |
| 166 // that data for this API. An error message will be logged. |
| 167 if (counter) |
| 168 counter->Add(sample); |
160 return PP_OK; | 169 return PP_OK; |
161 } | 170 } |
162 | 171 |
OLD | NEW |