• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "ppapi/proxy/uma_private_resource.h"
6 
7 #include "base/bind.h"
8 #include "ppapi/proxy/ppapi_messages.h"
9 #include "ppapi/proxy/resource_message_params.h"
10 #include "ppapi/shared_impl/var.h"
11 
12 namespace {
13 
StringFromPPVar(const PP_Var & var)14 std::string StringFromPPVar(const PP_Var& var) {
15   scoped_refptr<ppapi::StringVar> name_stringvar =
16       ppapi::StringVar::FromPPVar(var);
17   if (!name_stringvar.get())
18     return std::string();
19   return name_stringvar->value();
20 }
21 
22 }
23 
24 namespace ppapi {
25 namespace proxy {
26 
UMAPrivateResource(Connection connection,PP_Instance instance)27 UMAPrivateResource::UMAPrivateResource(
28     Connection connection, PP_Instance instance)
29     : PluginResource(connection, instance) {
30   SendCreate(RENDERER, PpapiHostMsg_UMA_Create());
31 }
32 
~UMAPrivateResource()33 UMAPrivateResource::~UMAPrivateResource() {
34 }
35 
AsPPB_UMA_Singleton_API()36 thunk::PPB_UMA_Singleton_API* UMAPrivateResource::AsPPB_UMA_Singleton_API() {
37   return this;
38 }
39 
HistogramCustomTimes(PP_Instance instance,struct PP_Var name,int64_t sample,int64_t min,int64_t max,uint32_t bucket_count)40 void UMAPrivateResource::HistogramCustomTimes(
41     PP_Instance instance,
42     struct PP_Var name,
43     int64_t sample,
44     int64_t min,
45     int64_t max,
46     uint32_t bucket_count) {
47   if (name.type != PP_VARTYPE_STRING)
48     return;
49 
50   Post(RENDERER, PpapiHostMsg_UMA_HistogramCustomTimes(StringFromPPVar(name),
51                                                        sample,
52                                                        min,
53                                                        max,
54                                                        bucket_count));
55 }
56 
HistogramCustomCounts(PP_Instance instance,struct PP_Var name,int32_t sample,int32_t min,int32_t max,uint32_t bucket_count)57 void UMAPrivateResource::HistogramCustomCounts(
58     PP_Instance instance,
59     struct PP_Var name,
60     int32_t sample,
61     int32_t min,
62     int32_t max,
63     uint32_t bucket_count) {
64   if (name.type != PP_VARTYPE_STRING)
65     return;
66 
67   Post(RENDERER, PpapiHostMsg_UMA_HistogramCustomCounts(StringFromPPVar(name),
68                                                         sample,
69                                                         min,
70                                                         max,
71                                                         bucket_count));
72 }
73 
HistogramEnumeration(PP_Instance instance,struct PP_Var name,int32_t sample,int32_t boundary_value)74 void UMAPrivateResource::HistogramEnumeration(
75     PP_Instance instance,
76     struct PP_Var name,
77     int32_t sample,
78     int32_t boundary_value) {
79   if (name.type != PP_VARTYPE_STRING)
80     return;
81 
82   Post(RENDERER, PpapiHostMsg_UMA_HistogramEnumeration(StringFromPPVar(name),
83                                                        sample,
84                                                        boundary_value));
85 }
86 
IsCrashReportingEnabled(PP_Instance instance,scoped_refptr<TrackedCallback> callback)87 int32_t UMAPrivateResource::IsCrashReportingEnabled(
88     PP_Instance instance,
89     scoped_refptr<TrackedCallback> callback) {
90   if (pending_callback_.get() != NULL)
91     return PP_ERROR_INPROGRESS;
92   pending_callback_ = callback;
93   Call<PpapiPluginMsg_UMA_IsCrashReportingEnabledReply>(
94       RENDERER,
95       PpapiHostMsg_UMA_IsCrashReportingEnabled(),
96       base::Bind(&UMAPrivateResource::OnPluginMsgIsCrashReportingEnabled,
97           this));
98   return PP_OK_COMPLETIONPENDING;
99 }
100 
OnPluginMsgIsCrashReportingEnabled(const ResourceMessageReplyParams & params)101 void UMAPrivateResource::OnPluginMsgIsCrashReportingEnabled(
102     const ResourceMessageReplyParams& params) {
103   if (TrackedCallback::IsPending(pending_callback_))
104     pending_callback_->Run(params.result());
105   pending_callback_ = NULL;
106 }
107 
108 }  // namespace proxy
109 }  // namespace ppapi
110 
111