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 "chrome/browser/extensions/api/socket/udp_socket.h" | 5 #include "chrome/browser/extensions/api/socket/udp_socket.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/api_resource.h" | 7 #include "chrome/browser/extensions/api/api_resource.h" |
8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" | 8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" |
9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 io_buffer.get(), | 178 io_buffer.get(), |
179 byte_count, | 179 byte_count, |
180 ip_end_point, | 180 ip_end_point, |
181 base::Bind(&UDPSocket::OnSendToComplete, base::Unretained(this))); | 181 base::Bind(&UDPSocket::OnSendToComplete, base::Unretained(this))); |
182 } while (false); | 182 } while (false); |
183 | 183 |
184 if (result != net::ERR_IO_PENDING) | 184 if (result != net::ERR_IO_PENDING) |
185 OnSendToComplete(result); | 185 OnSendToComplete(result); |
186 } | 186 } |
187 | 187 |
| 188 Socket::SocketType UDPSocket::socket_type() const { |
| 189 return Socket::TYPE_UDP; |
| 190 } |
| 191 |
188 void UDPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, | 192 void UDPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, |
189 int result) { | 193 int result) { |
190 DCHECK(!read_callback_.is_null()); | 194 DCHECK(!read_callback_.is_null()); |
191 read_callback_.Run(result, io_buffer); | 195 read_callback_.Run(result, io_buffer); |
192 read_callback_.Reset(); | 196 read_callback_.Reset(); |
193 } | 197 } |
194 | 198 |
195 void UDPSocket::OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, | 199 void UDPSocket::OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, |
196 scoped_refptr<IPEndPoint> address, | 200 scoped_refptr<IPEndPoint> address, |
197 int result) { | 201 int result) { |
198 DCHECK(!recv_from_callback_.is_null()); | 202 DCHECK(!recv_from_callback_.is_null()); |
199 std::string ip; | 203 std::string ip; |
200 int port = 0; | 204 int port = 0; |
201 if (result > 0 && address.get()) { | 205 if (result > 0 && address.get()) { |
202 IPEndPointToStringAndPort(address->data, &ip, &port); | 206 IPEndPointToStringAndPort(address->data, &ip, &port); |
203 } | 207 } |
204 recv_from_callback_.Run(result, io_buffer, ip, port); | 208 recv_from_callback_.Run(result, io_buffer, ip, port); |
205 recv_from_callback_.Reset(); | 209 recv_from_callback_.Reset(); |
206 } | 210 } |
207 | 211 |
208 void UDPSocket::OnSendToComplete(int result) { | 212 void UDPSocket::OnSendToComplete(int result) { |
209 DCHECK(!send_to_callback_.is_null()); | 213 DCHECK(!send_to_callback_.is_null()); |
210 send_to_callback_.Run(result); | 214 send_to_callback_.Run(result); |
211 send_to_callback_.Reset(); | 215 send_to_callback_.Reset(); |
212 } | 216 } |
213 | 217 |
214 } // namespace extensions | 218 } // namespace extensions |
OLD | NEW |