[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / ppapi / cpp / udp_socket.cc
blobbb4b1c895b0582a0c28f93052b415c1993700a9e
1 // Copyright 2013 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/cpp/udp_socket.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/cpp/completion_callback.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/var.h"
13 namespace pp {
15 namespace {
17 template <> const char* interface_name<PPB_UDPSocket_1_0>() {
18 return PPB_UDPSOCKET_INTERFACE_1_0;
21 } // namespace
23 UDPSocket::UDPSocket() {
26 UDPSocket::UDPSocket(const InstanceHandle& instance) {
27 if (has_interface<PPB_UDPSocket_1_0>()) {
28 PassRefFromConstructor(get_interface<PPB_UDPSocket_1_0>()->Create(
29 instance.pp_instance()));
33 UDPSocket::UDPSocket(PassRef, PP_Resource resource)
34 : Resource(PASS_REF, resource) {
37 UDPSocket::UDPSocket(const UDPSocket& other) : Resource(other) {
40 UDPSocket::~UDPSocket() {
43 UDPSocket& UDPSocket::operator=(const UDPSocket& other) {
44 Resource::operator=(other);
45 return *this;
48 // static
49 bool UDPSocket::IsAvailable() {
50 return has_interface<PPB_UDPSocket_1_0>();
53 int32_t UDPSocket::Bind(const NetAddress& addr,
54 const CompletionCallback& callback) {
55 if (has_interface<PPB_UDPSocket_1_0>()) {
56 return get_interface<PPB_UDPSocket_1_0>()->Bind(
57 pp_resource(), addr.pp_resource(), callback.pp_completion_callback());
59 return callback.MayForce(PP_ERROR_NOINTERFACE);
62 NetAddress UDPSocket::GetBoundAddress() {
63 if (has_interface<PPB_UDPSocket_1_0>()) {
64 return NetAddress(
65 PASS_REF,
66 get_interface<PPB_UDPSocket_1_0>()->GetBoundAddress(pp_resource()));
68 return NetAddress();
71 int32_t UDPSocket::RecvFrom(
72 char* buffer,
73 int32_t num_bytes,
74 const CompletionCallbackWithOutput<NetAddress>& callback) {
75 if (has_interface<PPB_UDPSocket_1_0>()) {
76 return get_interface<PPB_UDPSocket_1_0>()->RecvFrom(
77 pp_resource(), buffer, num_bytes, callback.output(),
78 callback.pp_completion_callback());
80 return callback.MayForce(PP_ERROR_NOINTERFACE);
83 int32_t UDPSocket::SendTo(const char* buffer,
84 int32_t num_bytes,
85 const NetAddress& addr,
86 const CompletionCallback& callback) {
87 if (has_interface<PPB_UDPSocket_1_0>()) {
88 return get_interface<PPB_UDPSocket_1_0>()->SendTo(
89 pp_resource(), buffer, num_bytes, addr.pp_resource(),
90 callback.pp_completion_callback());
92 return callback.MayForce(PP_ERROR_NOINTERFACE);
95 void UDPSocket::Close() {
96 if (has_interface<PPB_UDPSocket_1_0>())
97 return get_interface<PPB_UDPSocket_1_0>()->Close(pp_resource());
100 int32_t UDPSocket::SetOption(PP_UDPSocket_Option name,
101 const Var& value,
102 const CompletionCallback& callback) {
103 if (has_interface<PPB_UDPSocket_1_0>()) {
104 return get_interface<PPB_UDPSocket_1_0>()->SetOption(
105 pp_resource(), name, value.pp_var(), callback.pp_completion_callback());
107 return callback.MayForce(PP_ERROR_NOINTERFACE);
110 } // namespace pp