| 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/socket.h" | 5 #include "extensions/browser/api/socket/socket.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "extensions/browser/api/api_resource_manager.h" | 9 #include "extensions/browser/api/api_resource_manager.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 if (!write_queue_.empty()) | 84 if (!write_queue_.empty()) |
| 85 WriteData(); | 85 WriteData(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool Socket::SetKeepAlive(bool enable, int delay) { return false; } | 88 bool Socket::SetKeepAlive(bool enable, int delay) { return false; } |
| 89 | 89 |
| 90 bool Socket::SetNoDelay(bool no_delay) { return false; } | 90 bool Socket::SetNoDelay(bool no_delay) { return false; } |
| 91 | 91 |
| 92 int Socket::Listen(const std::string& address, | 92 int Socket::Listen(const std::string& address, |
| 93 int port, | 93 uint16 port, |
| 94 int backlog, | 94 int backlog, |
| 95 std::string* error_msg) { | 95 std::string* error_msg) { |
| 96 *error_msg = kSocketTypeNotSupported; | 96 *error_msg = kSocketTypeNotSupported; |
| 97 return net::ERR_FAILED; | 97 return net::ERR_FAILED; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void Socket::Accept(const AcceptCompletionCallback& callback) { | 100 void Socket::Accept(const AcceptCompletionCallback& callback) { |
| 101 callback.Run(net::ERR_FAILED, NULL); | 101 callback.Run(net::ERR_FAILED, NULL); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 bool Socket::StringAndPortToIPEndPoint(const std::string& ip_address_str, | 105 bool Socket::StringAndPortToIPEndPoint(const std::string& ip_address_str, |
| 106 int port, | 106 uint16 port, |
| 107 net::IPEndPoint* ip_end_point) { | 107 net::IPEndPoint* ip_end_point) { |
| 108 DCHECK(ip_end_point); | 108 DCHECK(ip_end_point); |
| 109 net::IPAddressNumber ip_number; | 109 net::IPAddressNumber ip_number; |
| 110 if (!net::ParseIPLiteralToNumber(ip_address_str, &ip_number)) | 110 if (!net::ParseIPLiteralToNumber(ip_address_str, &ip_number)) |
| 111 return false; | 111 return false; |
| 112 | 112 |
| 113 *ip_end_point = net::IPEndPoint(ip_number, port); | 113 *ip_end_point = net::IPEndPoint(ip_number, port); |
| 114 return true; | 114 return true; |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool Socket::StringAndPortToAddressList(const std::string& ip_address_str, | 117 bool Socket::StringAndPortToAddressList(const std::string& ip_address_str, |
| 118 int port, | 118 uint16 port, |
| 119 net::AddressList* address_list) { | 119 net::AddressList* address_list) { |
| 120 DCHECK(address_list); | 120 DCHECK(address_list); |
| 121 net::IPAddressNumber ip_number; | 121 net::IPAddressNumber ip_number; |
| 122 if (!net::ParseIPLiteralToNumber(ip_address_str, &ip_number)) | 122 if (!net::ParseIPLiteralToNumber(ip_address_str, &ip_number)) |
| 123 return false; | 123 return false; |
| 124 | 124 |
| 125 *address_list = net::AddressList::CreateFromIPAddress(ip_number, port); | 125 *address_list = net::AddressList::CreateFromIPAddress(ip_number, port); |
| 126 return true; | 126 return true; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void Socket::IPEndPointToStringAndPort(const net::IPEndPoint& address, | 129 void Socket::IPEndPointToStringAndPort(const net::IPEndPoint& address, |
| 130 std::string* ip_address_str, | 130 std::string* ip_address_str, |
| 131 int* port) { | 131 uint16* port) { |
| 132 DCHECK(ip_address_str); | 132 DCHECK(ip_address_str); |
| 133 DCHECK(port); | 133 DCHECK(port); |
| 134 *ip_address_str = address.ToStringWithoutPort(); | 134 *ip_address_str = address.ToStringWithoutPort(); |
| 135 if (ip_address_str->empty()) { | 135 if (ip_address_str->empty()) { |
| 136 *port = 0; | 136 *port = 0; |
| 137 } else { | 137 } else { |
| 138 *port = address.port(); | 138 *port = address.port(); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 Socket::WriteRequest::WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, | 142 Socket::WriteRequest::WriteRequest(scoped_refptr<net::IOBuffer> io_buffer, |
| 143 int byte_count, | 143 int byte_count, |
| 144 const CompletionCallback& callback) | 144 const CompletionCallback& callback) |
| 145 : io_buffer(io_buffer), | 145 : io_buffer(io_buffer), |
| 146 byte_count(byte_count), | 146 byte_count(byte_count), |
| 147 callback(callback), | 147 callback(callback), |
| 148 bytes_written(0) {} | 148 bytes_written(0) {} |
| 149 | 149 |
| 150 Socket::WriteRequest::~WriteRequest() {} | 150 Socket::WriteRequest::~WriteRequest() {} |
| 151 | 151 |
| 152 } // namespace extensions | 152 } // namespace extensions |
| OLD | NEW |