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