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/tcp_socket.h" | 5 #include "extensions/browser/api/socket/tcp_socket.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "extensions/browser/api/api_resource.h" | 10 #include "extensions/browser/api/api_resource.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // static | 71 // static |
72 TCPSocket* TCPSocket::CreateServerSocketForTesting( | 72 TCPSocket* TCPSocket::CreateServerSocketForTesting( |
73 net::TCPServerSocket* tcp_server_socket, | 73 net::TCPServerSocket* tcp_server_socket, |
74 const std::string& owner_extension_id) { | 74 const std::string& owner_extension_id) { |
75 return new TCPSocket(tcp_server_socket, owner_extension_id); | 75 return new TCPSocket(tcp_server_socket, owner_extension_id); |
76 } | 76 } |
77 | 77 |
78 TCPSocket::~TCPSocket() { Disconnect(); } | 78 TCPSocket::~TCPSocket() { Disconnect(); } |
79 | 79 |
80 void TCPSocket::Connect(const std::string& address, | 80 void TCPSocket::Connect(const std::string& address, |
81 int port, | 81 uint16 port, |
82 const CompletionCallback& callback) { | 82 const CompletionCallback& callback) { |
83 DCHECK(!callback.is_null()); | 83 DCHECK(!callback.is_null()); |
84 | 84 |
85 if (socket_mode_ == SERVER || !connect_callback_.is_null()) { | 85 if (socket_mode_ == SERVER || !connect_callback_.is_null()) { |
86 callback.Run(net::ERR_CONNECTION_FAILED); | 86 callback.Run(net::ERR_CONNECTION_FAILED); |
87 return; | 87 return; |
88 } | 88 } |
89 DCHECK(!server_socket_.get()); | 89 DCHECK(!server_socket_.get()); |
90 socket_mode_ = CLIENT; | 90 socket_mode_ = CLIENT; |
91 connect_callback_ = callback; | 91 connect_callback_ = callback; |
(...skipping 25 matching lines...) Expand all Loading... |
117 is_connected_ = false; | 117 is_connected_ = false; |
118 if (socket_.get()) | 118 if (socket_.get()) |
119 socket_->Disconnect(); | 119 socket_->Disconnect(); |
120 server_socket_.reset(NULL); | 120 server_socket_.reset(NULL); |
121 connect_callback_.Reset(); | 121 connect_callback_.Reset(); |
122 read_callback_.Reset(); | 122 read_callback_.Reset(); |
123 accept_callback_.Reset(); | 123 accept_callback_.Reset(); |
124 accept_socket_.reset(NULL); | 124 accept_socket_.reset(NULL); |
125 } | 125 } |
126 | 126 |
127 int TCPSocket::Bind(const std::string& address, int port) { | 127 int TCPSocket::Bind(const std::string& address, uint16 port) { |
128 return net::ERR_FAILED; | 128 return net::ERR_FAILED; |
129 } | 129 } |
130 | 130 |
131 void TCPSocket::Read(int count, const ReadCompletionCallback& callback) { | 131 void TCPSocket::Read(int count, const ReadCompletionCallback& callback) { |
132 DCHECK(!callback.is_null()); | 132 DCHECK(!callback.is_null()); |
133 | 133 |
134 if (socket_mode_ != CLIENT) { | 134 if (socket_mode_ != CLIENT) { |
135 callback.Run(net::ERR_FAILED, NULL); | 135 callback.Run(net::ERR_FAILED, NULL); |
136 return; | 136 return; |
137 } | 137 } |
(...skipping 26 matching lines...) Expand all Loading... |
164 } | 164 } |
165 | 165 |
166 void TCPSocket::RecvFrom(int count, | 166 void TCPSocket::RecvFrom(int count, |
167 const RecvFromCompletionCallback& callback) { | 167 const RecvFromCompletionCallback& callback) { |
168 callback.Run(net::ERR_FAILED, NULL, NULL, 0); | 168 callback.Run(net::ERR_FAILED, NULL, NULL, 0); |
169 } | 169 } |
170 | 170 |
171 void TCPSocket::SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 171 void TCPSocket::SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
172 int byte_count, | 172 int byte_count, |
173 const std::string& address, | 173 const std::string& address, |
174 int port, | 174 uint16 port, |
175 const CompletionCallback& callback) { | 175 const CompletionCallback& callback) { |
176 callback.Run(net::ERR_FAILED); | 176 callback.Run(net::ERR_FAILED); |
177 } | 177 } |
178 | 178 |
179 bool TCPSocket::SetKeepAlive(bool enable, int delay) { | 179 bool TCPSocket::SetKeepAlive(bool enable, int delay) { |
180 if (!socket_.get()) | 180 if (!socket_.get()) |
181 return false; | 181 return false; |
182 return socket_->SetKeepAlive(enable, delay); | 182 return socket_->SetKeepAlive(enable, delay); |
183 } | 183 } |
184 | 184 |
185 bool TCPSocket::SetNoDelay(bool no_delay) { | 185 bool TCPSocket::SetNoDelay(bool no_delay) { |
186 if (!socket_.get()) | 186 if (!socket_.get()) |
187 return false; | 187 return false; |
188 return socket_->SetNoDelay(no_delay); | 188 return socket_->SetNoDelay(no_delay); |
189 } | 189 } |
190 | 190 |
191 int TCPSocket::Listen(const std::string& address, | 191 int TCPSocket::Listen(const std::string& address, |
192 int port, | 192 uint16 port, |
193 int backlog, | 193 int backlog, |
194 std::string* error_msg) { | 194 std::string* error_msg) { |
195 if (socket_mode_ == CLIENT) { | 195 if (socket_mode_ == CLIENT) { |
196 *error_msg = kTCPSocketTypeInvalidError; | 196 *error_msg = kTCPSocketTypeInvalidError; |
197 return net::ERR_NOT_IMPLEMENTED; | 197 return net::ERR_NOT_IMPLEMENTED; |
198 } | 198 } |
199 DCHECK(!socket_.get()); | 199 DCHECK(!socket_.get()); |
200 socket_mode_ = SERVER; | 200 socket_mode_ = SERVER; |
201 | 201 |
202 if (!server_socket_.get()) { | 202 if (!server_socket_.get()) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 350 |
351 bool ResumableTCPSocket::IsPersistent() const { return persistent(); } | 351 bool ResumableTCPSocket::IsPersistent() const { return persistent(); } |
352 | 352 |
353 ResumableTCPServerSocket::ResumableTCPServerSocket( | 353 ResumableTCPServerSocket::ResumableTCPServerSocket( |
354 const std::string& owner_extension_id) | 354 const std::string& owner_extension_id) |
355 : TCPSocket(owner_extension_id), persistent_(false), paused_(false) {} | 355 : TCPSocket(owner_extension_id), persistent_(false), paused_(false) {} |
356 | 356 |
357 bool ResumableTCPServerSocket::IsPersistent() const { return persistent(); } | 357 bool ResumableTCPServerSocket::IsPersistent() const { return persistent(); } |
358 | 358 |
359 } // namespace extensions | 359 } // namespace extensions |
OLD | NEW |