| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 5 #ifndef NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
| 6 #define NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 6 #define NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/linked_ptr.h" | 13 #include "base/linked_ptr.h" |
| 14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/task.h" | 17 #include "base/task.h" |
| 18 #include "net/base/address_list.h" | 18 #include "net/base/address_list.h" |
| 19 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
| 20 #include "net/base/host_port_pair.h" |
| 20 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 21 #include "net/base/net_log.h" | 22 #include "net/base/net_log.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "net/base/ssl_config_service.h" | 24 #include "net/base/ssl_config_service.h" |
| 24 #include "net/http/http_auth.h" | 25 #include "net/http/http_auth.h" |
| 25 #include "net/http/http_auth_cache.h" | 26 #include "net/http/http_auth_cache.h" |
| 26 #include "net/http/http_auth_handler.h" | 27 #include "net/http/http_auth_handler.h" |
| 27 #include "net/proxy/proxy_service.h" | 28 #include "net/proxy/proxy_service.h" |
| 28 #include "net/socket/tcp_client_socket.h" | 29 #include "net/socket/tcp_client_socket.h" |
| 29 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 30 | 31 |
| 31 namespace net { | 32 namespace net { |
| 32 | 33 |
| 33 class AuthChallengeInfo; | 34 class AuthChallengeInfo; |
| 34 class ClientSocketFactory; | 35 class ClientSocketFactory; |
| 35 class HostResolver; | 36 class HostResolver; |
| 36 class HttpAuthHandlerFactory; | 37 class HttpAuthHandlerFactory; |
| 38 class ProxyServer; |
| 37 class SSLConfigService; | 39 class SSLConfigService; |
| 38 class SingleRequestHostResolver; | 40 class SingleRequestHostResolver; |
| 39 class SocketStreamMetrics; | 41 class SocketStreamMetrics; |
| 40 | 42 |
| 41 // SocketStream is used to implement Web Sockets. | 43 // SocketStream is used to implement Web Sockets. |
| 42 // It provides plain full-duplex stream with proxy and SSL support. | 44 // It provides plain full-duplex stream with proxy and SSL support. |
| 43 // For proxy authentication, only basic mechanisum is supported. It will try | 45 // For proxy authentication, only basic mechanisum is supported. It will try |
| 44 // authentication identity for proxy URL first. If server requires proxy | 46 // authentication identity for proxy URL first. If server requires proxy |
| 45 // authentication, it will try authentication identity for realm that server | 47 // authentication, it will try authentication identity for realm that server |
| 46 // requests. | 48 // requests. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // Should be used for response of OnAuthRequired. | 137 // Should be used for response of OnAuthRequired. |
| 136 virtual void RestartWithAuth( | 138 virtual void RestartWithAuth( |
| 137 const string16& username, | 139 const string16& username, |
| 138 const string16& password); | 140 const string16& password); |
| 139 | 141 |
| 140 // Detach delegate. Call before delegate is deleted. | 142 // Detach delegate. Call before delegate is deleted. |
| 141 // Once delegate is detached, close the socket stream and never call delegate | 143 // Once delegate is detached, close the socket stream and never call delegate |
| 142 // back. | 144 // back. |
| 143 virtual void DetachDelegate(); | 145 virtual void DetachDelegate(); |
| 144 | 146 |
| 147 const HostPortPair& GetHostPortPair() const; |
| 148 const ProxyServer& proxy_server() const; |
| 149 void SwitchToSpdy(); |
| 150 |
| 145 // Sets an alternative HostResolver. For testing purposes only. | 151 // Sets an alternative HostResolver. For testing purposes only. |
| 146 void SetHostResolver(HostResolver* host_resolver); | 152 void SetHostResolver(HostResolver* host_resolver); |
| 147 | 153 |
| 148 // Sets an alternative ClientSocketFactory. Doesn't take ownership of | 154 // Sets an alternative ClientSocketFactory. Doesn't take ownership of |
| 149 // |factory|. For testing purposes only. | 155 // |factory|. For testing purposes only. |
| 150 void SetClientSocketFactory(ClientSocketFactory* factory); | 156 void SetClientSocketFactory(ClientSocketFactory* factory); |
| 151 | 157 |
| 152 protected: | 158 protected: |
| 153 friend class base::RefCountedThreadSafe<SocketStream>; | 159 friend class base::RefCountedThreadSafe<SocketStream>; |
| 154 virtual ~SocketStream(); | 160 virtual ~SocketStream(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 STATE_TCP_CONNECT_COMPLETE, | 201 STATE_TCP_CONNECT_COMPLETE, |
| 196 STATE_WRITE_TUNNEL_HEADERS, | 202 STATE_WRITE_TUNNEL_HEADERS, |
| 197 STATE_WRITE_TUNNEL_HEADERS_COMPLETE, | 203 STATE_WRITE_TUNNEL_HEADERS_COMPLETE, |
| 198 STATE_READ_TUNNEL_HEADERS, | 204 STATE_READ_TUNNEL_HEADERS, |
| 199 STATE_READ_TUNNEL_HEADERS_COMPLETE, | 205 STATE_READ_TUNNEL_HEADERS_COMPLETE, |
| 200 STATE_SOCKS_CONNECT, | 206 STATE_SOCKS_CONNECT, |
| 201 STATE_SOCKS_CONNECT_COMPLETE, | 207 STATE_SOCKS_CONNECT_COMPLETE, |
| 202 STATE_SSL_CONNECT, | 208 STATE_SSL_CONNECT, |
| 203 STATE_SSL_CONNECT_COMPLETE, | 209 STATE_SSL_CONNECT_COMPLETE, |
| 204 STATE_READ_WRITE, | 210 STATE_READ_WRITE, |
| 211 STATE_SPDY, |
| 205 STATE_AUTH_REQUIRED, | 212 STATE_AUTH_REQUIRED, |
| 206 STATE_CLOSE, | 213 STATE_CLOSE, |
| 207 }; | 214 }; |
| 208 | 215 |
| 209 enum ProxyMode { | 216 enum ProxyMode { |
| 210 kDirectConnection, // If using a direct connection | 217 kDirectConnection, // If using a direct connection |
| 211 kTunnelProxy, // If using a tunnel (CONNECT method as HTTPS) | 218 kTunnelProxy, // If using a tunnel (CONNECT method as HTTPS) |
| 212 kSOCKSProxy, // If using a SOCKS proxy | 219 kSOCKSProxy, // If using a SOCKS proxy |
| 213 }; | 220 }; |
| 214 | 221 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 245 int DoTcpConnectComplete(int result); | 252 int DoTcpConnectComplete(int result); |
| 246 int DoWriteTunnelHeaders(); | 253 int DoWriteTunnelHeaders(); |
| 247 int DoWriteTunnelHeadersComplete(int result); | 254 int DoWriteTunnelHeadersComplete(int result); |
| 248 int DoReadTunnelHeaders(); | 255 int DoReadTunnelHeaders(); |
| 249 int DoReadTunnelHeadersComplete(int result); | 256 int DoReadTunnelHeadersComplete(int result); |
| 250 int DoSOCKSConnect(); | 257 int DoSOCKSConnect(); |
| 251 int DoSOCKSConnectComplete(int result); | 258 int DoSOCKSConnectComplete(int result); |
| 252 int DoSSLConnect(); | 259 int DoSSLConnect(); |
| 253 int DoSSLConnectComplete(int result); | 260 int DoSSLConnectComplete(int result); |
| 254 int DoReadWrite(int result); | 261 int DoReadWrite(int result); |
| 262 int DoSpdy(); |
| 255 | 263 |
| 256 GURL ProxyAuthOrigin() const; | 264 GURL ProxyAuthOrigin() const; |
| 257 int HandleAuthChallenge(const HttpResponseHeaders* headers); | 265 int HandleAuthChallenge(const HttpResponseHeaders* headers); |
| 258 void DoAuthRequired(); | 266 void DoAuthRequired(); |
| 259 void DoRestartWithAuth(); | 267 void DoRestartWithAuth(); |
| 260 | 268 |
| 261 int HandleCertificateError(int result); | 269 int HandleCertificateError(int result); |
| 262 | 270 |
| 263 SSLConfigService* ssl_config_service() const; | 271 SSLConfigService* ssl_config_service() const; |
| 264 ProxyService* proxy_service() const; | 272 ProxyService* proxy_service() const; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 290 | 298 |
| 291 scoped_refptr<RequestHeaders> tunnel_request_headers_; | 299 scoped_refptr<RequestHeaders> tunnel_request_headers_; |
| 292 size_t tunnel_request_headers_bytes_sent_; | 300 size_t tunnel_request_headers_bytes_sent_; |
| 293 scoped_refptr<ResponseHeaders> tunnel_response_headers_; | 301 scoped_refptr<ResponseHeaders> tunnel_response_headers_; |
| 294 int tunnel_response_headers_capacity_; | 302 int tunnel_response_headers_capacity_; |
| 295 int tunnel_response_headers_len_; | 303 int tunnel_response_headers_len_; |
| 296 | 304 |
| 297 // Use the same number as HttpNetworkTransaction::kMaxHeaderBufSize. | 305 // Use the same number as HttpNetworkTransaction::kMaxHeaderBufSize. |
| 298 enum { kMaxTunnelResponseHeadersSize = 32768 }; // 32 kilobytes. | 306 enum { kMaxTunnelResponseHeadersSize = 32768 }; // 32 kilobytes. |
| 299 | 307 |
| 308 // The hostname and port of the endpoint. This is not necessarily the one |
| 309 // specified by the URL, due to Alternate-Protocol or fixed testing ports. |
| 310 HostPortPair endpoint_; |
| 311 |
| 300 scoped_ptr<SingleRequestHostResolver> resolver_; | 312 scoped_ptr<SingleRequestHostResolver> resolver_; |
| 301 AddressList addresses_; | 313 AddressList addresses_; |
| 302 scoped_ptr<ClientSocket> socket_; | 314 scoped_ptr<ClientSocket> socket_; |
| 303 | 315 |
| 304 SSLConfig ssl_config_; | 316 SSLConfig ssl_config_; |
| 305 | 317 |
| 306 CompletionCallbackImpl<SocketStream> io_callback_; | 318 CompletionCallbackImpl<SocketStream> io_callback_; |
| 307 CompletionCallbackImpl<SocketStream> read_callback_; | 319 CompletionCallbackImpl<SocketStream> read_callback_; |
| 308 CompletionCallbackImpl<SocketStream> write_callback_; | 320 CompletionCallbackImpl<SocketStream> write_callback_; |
| 309 | 321 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 326 bool server_closed_; | 338 bool server_closed_; |
| 327 | 339 |
| 328 scoped_ptr<SocketStreamMetrics> metrics_; | 340 scoped_ptr<SocketStreamMetrics> metrics_; |
| 329 | 341 |
| 330 DISALLOW_COPY_AND_ASSIGN(SocketStream); | 342 DISALLOW_COPY_AND_ASSIGN(SocketStream); |
| 331 }; | 343 }; |
| 332 | 344 |
| 333 } // namespace net | 345 } // namespace net |
| 334 | 346 |
| 335 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 347 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
| OLD | NEW |