Avi Drissman | db497b3 | 2022-09-15 19:47:28 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
[email protected] | 4564949 | 2014-01-24 20:49:34 | [diff] [blame] | 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 "ppapi/cpp/private/uma_private.h" |
| 6 | |
| 7 | #include "ppapi/c/pp_errors.h" |
| 8 | #include "ppapi/c/private/ppb_uma_private.h" |
[email protected] | 1ef13cf | 2014-03-21 22:44:01 | [diff] [blame] | 9 | #include "ppapi/cpp/completion_callback.h" |
[email protected] | 4564949 | 2014-01-24 20:49:34 | [diff] [blame] | 10 | #include "ppapi/cpp/module_impl.h" |
| 11 | #include "ppapi/cpp/var.h" |
| 12 | |
| 13 | namespace pp { |
| 14 | |
| 15 | namespace { |
| 16 | |
[email protected] | 1ef13cf | 2014-03-21 22:44:01 | [diff] [blame] | 17 | template <> const char* interface_name<PPB_UMA_Private_0_3>() { |
| 18 | return PPB_UMA_PRIVATE_INTERFACE_0_3; |
[email protected] | 4564949 | 2014-01-24 20:49:34 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | } // namespace |
| 22 | |
| 23 | UMAPrivate::UMAPrivate() { |
| 24 | } |
| 25 | |
| 26 | UMAPrivate::UMAPrivate( |
| 27 | const InstanceHandle& instance) : instance_(instance.pp_instance()) { |
| 28 | } |
| 29 | |
| 30 | UMAPrivate::~UMAPrivate() { |
| 31 | } |
| 32 | |
| 33 | bool UMAPrivate::IsAvailable() { |
[email protected] | 1ef13cf | 2014-03-21 22:44:01 | [diff] [blame] | 34 | return has_interface<PPB_UMA_Private_0_3>(); |
[email protected] | 4564949 | 2014-01-24 20:49:34 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void UMAPrivate::HistogramCustomTimes(const std::string& name, |
| 38 | int64_t sample, |
| 39 | int64_t min, |
| 40 | int64_t max, |
| 41 | uint32_t bucket_count) { |
| 42 | if (!IsAvailable()) |
| 43 | return; |
[email protected] | 1ef13cf | 2014-03-21 22:44:01 | [diff] [blame] | 44 | get_interface<PPB_UMA_Private_0_3>()-> |
[email protected] | 4564949 | 2014-01-24 20:49:34 | [diff] [blame] | 45 | HistogramCustomTimes(instance_, pp::Var(name).pp_var(), |
| 46 | sample, min, max, bucket_count); |
| 47 | } |
| 48 | |
| 49 | void UMAPrivate::HistogramCustomCounts(const std::string& name, |
| 50 | int32_t sample, |
| 51 | int32_t min, |
| 52 | int32_t max, |
| 53 | uint32_t bucket_count) { |
| 54 | if (!IsAvailable()) |
| 55 | return; |
[email protected] | 1ef13cf | 2014-03-21 22:44:01 | [diff] [blame] | 56 | get_interface<PPB_UMA_Private_0_3>()-> |
[email protected] | 4564949 | 2014-01-24 20:49:34 | [diff] [blame] | 57 | HistogramCustomCounts(instance_, pp::Var(name).pp_var(), |
| 58 | sample, min, max, bucket_count); |
| 59 | } |
| 60 | |
| 61 | void UMAPrivate::HistogramEnumeration(const std::string& name, |
| 62 | int32_t sample, |
| 63 | int32_t boundary_value) { |
| 64 | if (!IsAvailable()) |
| 65 | return; |
[email protected] | 1ef13cf | 2014-03-21 22:44:01 | [diff] [blame] | 66 | get_interface<PPB_UMA_Private_0_3>()-> |
[email protected] | 4564949 | 2014-01-24 20:49:34 | [diff] [blame] | 67 | HistogramEnumeration(instance_, pp::Var(name).pp_var(), |
| 68 | sample, boundary_value); |
| 69 | } |
| 70 | |
[email protected] | 1ef13cf | 2014-03-21 22:44:01 | [diff] [blame] | 71 | int32_t UMAPrivate::IsCrashReportingEnabled(const CompletionCallback& cc) { |
| 72 | if (!IsAvailable()) |
| 73 | return PP_ERROR_NOINTERFACE; |
| 74 | |
| 75 | return get_interface<PPB_UMA_Private_0_3>()-> |
| 76 | IsCrashReportingEnabled(instance_, cc.pp_completion_callback()); |
| 77 | } |
| 78 | |
[email protected] | 4564949 | 2014-01-24 20:49:34 | [diff] [blame] | 79 | } // namespace pp |