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_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ |
6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ | 6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
16 #include "net/http/http_auth.h" | 16 #include "net/http/http_auth.h" |
17 #include "net/socket/client_socket_pool_base.h" | 17 #include "net/socket/client_socket_pool_base.h" |
18 #include "net/socket/client_socket_pool_histograms.h" | 18 #include "net/socket/client_socket_pool_histograms.h" |
19 #include "net/socket/client_socket_pool.h" | 19 #include "net/socket/client_socket_pool.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 class HostResolver; | 23 class HostResolver; |
24 class HttpNetworkSession; | 24 class HttpNetworkSession; |
| 25 class SSLClientSocketPool; |
| 26 class SSLSocketParams; |
25 class TCPClientSocketPool; | 27 class TCPClientSocketPool; |
26 class TCPSocketParams; | 28 class TCPSocketParams; |
27 | 29 |
| 30 // HttpProxySocketParams only needs the socket params for one of the proxy |
| 31 // types. The other param must be NULL. When using an HTTP Proxy, |
| 32 // |tcp_params| must be set. When using an HTTPS Proxy, |ssl_params| |
| 33 // must be set. |
28 class HttpProxySocketParams : public base::RefCounted<HttpProxySocketParams> { | 34 class HttpProxySocketParams : public base::RefCounted<HttpProxySocketParams> { |
29 public: | 35 public: |
30 HttpProxySocketParams(const scoped_refptr<TCPSocketParams>& proxy_server, | 36 HttpProxySocketParams(const scoped_refptr<TCPSocketParams>& tcp_params, |
| 37 const scoped_refptr<SSLSocketParams>& ssl_params, |
31 const GURL& request_url, | 38 const GURL& request_url, |
32 const std::string& user_agent, | 39 const std::string& user_agent, |
33 HostPortPair endpoint, | 40 HostPortPair endpoint, |
34 scoped_refptr<HttpNetworkSession> session, | 41 scoped_refptr<HttpNetworkSession> session, |
35 bool tunnel); | 42 bool tunnel); |
36 | 43 |
37 const scoped_refptr<TCPSocketParams>& tcp_params() const { | 44 const scoped_refptr<TCPSocketParams>& tcp_params() const { |
38 return tcp_params_; | 45 return tcp_params_; |
39 } | 46 } |
| 47 const scoped_refptr<SSLSocketParams>& ssl_params() const { |
| 48 return ssl_params_; |
| 49 } |
40 const GURL& request_url() const { return request_url_; } | 50 const GURL& request_url() const { return request_url_; } |
41 const std::string& user_agent() const { return user_agent_; } | 51 const std::string& user_agent() const { return user_agent_; } |
42 const HostPortPair& endpoint() const { return endpoint_; } | 52 const HostPortPair& endpoint() const { return endpoint_; } |
43 const scoped_refptr<HttpNetworkSession>& session() { | 53 const scoped_refptr<HttpNetworkSession>& session() { |
44 return session_; | 54 return session_; |
45 } | 55 } |
| 56 const HostResolver::RequestInfo& destination() const; |
46 bool tunnel() const { return tunnel_; } | 57 bool tunnel() const { return tunnel_; } |
47 | 58 |
48 private: | 59 private: |
49 friend class base::RefCounted<HttpProxySocketParams>; | 60 friend class base::RefCounted<HttpProxySocketParams>; |
50 ~HttpProxySocketParams(); | 61 ~HttpProxySocketParams(); |
51 | 62 |
52 const scoped_refptr<TCPSocketParams> tcp_params_; | 63 const scoped_refptr<TCPSocketParams> tcp_params_; |
| 64 const scoped_refptr<SSLSocketParams> ssl_params_; |
53 const GURL request_url_; | 65 const GURL request_url_; |
54 const std::string user_agent_; | 66 const std::string user_agent_; |
55 const HostPortPair endpoint_; | 67 const HostPortPair endpoint_; |
56 const scoped_refptr<HttpNetworkSession> session_; | 68 const scoped_refptr<HttpNetworkSession> session_; |
57 const bool tunnel_; | 69 const bool tunnel_; |
58 | 70 |
59 DISALLOW_COPY_AND_ASSIGN(HttpProxySocketParams); | 71 DISALLOW_COPY_AND_ASSIGN(HttpProxySocketParams); |
60 }; | 72 }; |
61 | 73 |
62 // HttpProxyConnectJob optionally establishes a tunnel through the proxy | 74 // HttpProxyConnectJob optionally establishes a tunnel through the proxy |
63 // server after connecting the underlying transport socket. | 75 // server after connecting the underlying transport socket. |
64 class HttpProxyConnectJob : public ConnectJob { | 76 class HttpProxyConnectJob : public ConnectJob { |
65 public: | 77 public: |
66 HttpProxyConnectJob(const std::string& group_name, | 78 HttpProxyConnectJob(const std::string& group_name, |
67 const scoped_refptr<HttpProxySocketParams>& params, | 79 const scoped_refptr<HttpProxySocketParams>& params, |
68 const base::TimeDelta& timeout_duration, | 80 const base::TimeDelta& timeout_duration, |
69 const scoped_refptr<TCPClientSocketPool>& tcp_pool, | 81 const scoped_refptr<TCPClientSocketPool>& tcp_pool, |
| 82 const scoped_refptr<SSLClientSocketPool>& ssl_pool, |
70 const scoped_refptr<HostResolver> &host_resolver, | 83 const scoped_refptr<HostResolver> &host_resolver, |
71 Delegate* delegate, | 84 Delegate* delegate, |
72 NetLog* net_log); | 85 NetLog* net_log); |
73 virtual ~HttpProxyConnectJob(); | 86 virtual ~HttpProxyConnectJob(); |
74 | 87 |
75 // ConnectJob methods. | 88 // ConnectJob methods. |
76 virtual LoadState GetLoadState() const; | 89 virtual LoadState GetLoadState() const; |
77 | 90 |
78 private: | 91 private: |
79 enum State { | 92 enum State { |
80 kStateTCPConnect, | 93 kStateTCPConnect, |
81 kStateTCPConnectComplete, | 94 kStateTCPConnectComplete, |
| 95 kStateSSLConnect, |
| 96 kStateSSLConnectComplete, |
82 kStateHttpProxyConnect, | 97 kStateHttpProxyConnect, |
83 kStateHttpProxyConnectComplete, | 98 kStateHttpProxyConnectComplete, |
84 kStateNone, | 99 kStateNone, |
85 }; | 100 }; |
86 | 101 |
87 // Begins the tcp connection and the optional Http proxy tunnel. If the | 102 // Begins the tcp connection and the optional Http proxy tunnel. If the |
88 // request is not immediately servicable (likely), the request will return | 103 // request is not immediately servicable (likely), the request will return |
89 // ERR_IO_PENDING. An OK return from this function or the callback means | 104 // ERR_IO_PENDING. An OK return from this function or the callback means |
90 // that the connection is established; ERR_PROXY_AUTH_REQUESTED means | 105 // that the connection is established; ERR_PROXY_AUTH_REQUESTED means |
91 // that the tunnel needs authentication credentials, the socket will be | 106 // that the tunnel needs authentication credentials, the socket will be |
92 // returned in this case, and must be release back to the pool; or | 107 // returned in this case, and must be release back to the pool; or |
93 // a standard net error code will be returned. | 108 // a standard net error code will be returned. |
94 virtual int ConnectInternal(); | 109 virtual int ConnectInternal(); |
95 | 110 |
96 void OnIOComplete(int result); | 111 void OnIOComplete(int result); |
97 | 112 |
98 // Runs the state transition loop. | 113 // Runs the state transition loop. |
99 int DoLoop(int result); | 114 int DoLoop(int result); |
100 | 115 |
| 116 // Connecting to HTTP Proxy |
101 int DoTCPConnect(); | 117 int DoTCPConnect(); |
102 int DoTCPConnectComplete(int result); | 118 int DoTCPConnectComplete(int result); |
| 119 // Connecting to HTTPS Proxy |
| 120 int DoSSLConnect(); |
| 121 int DoSSLConnectComplete(int result); |
| 122 |
103 int DoHttpProxyConnect(); | 123 int DoHttpProxyConnect(); |
104 int DoHttpProxyConnectComplete(int result); | 124 int DoHttpProxyConnectComplete(int result); |
105 | 125 |
106 scoped_refptr<HttpProxySocketParams> params_; | 126 scoped_refptr<HttpProxySocketParams> params_; |
107 const scoped_refptr<TCPClientSocketPool> tcp_pool_; | 127 const scoped_refptr<TCPClientSocketPool> tcp_pool_; |
| 128 const scoped_refptr<SSLClientSocketPool> ssl_pool_; |
108 const scoped_refptr<HostResolver> resolver_; | 129 const scoped_refptr<HostResolver> resolver_; |
109 | 130 |
110 State next_state_; | 131 State next_state_; |
111 CompletionCallbackImpl<HttpProxyConnectJob> callback_; | 132 CompletionCallbackImpl<HttpProxyConnectJob> callback_; |
112 scoped_ptr<ClientSocketHandle> tcp_socket_handle_; | 133 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
113 scoped_ptr<ClientSocket> socket_; | 134 scoped_ptr<ClientSocket> transport_socket_; |
114 | 135 |
115 DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJob); | 136 DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJob); |
116 }; | 137 }; |
117 | 138 |
118 class HttpProxyClientSocketPool : public ClientSocketPool { | 139 class HttpProxyClientSocketPool : public ClientSocketPool { |
119 public: | 140 public: |
120 HttpProxyClientSocketPool( | 141 HttpProxyClientSocketPool( |
121 int max_sockets, | 142 int max_sockets, |
122 int max_sockets_per_group, | 143 int max_sockets_per_group, |
123 const scoped_refptr<ClientSocketPoolHistograms>& histograms, | 144 const scoped_refptr<ClientSocketPoolHistograms>& histograms, |
124 const scoped_refptr<HostResolver>& host_resolver, | 145 const scoped_refptr<HostResolver>& host_resolver, |
125 const scoped_refptr<TCPClientSocketPool>& tcp_pool, | 146 const scoped_refptr<TCPClientSocketPool>& tcp_pool, |
| 147 const scoped_refptr<SSLClientSocketPool>& ssl_pool, |
126 NetLog* net_log); | 148 NetLog* net_log); |
127 | 149 |
128 // ClientSocketPool methods: | 150 // ClientSocketPool methods: |
129 virtual int RequestSocket(const std::string& group_name, | 151 virtual int RequestSocket(const std::string& group_name, |
130 const void* connect_params, | 152 const void* connect_params, |
131 RequestPriority priority, | 153 RequestPriority priority, |
132 ClientSocketHandle* handle, | 154 ClientSocketHandle* handle, |
133 CompletionCallback* callback, | 155 CompletionCallback* callback, |
134 const BoundNetLog& net_log); | 156 const BoundNetLog& net_log); |
135 | 157 |
(...skipping 28 matching lines...) Expand all Loading... |
164 protected: | 186 protected: |
165 virtual ~HttpProxyClientSocketPool(); | 187 virtual ~HttpProxyClientSocketPool(); |
166 | 188 |
167 private: | 189 private: |
168 typedef ClientSocketPoolBase<HttpProxySocketParams> PoolBase; | 190 typedef ClientSocketPoolBase<HttpProxySocketParams> PoolBase; |
169 | 191 |
170 class HttpProxyConnectJobFactory : public PoolBase::ConnectJobFactory { | 192 class HttpProxyConnectJobFactory : public PoolBase::ConnectJobFactory { |
171 public: | 193 public: |
172 HttpProxyConnectJobFactory( | 194 HttpProxyConnectJobFactory( |
173 const scoped_refptr<TCPClientSocketPool>& tcp_pool, | 195 const scoped_refptr<TCPClientSocketPool>& tcp_pool, |
| 196 const scoped_refptr<SSLClientSocketPool>& ssl_pool, |
174 HostResolver* host_resolver, | 197 HostResolver* host_resolver, |
175 NetLog* net_log) | 198 NetLog* net_log); |
176 : tcp_pool_(tcp_pool), | |
177 host_resolver_(host_resolver), | |
178 net_log_(net_log) {} | |
179 | |
180 virtual ~HttpProxyConnectJobFactory() {} | |
181 | 199 |
182 // ClientSocketPoolBase::ConnectJobFactory methods. | 200 // ClientSocketPoolBase::ConnectJobFactory methods. |
183 virtual ConnectJob* NewConnectJob(const std::string& group_name, | 201 virtual ConnectJob* NewConnectJob(const std::string& group_name, |
184 const PoolBase::Request& request, | 202 const PoolBase::Request& request, |
185 ConnectJob::Delegate* delegate) const; | 203 ConnectJob::Delegate* delegate) const; |
186 | 204 |
187 virtual base::TimeDelta ConnectionTimeout() const; | 205 virtual base::TimeDelta ConnectionTimeout() const { return timeout_; } |
188 | 206 |
189 private: | 207 private: |
190 const scoped_refptr<TCPClientSocketPool> tcp_pool_; | 208 const scoped_refptr<TCPClientSocketPool> tcp_pool_; |
| 209 const scoped_refptr<SSLClientSocketPool> ssl_pool_; |
191 const scoped_refptr<HostResolver> host_resolver_; | 210 const scoped_refptr<HostResolver> host_resolver_; |
192 NetLog* net_log_; | 211 NetLog* net_log_; |
| 212 base::TimeDelta timeout_; |
193 | 213 |
194 DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJobFactory); | 214 DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJobFactory); |
195 }; | 215 }; |
196 | 216 |
197 PoolBase base_; | 217 PoolBase base_; |
198 | 218 |
199 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocketPool); | 219 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocketPool); |
200 }; | 220 }; |
201 | 221 |
202 REGISTER_SOCKET_PARAMS_FOR_POOL(HttpProxyClientSocketPool, | 222 REGISTER_SOCKET_PARAMS_FOR_POOL(HttpProxyClientSocketPool, |
203 HttpProxySocketParams); | 223 HttpProxySocketParams); |
204 | 224 |
205 } // namespace net | 225 } // namespace net |
206 | 226 |
207 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ | 227 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |