OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 REMOTING_JINGLE_GLUE_SSL_SOCKET_ADAPTER_H_ | 5 #ifndef REMOTING_JINGLE_GLUE_SSL_SOCKET_ADAPTER_H_ |
6 #define REMOTING_JINGLE_GLUE_SSL_SOCKET_ADAPTER_H_ | 6 #define REMOTING_JINGLE_GLUE_SSL_SOCKET_ADAPTER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 TransportSocket(talk_base::AsyncSocket* socket, | 34 TransportSocket(talk_base::AsyncSocket* socket, |
35 SSLSocketAdapter *ssl_adapter); | 35 SSLSocketAdapter *ssl_adapter); |
36 virtual ~TransportSocket(); | 36 virtual ~TransportSocket(); |
37 | 37 |
38 void set_addr(const talk_base::SocketAddress& addr) { | 38 void set_addr(const talk_base::SocketAddress& addr) { |
39 addr_ = addr; | 39 addr_ = addr; |
40 } | 40 } |
41 | 41 |
42 // net::StreamSocket implementation | 42 // net::StreamSocket implementation |
43 | 43 |
44 virtual int Connect(net::OldCompletionCallback* callback); | 44 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; |
45 virtual void Disconnect(); | 45 virtual void Disconnect() OVERRIDE; |
46 virtual bool IsConnected() const; | 46 virtual bool IsConnected() const OVERRIDE; |
47 virtual bool IsConnectedAndIdle() const; | 47 virtual bool IsConnectedAndIdle() const OVERRIDE; |
48 virtual int GetPeerAddress(net::AddressList* address) const; | 48 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; |
49 virtual int GetLocalAddress(net::IPEndPoint* address) const; | 49 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; |
50 virtual const net::BoundNetLog& NetLog() const; | 50 virtual const net::BoundNetLog& NetLog() const OVERRIDE; |
51 virtual void SetSubresourceSpeculation(); | 51 virtual void SetSubresourceSpeculation() OVERRIDE; |
52 virtual void SetOmniboxSpeculation(); | 52 virtual void SetOmniboxSpeculation() OVERRIDE; |
53 virtual bool WasEverUsed() const; | 53 virtual bool WasEverUsed() const OVERRIDE; |
54 virtual bool UsingTCPFastOpen() const; | 54 virtual bool UsingTCPFastOpen() const OVERRIDE; |
55 virtual int64 NumBytesRead() const; | 55 virtual int64 NumBytesRead() const OVERRIDE; |
56 virtual base::TimeDelta GetConnectTimeMicros() const; | 56 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
57 | 57 |
58 // net::Socket implementation | 58 // net::Socket implementation |
59 | 59 |
60 virtual int Read(net::IOBuffer* buf, int buf_len, | 60 virtual int Read(net::IOBuffer* buf, int buf_len, |
61 net::OldCompletionCallback* callback); | 61 net::OldCompletionCallback* callback) OVERRIDE; |
62 virtual int Write(net::IOBuffer* buf, int buf_len, | 62 virtual int Write(net::IOBuffer* buf, int buf_len, |
63 net::OldCompletionCallback* callback); | 63 net::OldCompletionCallback* callback) OVERRIDE; |
64 virtual bool SetReceiveBufferSize(int32 size); | 64 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
65 virtual bool SetSendBufferSize(int32 size); | 65 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
66 | 66 |
67 private: | 67 private: |
68 friend class SSLSocketAdapter; | 68 friend class SSLSocketAdapter; |
69 | 69 |
70 void OnReadEvent(talk_base::AsyncSocket* socket); | 70 void OnReadEvent(talk_base::AsyncSocket* socket); |
71 void OnWriteEvent(talk_base::AsyncSocket* socket); | 71 void OnWriteEvent(talk_base::AsyncSocket* socket); |
72 | 72 |
73 net::OldCompletionCallback* read_callback_; | 73 net::OldCompletionCallback* read_callback_; |
74 net::OldCompletionCallback* write_callback_; | 74 net::OldCompletionCallback* write_callback_; |
75 | 75 |
(...skipping 18 matching lines...) Expand all Loading... |
94 class SSLSocketAdapter : public talk_base::SSLAdapter { | 94 class SSLSocketAdapter : public talk_base::SSLAdapter { |
95 public: | 95 public: |
96 explicit SSLSocketAdapter(talk_base::AsyncSocket* socket); | 96 explicit SSLSocketAdapter(talk_base::AsyncSocket* socket); |
97 virtual ~SSLSocketAdapter(); | 97 virtual ~SSLSocketAdapter(); |
98 | 98 |
99 // StartSSL returns 0 if successful, or non-zero on failure. | 99 // StartSSL returns 0 if successful, or non-zero on failure. |
100 // If StartSSL is called while the socket is closed or connecting, the SSL | 100 // If StartSSL is called while the socket is closed or connecting, the SSL |
101 // negotiation will begin as soon as the socket connects. | 101 // negotiation will begin as soon as the socket connects. |
102 // | 102 // |
103 // restartable is not implemented, and must be set to false. | 103 // restartable is not implemented, and must be set to false. |
104 virtual int StartSSL(const char* hostname, bool restartable); | 104 virtual int StartSSL(const char* hostname, bool restartable) OVERRIDE; |
105 | 105 |
106 // Create the default SSL adapter for this platform. | 106 // Create the default SSL adapter for this platform. |
107 static SSLSocketAdapter* Create(AsyncSocket* socket); | 107 static SSLSocketAdapter* Create(AsyncSocket* socket); |
108 | 108 |
109 virtual int Send(const void* pv, size_t cb); | 109 virtual int Send(const void* pv, size_t cb) OVERRIDE; |
110 virtual int Recv(void* pv, size_t cb); | 110 virtual int Recv(void* pv, size_t cb) OVERRIDE; |
111 | 111 |
112 private: | 112 private: |
113 friend class TransportSocket; | 113 friend class TransportSocket; |
114 | 114 |
115 enum SSLState { | 115 enum SSLState { |
116 SSLSTATE_NONE, | 116 SSLSTATE_NONE, |
117 SSLSTATE_WAIT, | 117 SSLSTATE_WAIT, |
118 SSLSTATE_CONNECTED, | 118 SSLSTATE_CONNECTED, |
119 }; | 119 }; |
120 | 120 |
121 enum IOState { | 121 enum IOState { |
122 IOSTATE_NONE, | 122 IOSTATE_NONE, |
123 IOSTATE_PENDING, | 123 IOSTATE_PENDING, |
124 IOSTATE_COMPLETE, | 124 IOSTATE_COMPLETE, |
125 }; | 125 }; |
126 | 126 |
127 void OnConnected(int result); | 127 void OnConnected(int result); |
128 void OnRead(int result); | 128 void OnRead(int result); |
129 void OnWrite(int result); | 129 void OnWrite(int result); |
130 | 130 |
131 virtual void OnConnectEvent(talk_base::AsyncSocket* socket); | 131 virtual void OnConnectEvent(talk_base::AsyncSocket* socket) OVERRIDE; |
132 | 132 |
133 int BeginSSL(); | 133 int BeginSSL(); |
134 | 134 |
135 bool ignore_bad_cert_; | 135 bool ignore_bad_cert_; |
136 std::string hostname_; | 136 std::string hostname_; |
137 TransportSocket* transport_socket_; | 137 TransportSocket* transport_socket_; |
138 | 138 |
139 // |cert_verifier_| must be defined before |ssl_socket_|, so that | 139 // |cert_verifier_| must be defined before |ssl_socket_|, so that |
140 // it's destroyed after |ssl_socket_|. | 140 // it's destroyed after |ssl_socket_|. |
141 scoped_ptr<net::CertVerifier> cert_verifier_; | 141 scoped_ptr<net::CertVerifier> cert_verifier_; |
142 scoped_ptr<net::SSLClientSocket> ssl_socket_; | 142 scoped_ptr<net::SSLClientSocket> ssl_socket_; |
143 | 143 |
144 net::OldCompletionCallbackImpl<SSLSocketAdapter> connected_callback_; | 144 net::OldCompletionCallbackImpl<SSLSocketAdapter> connected_callback_; |
145 net::OldCompletionCallbackImpl<SSLSocketAdapter> read_callback_; | 145 net::OldCompletionCallbackImpl<SSLSocketAdapter> read_callback_; |
146 net::OldCompletionCallbackImpl<SSLSocketAdapter> write_callback_; | 146 net::OldCompletionCallbackImpl<SSLSocketAdapter> write_callback_; |
147 SSLState ssl_state_; | 147 SSLState ssl_state_; |
148 IOState read_state_; | 148 IOState read_state_; |
149 IOState write_state_; | 149 IOState write_state_; |
150 scoped_refptr<net::IOBuffer> transport_buf_; | 150 scoped_refptr<net::IOBuffer> transport_buf_; |
151 int data_transferred_; | 151 int data_transferred_; |
152 | 152 |
153 DISALLOW_COPY_AND_ASSIGN(SSLSocketAdapter); | 153 DISALLOW_COPY_AND_ASSIGN(SSLSocketAdapter); |
154 }; | 154 }; |
155 | 155 |
156 } // namespace remoting | 156 } // namespace remoting |
157 | 157 |
158 #endif // REMOTING_JINGLE_GLUE_SSL_SOCKET_ADAPTER_H_ | 158 #endif // REMOTING_JINGLE_GLUE_SSL_SOCKET_ADAPTER_H_ |
OLD | NEW |