| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/browser/extensions/api/socket/socket.h" | 10 #include "chrome/browser/extensions/api/socket/socket.h" |
| 11 | 11 |
| 12 // This looks like it should be forward-declarable, but it does some tricky | 12 // This looks like it should be forward-declarable, but it does some tricky |
| 13 // moves that make it easier to just include it. | 13 // moves that make it easier to just include it. |
| 14 #include "net/socket/tcp_client_socket.h" | 14 #include "net/socket/tcp_client_socket.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class Socket; | 17 class Socket; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 class APIResourceEventNotifier; | 22 class ApiResourceEventNotifier; |
| 23 | 23 |
| 24 class TCPSocket : public Socket { | 24 class TCPSocket : public Socket { |
| 25 public: | 25 public: |
| 26 explicit TCPSocket(APIResourceEventNotifier* event_notifier); | 26 explicit TCPSocket(ApiResourceEventNotifier* event_notifier); |
| 27 virtual ~TCPSocket(); | 27 virtual ~TCPSocket(); |
| 28 | 28 |
| 29 virtual void Connect(const std::string& address, | 29 virtual void Connect(const std::string& address, |
| 30 int port, | 30 int port, |
| 31 const CompletionCallback& callback) OVERRIDE; | 31 const CompletionCallback& callback) OVERRIDE; |
| 32 virtual void Disconnect() OVERRIDE; | 32 virtual void Disconnect() OVERRIDE; |
| 33 virtual int Bind(const std::string& address, int port) OVERRIDE; | 33 virtual int Bind(const std::string& address, int port) OVERRIDE; |
| 34 virtual void Read(int count, | 34 virtual void Read(int count, |
| 35 const ReadCompletionCallback& callback) OVERRIDE; | 35 const ReadCompletionCallback& callback) OVERRIDE; |
| 36 virtual void RecvFrom(int count, | 36 virtual void RecvFrom(int count, |
| 37 const RecvFromCompletionCallback& callback) OVERRIDE; | 37 const RecvFromCompletionCallback& callback) OVERRIDE; |
| 38 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 38 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
| 39 int byte_count, | 39 int byte_count, |
| 40 const std::string& address, | 40 const std::string& address, |
| 41 int port, | 41 int port, |
| 42 const CompletionCallback& callback) OVERRIDE; | 42 const CompletionCallback& callback) OVERRIDE; |
| 43 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; | 43 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; |
| 44 virtual bool SetNoDelay(bool no_delay) OVERRIDE; | 44 virtual bool SetNoDelay(bool no_delay) OVERRIDE; |
| 45 | 45 |
| 46 static TCPSocket* CreateSocketForTesting( | 46 static TCPSocket* CreateSocketForTesting( |
| 47 net::TCPClientSocket* tcp_client_socket, | 47 net::TCPClientSocket* tcp_client_socket, |
| 48 APIResourceEventNotifier* event_notifier); | 48 ApiResourceEventNotifier* event_notifier); |
| 49 | 49 |
| 50 protected: | 50 protected: |
| 51 virtual int WriteImpl(net::IOBuffer* io_buffer, | 51 virtual int WriteImpl(net::IOBuffer* io_buffer, |
| 52 int io_buffer_size, | 52 int io_buffer_size, |
| 53 const net::CompletionCallback& callback) OVERRIDE; | 53 const net::CompletionCallback& callback) OVERRIDE; |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 void OnConnectComplete(int result); | 56 void OnConnectComplete(int result); |
| 57 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, | 57 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, |
| 58 int result); | 58 int result); |
| 59 | 59 |
| 60 TCPSocket(net::TCPClientSocket* tcp_client_socket, | 60 TCPSocket(net::TCPClientSocket* tcp_client_socket, |
| 61 APIResourceEventNotifier* event_notifier); | 61 ApiResourceEventNotifier* event_notifier); |
| 62 | 62 |
| 63 scoped_ptr<net::TCPClientSocket> socket_; | 63 scoped_ptr<net::TCPClientSocket> socket_; |
| 64 | 64 |
| 65 CompletionCallback connect_callback_; | 65 CompletionCallback connect_callback_; |
| 66 | 66 |
| 67 ReadCompletionCallback read_callback_; | 67 ReadCompletionCallback read_callback_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace extensions | 70 } // namespace extensions |
| 71 | 71 |
| 72 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ | 72 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ |
| OLD | NEW |