| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/pepper/ppb_uma_private_impl.h" | |
| 6 | |
| 7 #include "base/metrics/histogram.h" | |
| 8 #include "ppapi/c/pp_var.h" | |
| 9 #include "ppapi/c/private/ppb_uma_private.h" | |
| 10 #include "ppapi/shared_impl/var.h" | |
| 11 | |
| 12 using ppapi::StringVar; | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 #define RETURN_IF_BAD_ARGS(_name, _sample, _min, _max, _bucket_count) \ | |
| 19 do { \ | |
| 20 if (_name.type != PP_VARTYPE_STRING || _name.value.as_id == 0) \ | |
| 21 return; \ | |
| 22 if (_min >= _max) \ | |
| 23 return; \ | |
| 24 if (_bucket_count <= 1) \ | |
| 25 return; \ | |
| 26 } while (0) | |
| 27 | |
| 28 void HistogramCustomTimes(PP_Var name, | |
| 29 int64_t sample, | |
| 30 int64_t min, int64_t max, | |
| 31 uint32_t bucket_count) { | |
| 32 RETURN_IF_BAD_ARGS(name, sample, min, max, bucket_count); | |
| 33 | |
| 34 StringVar* name_string = StringVar::FromPPVar(name); | |
| 35 if (name_string == NULL) | |
| 36 return; | |
| 37 base::HistogramBase* counter = | |
| 38 base::Histogram::FactoryTimeGet( | |
| 39 name_string->value(), | |
| 40 base::TimeDelta::FromMilliseconds(min), | |
| 41 base::TimeDelta::FromMilliseconds(max), | |
| 42 bucket_count, | |
| 43 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 44 counter->AddTime(base::TimeDelta::FromMilliseconds(sample)); | |
| 45 } | |
| 46 | |
| 47 void HistogramCustomCounts(PP_Var name, | |
| 48 int32_t sample, | |
| 49 int32_t min, int32_t max, | |
| 50 uint32_t bucket_count) { | |
| 51 RETURN_IF_BAD_ARGS(name, sample, min, max, bucket_count); | |
| 52 | |
| 53 StringVar* name_string = StringVar::FromPPVar(name); | |
| 54 if (name_string == NULL) | |
| 55 return; | |
| 56 base::HistogramBase* counter = | |
| 57 base::Histogram::FactoryGet( | |
| 58 name_string->value(), | |
| 59 min, | |
| 60 max, | |
| 61 bucket_count, | |
| 62 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 63 counter->Add(sample); | |
| 64 } | |
| 65 | |
| 66 void HistogramEnumeration(PP_Var name, | |
| 67 int32_t sample, | |
| 68 int32_t boundary_value) { | |
| 69 RETURN_IF_BAD_ARGS(name, sample, 1, boundary_value, boundary_value + 1); | |
| 70 | |
| 71 StringVar* name_string = StringVar::FromPPVar(name); | |
| 72 if (name_string == NULL) | |
| 73 return; | |
| 74 base::HistogramBase* counter = | |
| 75 base::LinearHistogram::FactoryGet( | |
| 76 name_string->value(), | |
| 77 1, | |
| 78 boundary_value, | |
| 79 boundary_value + 1, | |
| 80 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 81 counter->Add(sample); | |
| 82 } | |
| 83 | |
| 84 } // namespace | |
| 85 | |
| 86 const PPB_UMA_Private ppb_uma = { | |
| 87 &HistogramCustomTimes, | |
| 88 &HistogramCustomCounts, | |
| 89 &HistogramEnumeration, | |
| 90 }; | |
| 91 | |
| 92 // static | |
| 93 const PPB_UMA_Private* PPB_UMA_Private_Impl::GetInterface() { | |
| 94 return &ppb_uma; | |
| 95 } | |
| 96 | |
| 97 } // namespace content | |
| OLD | NEW |