Chromium Code Reviews| 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_SSL_SOCKET_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SSL_SOCKET_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" | |
| 11 #include "chrome/browser/extensions/api/socket/socket.h" | 12 #include "chrome/browser/extensions/api/socket/socket.h" |
| 12 | 13 |
| 13 // This looks like it should be forward-declarable, but it does some tricky | 14 #include "net/socket/ssl_client_socket.h" |
| 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 { | |
| 18 class Socket; | |
| 19 } | |
| 20 | |
| 21 namespace extensions { | 17 namespace extensions { |
| 22 | 18 |
| 23 class APIResourceEventNotifier; | 19 class SSLSocket : public Socket { |
| 24 | |
| 25 class TCPSocket : public Socket { | |
| 26 public: | 20 public: |
| 27 explicit TCPSocket(APIResourceEventNotifier* event_notifier); | 21 explicit SSLSocket(extensions::APIResourceEventNotifier* event_notifier); |
| 28 virtual ~TCPSocket(); | 22 virtual ~SSLSocket(); |
| 29 | 23 |
| 30 virtual void Connect(const std::string& address, | 24 virtual void Connect(const std::string& address, |
| 31 int port, | 25 int port, |
| 32 const CompletionCallback& callback) OVERRIDE; | 26 const CompletionCallback& callback) OVERRIDE; |
| 27 virtual void PerformSSLHandshake( | |
| 28 const std::string& ssl_hostname, | |
| 29 int ssl_port, | |
| 30 const CompletionCallback& callback) OVERRIDE; | |
| 33 virtual void Disconnect() OVERRIDE; | 31 virtual void Disconnect() OVERRIDE; |
| 34 virtual int Bind(const std::string& address, int port) OVERRIDE; | 32 virtual int Bind(const std::string& address, int port) OVERRIDE; |
| 35 virtual void Read(int count, | 33 virtual void Read(int count, |
| 36 const ReadCompletionCallback& callback) OVERRIDE; | 34 const ReadCompletionCallback& callback) OVERRIDE; |
| 37 virtual void RecvFrom(int count, | 35 virtual void RecvFrom(int count, |
| 38 const RecvFromCompletionCallback& callback) OVERRIDE; | 36 const RecvFromCompletionCallback& callback) OVERRIDE; |
| 39 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 37 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
| 40 int byte_count, | 38 int byte_count, |
| 41 const std::string& address, | 39 const std::string& address, |
| 42 int port, | 40 int port, |
| 43 const CompletionCallback& callback) OVERRIDE; | 41 const CompletionCallback& callback) OVERRIDE; |
| 44 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; | 42 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; |
| 45 virtual bool SetNoDelay(bool no_delay) OVERRIDE; | 43 virtual bool SetNoDelay(bool no_delay) OVERRIDE; |
| 46 | 44 |
| 47 static TCPSocket* CreateSocketForTesting( | 45 static SSLSocket* CreateSocketForTesting( |
| 48 net::TCPClientSocket* tcp_client_socket, | 46 net::TCPClientSocket* tcp_client_socket, |
| 49 APIResourceEventNotifier* event_notifier); | 47 APIResourceEventNotifier* event_notifier); |
| 50 | 48 |
| 51 protected: | 49 protected: |
| 52 virtual int WriteImpl(net::IOBuffer* io_buffer, | 50 virtual int WriteImpl(net::IOBuffer* io_buffer, |
| 53 int io_buffer_size, | 51 int io_buffer_size, |
| 54 const net::CompletionCallback& callback) OVERRIDE; | 52 const net::CompletionCallback& callback) OVERRIDE; |
| 55 | 53 |
| 54 virtual void OnWriteComplete(int result) OVERRIDE; | |
| 55 | |
| 56 private: | 56 private: |
| 57 enum SSLState { | |
| 58 SSLSTATE_NONE, | |
| 59 SSLSTATE_WAIT, | |
| 60 SSLSTATE_CONNECTED, | |
| 61 SSLSTATE_ERROR | |
| 62 }; | |
| 63 | |
| 57 void OnConnectComplete(int result); | 64 void OnConnectComplete(int result); |
| 65 void OnHandshakeComplete(int result); | |
| 58 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, | 66 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, |
| 59 int result); | 67 int result); |
| 60 | 68 |
| 61 TCPSocket(net::TCPClientSocket* tcp_client_socket, | 69 void AttemptSSLHandshake(); |
| 70 | |
| 71 SSLSocket(net::TCPClientSocket* tcp_client_socket, | |
| 62 APIResourceEventNotifier* event_notifier); | 72 APIResourceEventNotifier* event_notifier); |
| 63 | 73 |
| 74 // See remoting/jingle_glue/ssl_socket_adapter.h: | |
| 75 // |cert_verifier_| must be defined before |ssl_socket_| so that it's | |
| 76 // destroyed after |ssl_socket_|. | |
| 77 scoped_ptr<net::CertVerifier> cert_verifier_; | |
|
Ryan Sleevi
2012/07/09 20:55:45
drive-by: The CertVerifier should be passed in as
| |
| 78 scoped_ptr<net::SSLClientSocket> ssl_socket_; | |
| 64 scoped_ptr<net::TCPClientSocket> socket_; | 79 scoped_ptr<net::TCPClientSocket> socket_; |
| 65 | 80 |
| 81 SSLState ssl_state_; | |
| 82 int ssl_port_; | |
| 83 std::string ssl_hostname_; | |
| 84 | |
| 66 CompletionCallback connect_callback_; | 85 CompletionCallback connect_callback_; |
| 86 CompletionCallback handshake_callback_; | |
| 67 | 87 |
| 68 ReadCompletionCallback read_callback_; | 88 ReadCompletionCallback read_callback_; |
| 69 }; | 89 }; |
| 70 | 90 |
| 71 } // namespace extensions | 91 } // namespace extensions |
| 72 | 92 |
| 73 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ | 93 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SSL_SOCKET_H_ |
| OLD | NEW |