Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Side by Side Diff: ppapi/cpp/udp_socket.cc

Issue 690903002: Remove timing limitation of SetOption invocation for PPAPI sockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fixed implementation. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/cpp/udp_socket.h" 5 #include "ppapi/cpp/udp_socket.h"
6 6
7 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/cpp/completion_callback.h" 8 #include "ppapi/cpp/completion_callback.h"
9 #include "ppapi/cpp/instance_handle.h" 9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module_impl.h" 10 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/var.h" 11 #include "ppapi/cpp/var.h"
12 12
13 namespace pp { 13 namespace pp {
14 14
15 namespace { 15 namespace {
16 16
17 template <> const char* interface_name<PPB_UDPSocket_1_0>() { 17 template <> const char* interface_name<PPB_UDPSocket_1_0>() {
18 return PPB_UDPSOCKET_INTERFACE_1_0; 18 return PPB_UDPSOCKET_INTERFACE_1_0;
19 } 19 }
20 20
21 template <> const char* interface_name<PPB_UDPSocket_1_1>() {
22 return PPB_UDPSOCKET_INTERFACE_1_1;
23 }
24
21 } // namespace 25 } // namespace
22 26
23 UDPSocket::UDPSocket() { 27 UDPSocket::UDPSocket() {
24 } 28 }
25 29
26 UDPSocket::UDPSocket(const InstanceHandle& instance) { 30 UDPSocket::UDPSocket(const InstanceHandle& instance) {
27 if (has_interface<PPB_UDPSocket_1_0>()) { 31 if (has_interface<PPB_UDPSocket_1_1>()) {
32 PassRefFromConstructor(get_interface<PPB_UDPSocket_1_1>()->Create(
33 instance.pp_instance()));
34 } else if (has_interface<PPB_UDPSocket_1_0>()) {
28 PassRefFromConstructor(get_interface<PPB_UDPSocket_1_0>()->Create( 35 PassRefFromConstructor(get_interface<PPB_UDPSocket_1_0>()->Create(
29 instance.pp_instance())); 36 instance.pp_instance()));
30 } 37 }
31 } 38 }
32 39
33 UDPSocket::UDPSocket(PassRef, PP_Resource resource) 40 UDPSocket::UDPSocket(PassRef, PP_Resource resource)
34 : Resource(PASS_REF, resource) { 41 : Resource(PASS_REF, resource) {
35 } 42 }
36 43
37 UDPSocket::UDPSocket(const UDPSocket& other) : Resource(other) { 44 UDPSocket::UDPSocket(const UDPSocket& other) : Resource(other) {
38 } 45 }
39 46
40 UDPSocket::~UDPSocket() { 47 UDPSocket::~UDPSocket() {
41 } 48 }
42 49
43 UDPSocket& UDPSocket::operator=(const UDPSocket& other) { 50 UDPSocket& UDPSocket::operator=(const UDPSocket& other) {
44 Resource::operator=(other); 51 Resource::operator=(other);
45 return *this; 52 return *this;
46 } 53 }
47 54
48 // static 55 // static
49 bool UDPSocket::IsAvailable() { 56 bool UDPSocket::IsAvailable() {
50 return has_interface<PPB_UDPSocket_1_0>(); 57 return has_interface<PPB_UDPSocket_1_1>() ||
58 has_interface<PPB_UDPSocket_1_0>();
51 } 59 }
52 60
53 int32_t UDPSocket::Bind(const NetAddress& addr, 61 int32_t UDPSocket::Bind(const NetAddress& addr,
54 const CompletionCallback& callback) { 62 const CompletionCallback& callback) {
63 if (has_interface<PPB_UDPSocket_1_1>()) {
64 return get_interface<PPB_UDPSocket_1_1>()->Bind(
65 pp_resource(), addr.pp_resource(), callback.pp_completion_callback());
66 }
55 if (has_interface<PPB_UDPSocket_1_0>()) { 67 if (has_interface<PPB_UDPSocket_1_0>()) {
56 return get_interface<PPB_UDPSocket_1_0>()->Bind( 68 return get_interface<PPB_UDPSocket_1_0>()->Bind(
57 pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); 69 pp_resource(), addr.pp_resource(), callback.pp_completion_callback());
58 } 70 }
59 return callback.MayForce(PP_ERROR_NOINTERFACE); 71 return callback.MayForce(PP_ERROR_NOINTERFACE);
60 } 72 }
61 73
62 NetAddress UDPSocket::GetBoundAddress() { 74 NetAddress UDPSocket::GetBoundAddress() {
75 if (has_interface<PPB_UDPSocket_1_1>()) {
76 return NetAddress(
77 PASS_REF,
78 get_interface<PPB_UDPSocket_1_1>()->GetBoundAddress(pp_resource()));
79 }
63 if (has_interface<PPB_UDPSocket_1_0>()) { 80 if (has_interface<PPB_UDPSocket_1_0>()) {
64 return NetAddress( 81 return NetAddress(
65 PASS_REF, 82 PASS_REF,
66 get_interface<PPB_UDPSocket_1_0>()->GetBoundAddress(pp_resource())); 83 get_interface<PPB_UDPSocket_1_0>()->GetBoundAddress(pp_resource()));
67 } 84 }
68 return NetAddress(); 85 return NetAddress();
69 } 86 }
70 87
71 int32_t UDPSocket::RecvFrom( 88 int32_t UDPSocket::RecvFrom(
72 char* buffer, 89 char* buffer,
73 int32_t num_bytes, 90 int32_t num_bytes,
74 const CompletionCallbackWithOutput<NetAddress>& callback) { 91 const CompletionCallbackWithOutput<NetAddress>& callback) {
92 if (has_interface<PPB_UDPSocket_1_1>()) {
93 return get_interface<PPB_UDPSocket_1_1>()->RecvFrom(
94 pp_resource(), buffer, num_bytes, callback.output(),
95 callback.pp_completion_callback());
96 }
75 if (has_interface<PPB_UDPSocket_1_0>()) { 97 if (has_interface<PPB_UDPSocket_1_0>()) {
76 return get_interface<PPB_UDPSocket_1_0>()->RecvFrom( 98 return get_interface<PPB_UDPSocket_1_0>()->RecvFrom(
77 pp_resource(), buffer, num_bytes, callback.output(), 99 pp_resource(), buffer, num_bytes, callback.output(),
78 callback.pp_completion_callback()); 100 callback.pp_completion_callback());
79 } 101 }
80 return callback.MayForce(PP_ERROR_NOINTERFACE); 102 return callback.MayForce(PP_ERROR_NOINTERFACE);
81 } 103 }
82 104
83 int32_t UDPSocket::SendTo(const char* buffer, 105 int32_t UDPSocket::SendTo(const char* buffer,
84 int32_t num_bytes, 106 int32_t num_bytes,
85 const NetAddress& addr, 107 const NetAddress& addr,
86 const CompletionCallback& callback) { 108 const CompletionCallback& callback) {
109 if (has_interface<PPB_UDPSocket_1_1>()) {
110 return get_interface<PPB_UDPSocket_1_1>()->SendTo(
111 pp_resource(), buffer, num_bytes, addr.pp_resource(),
112 callback.pp_completion_callback());
113 }
87 if (has_interface<PPB_UDPSocket_1_0>()) { 114 if (has_interface<PPB_UDPSocket_1_0>()) {
88 return get_interface<PPB_UDPSocket_1_0>()->SendTo( 115 return get_interface<PPB_UDPSocket_1_0>()->SendTo(
89 pp_resource(), buffer, num_bytes, addr.pp_resource(), 116 pp_resource(), buffer, num_bytes, addr.pp_resource(),
90 callback.pp_completion_callback()); 117 callback.pp_completion_callback());
91 } 118 }
92 return callback.MayForce(PP_ERROR_NOINTERFACE); 119 return callback.MayForce(PP_ERROR_NOINTERFACE);
93 } 120 }
94 121
95 void UDPSocket::Close() { 122 void UDPSocket::Close() {
123 if (has_interface<PPB_UDPSocket_1_1>())
124 return get_interface<PPB_UDPSocket_1_1>()->Close(pp_resource());
96 if (has_interface<PPB_UDPSocket_1_0>()) 125 if (has_interface<PPB_UDPSocket_1_0>())
97 return get_interface<PPB_UDPSocket_1_0>()->Close(pp_resource()); 126 return get_interface<PPB_UDPSocket_1_0>()->Close(pp_resource());
98 } 127 }
99 128
100 int32_t UDPSocket::SetOption(PP_UDPSocket_Option name, 129 int32_t UDPSocket::SetOption(PP_UDPSocket_Option name,
101 const Var& value, 130 const Var& value,
102 const CompletionCallback& callback) { 131 const CompletionCallback& callback) {
132 if (has_interface<PPB_UDPSocket_1_1>()) {
133 return get_interface<PPB_UDPSocket_1_1>()->SetOption(
134 pp_resource(), name, value.pp_var(), callback.pp_completion_callback());
135 }
103 if (has_interface<PPB_UDPSocket_1_0>()) { 136 if (has_interface<PPB_UDPSocket_1_0>()) {
104 return get_interface<PPB_UDPSocket_1_0>()->SetOption( 137 return get_interface<PPB_UDPSocket_1_0>()->SetOption(
105 pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); 138 pp_resource(), name, value.pp_var(), callback.pp_completion_callback());
106 } 139 }
107 return callback.MayForce(PP_ERROR_NOINTERFACE); 140 return callback.MayForce(PP_ERROR_NOINTERFACE);
108 } 141 }
109 142
110 } // namespace pp 143 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698