| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/socket/udp_socket.h" | 5 #include "extensions/browser/api/socket/udp_socket.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" |
| 9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 10 #include "extensions/browser/api/api_resource.h" | 11 #include "extensions/browser/api/api_resource.h" |
| 11 #include "net/base/ip_address.h" | 12 #include "net/base/ip_address.h" |
| 12 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 #include "net/udp/datagram_socket.h" | 15 #include "net/udp/datagram_socket.h" |
| 15 #include "net/udp/udp_client_socket.h" | 16 #include "net/udp/udp_client_socket.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 result = socket_.Bind(ip_end_point); | 77 result = socket_.Bind(ip_end_point); |
| 77 if (result != net::OK) | 78 if (result != net::OK) |
| 78 socket_.Close(); | 79 socket_.Close(); |
| 79 return result; | 80 return result; |
| 80 } | 81 } |
| 81 | 82 |
| 82 void UDPSocket::Disconnect() { | 83 void UDPSocket::Disconnect() { |
| 83 is_connected_ = false; | 84 is_connected_ = false; |
| 84 socket_.Close(); | 85 socket_.Close(); |
| 85 read_callback_.Reset(); | 86 read_callback_.Reset(); |
| 86 recv_from_callback_.Reset(); | 87 // TODO(devlin): Should we do this for all callbacks? |
| 88 if (!recv_from_callback_.is_null()) { |
| 89 base::ResetAndReturn(&recv_from_callback_) |
| 90 .Run(net::ERR_CONNECTION_CLOSED, nullptr, std::string(), 0); |
| 91 } |
| 87 send_to_callback_.Reset(); | 92 send_to_callback_.Reset(); |
| 88 multicast_groups_.clear(); | 93 multicast_groups_.clear(); |
| 89 } | 94 } |
| 90 | 95 |
| 91 void UDPSocket::Read(int count, const ReadCompletionCallback& callback) { | 96 void UDPSocket::Read(int count, const ReadCompletionCallback& callback) { |
| 92 DCHECK(!callback.is_null()); | 97 DCHECK(!callback.is_null()); |
| 93 | 98 |
| 94 if (!read_callback_.is_null()) { | 99 if (!read_callback_.is_null()) { |
| 95 callback.Run(net::ERR_IO_PENDING, NULL); | 100 callback.Run(net::ERR_IO_PENDING, NULL); |
| 96 return; | 101 return; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 303 |
| 299 ResumableUDPSocket::ResumableUDPSocket(const std::string& owner_extension_id) | 304 ResumableUDPSocket::ResumableUDPSocket(const std::string& owner_extension_id) |
| 300 : UDPSocket(owner_extension_id), | 305 : UDPSocket(owner_extension_id), |
| 301 persistent_(false), | 306 persistent_(false), |
| 302 buffer_size_(0), | 307 buffer_size_(0), |
| 303 paused_(false) {} | 308 paused_(false) {} |
| 304 | 309 |
| 305 bool ResumableUDPSocket::IsPersistent() const { return persistent(); } | 310 bool ResumableUDPSocket::IsPersistent() const { return persistent(); } |
| 306 | 311 |
| 307 } // namespace extensions | 312 } // namespace extensions |
| OLD | NEW |