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.
5 #include "ppapi/proxy/uma_private_resource.h"
8 #include "ppapi/proxy/ppapi_messages.h"
9 #include "ppapi/proxy/resource_message_params.h"
10 #include "ppapi/shared_impl/var.h"
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())
19 return name_stringvar
->value();
27 UMAPrivateResource::UMAPrivateResource(
28 Connection connection
, PP_Instance instance
)
29 : PluginResource(connection
, instance
) {
30 SendCreate(RENDERER
, PpapiHostMsg_UMA_Create());
33 UMAPrivateResource::~UMAPrivateResource() {
36 thunk::PPB_UMA_Singleton_API
* UMAPrivateResource::AsPPB_UMA_Singleton_API() {
40 void UMAPrivateResource::HistogramCustomTimes(
46 uint32_t bucket_count
) {
47 if (name
.type
!= PP_VARTYPE_STRING
)
50 Post(RENDERER
, PpapiHostMsg_UMA_HistogramCustomTimes(StringFromPPVar(name
),
57 void UMAPrivateResource::HistogramCustomCounts(
63 uint32_t bucket_count
) {
64 if (name
.type
!= PP_VARTYPE_STRING
)
67 Post(RENDERER
, PpapiHostMsg_UMA_HistogramCustomCounts(StringFromPPVar(name
),
74 void UMAPrivateResource::HistogramEnumeration(
78 int32_t boundary_value
) {
79 if (name
.type
!= PP_VARTYPE_STRING
)
82 Post(RENDERER
, PpapiHostMsg_UMA_HistogramEnumeration(StringFromPPVar(name
),
87 int32_t UMAPrivateResource::IsCrashReportingEnabled(
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
>(
95 PpapiHostMsg_UMA_IsCrashReportingEnabled(),
96 base::Bind(&UMAPrivateResource::OnPluginMsgIsCrashReportingEnabled
,
98 return PP_OK_COMPLETIONPENDING
;
101 void UMAPrivateResource::OnPluginMsgIsCrashReportingEnabled(
102 const ResourceMessageReplyParams
& params
) {
103 if (TrackedCallback::IsPending(pending_callback_
))
104 pending_callback_
->Run(params
.result());
105 pending_callback_
= NULL
;