| 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/socket.h" | 5 #include "chrome/browser/extensions/api/socket/socket.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.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/address_list.h" | 9 #include "net/base/address_list.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 11 #include "net/base/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/socket/socket.h" | 13 #include "net/socket/socket.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 Socket::Socket(APIResourceEventNotifier* event_notifier) | 17 Socket::Socket(APIResourceEventNotifier* event_notifier) |
| 18 : APIResource(APIResource::SocketResource, event_notifier), | 18 : APIResource(APIResource::SocketResource, event_notifier), |
| 19 port_(0), | 19 port_(0), |
| 20 is_connected_(false) { | 20 is_connected_(false) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 Socket::~Socket() { | 23 Socket::~Socket() { |
| 24 // Derived destructors should make sure the socket has been closed. | 24 // Derived destructors should make sure the socket has been closed. |
| 25 DCHECK(!is_connected_); | 25 DCHECK(!is_connected_); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void Socket::PerformSSLHandshake(const std::string& ssl_hostname, |
| 29 int ssl_port, |
| 30 const CompletionCallback& callback) { |
| 31 callback.Run(-1); |
| 32 } |
| 33 |
| 28 void Socket::Write(scoped_refptr<net::IOBuffer> io_buffer, | 34 void Socket::Write(scoped_refptr<net::IOBuffer> io_buffer, |
| 29 int byte_count, | 35 int byte_count, |
| 30 const CompletionCallback& callback) { | 36 const CompletionCallback& callback) { |
| 31 DCHECK(!callback.is_null()); | 37 DCHECK(!callback.is_null()); |
| 32 write_queue_.push(WriteRequest(io_buffer, byte_count, callback)); | 38 write_queue_.push(WriteRequest(io_buffer, byte_count, callback)); |
| 33 WriteData(); | 39 WriteData(); |
| 34 } | 40 } |
| 35 | 41 |
| 36 void Socket::WriteData() { | 42 void Socket::WriteData() { |
| 37 // IO is pending. | 43 // IO is pending. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 result = request.bytes_written; | 73 result = request.bytes_written; |
| 68 } | 74 } |
| 69 | 75 |
| 70 request.callback.Run(result); | 76 request.callback.Run(result); |
| 71 write_queue_.pop(); | 77 write_queue_.pop(); |
| 72 | 78 |
| 73 if (!write_queue_.empty()) | 79 if (!write_queue_.empty()) |
| 74 WriteData(); | 80 WriteData(); |
| 75 } | 81 } |
| 76 | 82 |
| 83 bool Socket::write_queue_empty() const { |
| 84 return write_queue_.empty(); |
| 85 } |
| 86 |
| 77 bool Socket::SetKeepAlive(bool enable, int delay) { | 87 bool Socket::SetKeepAlive(bool enable, int delay) { |
| 78 return false; | 88 return false; |
| 79 } | 89 } |
| 80 | 90 |
| 81 bool Socket::SetNoDelay(bool no_delay) { | 91 bool Socket::SetNoDelay(bool no_delay) { |
| 82 return false; | 92 return false; |
| 83 } | 93 } |
| 84 | 94 |
| 85 // static | 95 // static |
| 86 bool Socket::StringAndPortToIPEndPoint(const std::string& ip_address_str, | 96 bool Socket::StringAndPortToIPEndPoint(const std::string& ip_address_str, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 114 DCHECK(port); | 124 DCHECK(port); |
| 115 *ip_address_str = address.ToStringWithoutPort(); | 125 *ip_address_str = address.ToStringWithoutPort(); |
| 116 if (ip_address_str->empty()) { | 126 if (ip_address_str->empty()) { |
| 117 *port = 0; | 127 *port = 0; |
| 118 } else { | 128 } else { |
| 119 *port = address.port(); | 129 *port = address.port(); |
| 120 } | 130 } |
| 121 } | 131 } |
| 122 | 132 |
| 123 } // namespace extensions | 133 } // namespace extensions |
| OLD | NEW |