Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / ppapi / cpp / private / tcp_server_socket_private.cc
blob50adcc126a63314a4ddd6ec2b8d5566c1a2e6a48
1 // Copyright (c) 2012 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/private/tcp_server_socket_private.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.h"
11 #include "ppapi/cpp/module_impl.h"
13 namespace pp {
15 namespace {
17 template <> const char* interface_name<PPB_TCPServerSocket_Private_0_2>() {
18 return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_2;
21 template <> const char* interface_name<PPB_TCPServerSocket_Private_0_1>() {
22 return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_1;
25 } // namespace
27 TCPServerSocketPrivate::TCPServerSocketPrivate(const InstanceHandle& instance) {
28 if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
29 PassRefFromConstructor(
30 get_interface<PPB_TCPServerSocket_Private_0_2>()->Create(
31 instance.pp_instance()));
32 } else if (has_interface<PPB_TCPServerSocket_Private_0_1>()) {
33 PassRefFromConstructor(
34 get_interface<PPB_TCPServerSocket_Private_0_1>()->Create(
35 instance.pp_instance()));
39 // static
40 bool TCPServerSocketPrivate::IsAvailable() {
41 return has_interface<PPB_TCPServerSocket_Private_0_2>() ||
42 has_interface<PPB_TCPServerSocket_Private_0_1>();
45 int32_t TCPServerSocketPrivate::Listen(const PP_NetAddress_Private* addr,
46 int32_t backlog,
47 const CompletionCallback& callback) {
48 if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
49 return get_interface<PPB_TCPServerSocket_Private_0_2>()->Listen(
50 pp_resource(), addr, backlog, callback.pp_completion_callback());
52 if (has_interface<PPB_TCPServerSocket_Private_0_1>()) {
53 return get_interface<PPB_TCPServerSocket_Private_0_1>()->Listen(
54 pp_resource(), addr, backlog, callback.pp_completion_callback());
56 return callback.MayForce(PP_ERROR_NOINTERFACE);
59 int32_t TCPServerSocketPrivate::Accept(PP_Resource* tcp_socket,
60 const CompletionCallback& callback) {
61 if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
62 return get_interface<PPB_TCPServerSocket_Private_0_2>()->Accept(
63 pp_resource(), tcp_socket, callback.pp_completion_callback());
65 if (has_interface<PPB_TCPServerSocket_Private_0_1>()) {
66 return get_interface<PPB_TCPServerSocket_Private_0_1>()->Accept(
67 pp_resource(), tcp_socket, callback.pp_completion_callback());
69 return callback.MayForce(PP_ERROR_NOINTERFACE);
72 int32_t TCPServerSocketPrivate::GetLocalAddress(PP_NetAddress_Private* addr) {
73 if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
74 return get_interface<PPB_TCPServerSocket_Private_0_2>()->GetLocalAddress(
75 pp_resource(), addr);
77 return PP_ERROR_NOINTERFACE;
80 void TCPServerSocketPrivate::StopListening() {
81 if (has_interface<PPB_TCPServerSocket_Private_0_2>()) {
82 return get_interface<PPB_TCPServerSocket_Private_0_2>()->StopListening(
83 pp_resource());
85 if (has_interface<PPB_TCPServerSocket_Private_0_1>()) {
86 return get_interface<PPB_TCPServerSocket_Private_0_1>()->StopListening(
87 pp_resource());
91 } // namespace pp