OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/shared_impl/private/udp_socket_private_impl.h" | 5 #include "ppapi/shared_impl/private/udp_socket_private_impl.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 UDPSocketPrivateImpl::~UDPSocketPrivateImpl() { | 35 UDPSocketPrivateImpl::~UDPSocketPrivateImpl() { |
36 } | 36 } |
37 | 37 |
38 thunk::PPB_UDPSocket_Private_API* | 38 thunk::PPB_UDPSocket_Private_API* |
39 UDPSocketPrivateImpl::AsPPB_UDPSocket_Private_API() { | 39 UDPSocketPrivateImpl::AsPPB_UDPSocket_Private_API() { |
40 return this; | 40 return this; |
41 } | 41 } |
42 | 42 |
| 43 int32_t UDPSocketPrivateImpl::SetSocketFeature( |
| 44 PP_UDPSocketFeature_Private name, |
| 45 PP_Var value, |
| 46 scoped_refptr<TrackedCallback> callback) { |
| 47 if (bound_ || closed_) |
| 48 return PP_ERROR_FAILED; |
| 49 if (TrackedCallback::IsPending(setsocketfeature_callback_)) |
| 50 return PP_ERROR_INPROGRESS; |
| 51 |
| 52 setsocketfeature_callback_ = callback; |
| 53 |
| 54 // Send the request, the browser will call us back via |
| 55 // SetSocketFeatureACK. |
| 56 SendSetSocketFeature(name, value); |
| 57 return PP_OK_COMPLETIONPENDING; |
| 58 } |
| 59 |
43 int32_t UDPSocketPrivateImpl::Bind(const PP_NetAddress_Private* addr, | 60 int32_t UDPSocketPrivateImpl::Bind(const PP_NetAddress_Private* addr, |
44 scoped_refptr<TrackedCallback> callback) { | 61 scoped_refptr<TrackedCallback> callback) { |
45 if (!addr) | 62 if (!addr) |
46 return PP_ERROR_BADARGUMENT; | 63 return PP_ERROR_BADARGUMENT; |
47 if (bound_ || closed_) | 64 if (bound_ || closed_) |
48 return PP_ERROR_FAILED; | 65 return PP_ERROR_FAILED; |
49 if (TrackedCallback::IsPending(bind_callback_)) | 66 if (TrackedCallback::IsPending(bind_callback_)) |
50 return PP_ERROR_INPROGRESS; | 67 return PP_ERROR_INPROGRESS; |
51 | 68 |
52 bind_callback_ = callback; | 69 bind_callback_ = callback; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 if(closed_) | 134 if(closed_) |
118 return; | 135 return; |
119 | 136 |
120 bound_ = false; | 137 bound_ = false; |
121 closed_ = true; | 138 closed_ = true; |
122 | 139 |
123 SendClose(); | 140 SendClose(); |
124 | 141 |
125 socket_id_ = 0; | 142 socket_id_ = 0; |
126 | 143 |
| 144 PostAbortIfNecessary(&setsocketfeature_callback_); |
127 PostAbortIfNecessary(&bind_callback_); | 145 PostAbortIfNecessary(&bind_callback_); |
128 PostAbortIfNecessary(&recvfrom_callback_); | 146 PostAbortIfNecessary(&recvfrom_callback_); |
129 PostAbortIfNecessary(&sendto_callback_); | 147 PostAbortIfNecessary(&sendto_callback_); |
130 } | 148 } |
131 | 149 |
| 150 void UDPSocketPrivateImpl::OnSetSocketFeatureCompleted(bool succeeded) { |
| 151 if (!TrackedCallback::IsPending(setsocketfeature_callback_)) { |
| 152 NOTREACHED(); |
| 153 return; |
| 154 } |
| 155 TrackedCallback::ClearAndRun(&setsocketfeature_callback_, |
| 156 succeeded ? PP_OK : PP_ERROR_FAILED); |
| 157 } |
| 158 |
132 void UDPSocketPrivateImpl::OnBindCompleted( | 159 void UDPSocketPrivateImpl::OnBindCompleted( |
133 bool succeeded, | 160 bool succeeded, |
134 const PP_NetAddress_Private& addr) { | 161 const PP_NetAddress_Private& addr) { |
135 if (!TrackedCallback::IsPending(bind_callback_)) { | 162 if (!TrackedCallback::IsPending(bind_callback_)) { |
136 NOTREACHED(); | 163 NOTREACHED(); |
137 return; | 164 return; |
138 } | 165 } |
139 | 166 |
140 if (succeeded) | 167 if (succeeded) |
141 bound_ = true; | 168 bound_ = true; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 arraysize(bound_addr_.data) * sizeof(*bound_addr_.data)); | 223 arraysize(bound_addr_.data) * sizeof(*bound_addr_.data)); |
197 } | 224 } |
198 | 225 |
199 void UDPSocketPrivateImpl::PostAbortIfNecessary( | 226 void UDPSocketPrivateImpl::PostAbortIfNecessary( |
200 scoped_refptr<TrackedCallback>* callback) { | 227 scoped_refptr<TrackedCallback>* callback) { |
201 if (callback->get()) | 228 if (callback->get()) |
202 (*callback)->PostAbort(); | 229 (*callback)->PostAbort(); |
203 } | 230 } |
204 | 231 |
205 } // namespace ppapi | 232 } // namespace ppapi |
OLD | NEW |