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