Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / http / http_proxy_client_socket_pool.h
blob1440fc7eb67d37fcf4c6eedd5b7f1c295e6bdd78
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
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_
6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "net/base/host_port_pair.h"
16 #include "net/base/net_export.h"
17 #include "net/http/http_auth.h"
18 #include "net/http/http_response_info.h"
19 #include "net/http/proxy_client_socket.h"
20 #include "net/socket/client_socket_pool.h"
21 #include "net/socket/client_socket_pool_base.h"
22 #include "net/socket/ssl_client_socket.h"
23 #include "net/spdy/spdy_session.h"
25 namespace net {
27 class HttpAuthCache;
28 class HttpAuthHandlerFactory;
29 class ProxyDelegate;
30 class SSLClientSocketPool;
31 class SSLSocketParams;
32 class SpdySessionPool;
33 class SpdyStream;
34 class TransportClientSocketPool;
35 class TransportSocketParams;
37 // HttpProxySocketParams only needs the socket params for one of the proxy
38 // types. The other param must be NULL. When using an HTTP Proxy,
39 // |transport_params| must be set. When using an HTTPS Proxy, |ssl_params|
40 // must be set.
41 class NET_EXPORT_PRIVATE HttpProxySocketParams
42 : public base::RefCounted<HttpProxySocketParams> {
43 public:
44 HttpProxySocketParams(
45 const scoped_refptr<TransportSocketParams>& transport_params,
46 const scoped_refptr<SSLSocketParams>& ssl_params,
47 const std::string& user_agent,
48 const HostPortPair& endpoint,
49 HttpAuthCache* http_auth_cache,
50 HttpAuthHandlerFactory* http_auth_handler_factory,
51 SpdySessionPool* spdy_session_pool,
52 bool tunnel,
53 ProxyDelegate* proxy_delegate);
55 const scoped_refptr<TransportSocketParams>& transport_params() const {
56 return transport_params_;
58 const scoped_refptr<SSLSocketParams>& ssl_params() const {
59 return ssl_params_;
61 const std::string& user_agent() const { return user_agent_; }
62 const HostPortPair& endpoint() const { return endpoint_; }
63 HttpAuthCache* http_auth_cache() const { return http_auth_cache_; }
64 HttpAuthHandlerFactory* http_auth_handler_factory() const {
65 return http_auth_handler_factory_;
67 SpdySessionPool* spdy_session_pool() {
68 return spdy_session_pool_;
70 const HostResolver::RequestInfo& destination() const;
71 bool tunnel() const { return tunnel_; }
72 bool ignore_limits() const { return ignore_limits_; }
74 ProxyDelegate* proxy_delegate() const {
75 return proxy_delegate_;
78 private:
79 friend class base::RefCounted<HttpProxySocketParams>;
80 ~HttpProxySocketParams();
82 const scoped_refptr<TransportSocketParams> transport_params_;
83 const scoped_refptr<SSLSocketParams> ssl_params_;
84 SpdySessionPool* spdy_session_pool_;
85 const std::string user_agent_;
86 const HostPortPair endpoint_;
87 HttpAuthCache* const http_auth_cache_;
88 HttpAuthHandlerFactory* const http_auth_handler_factory_;
89 const bool tunnel_;
90 bool ignore_limits_;
91 ProxyDelegate* proxy_delegate_;
93 DISALLOW_COPY_AND_ASSIGN(HttpProxySocketParams);
96 // HttpProxyConnectJob optionally establishes a tunnel through the proxy
97 // server after connecting the underlying transport socket.
98 class HttpProxyConnectJob : public ConnectJob {
99 public:
100 HttpProxyConnectJob(const std::string& group_name,
101 RequestPriority priority,
102 const scoped_refptr<HttpProxySocketParams>& params,
103 const base::TimeDelta& timeout_duration,
104 TransportClientSocketPool* transport_pool,
105 SSLClientSocketPool* ssl_pool,
106 Delegate* delegate,
107 NetLog* net_log);
108 ~HttpProxyConnectJob() override;
110 // ConnectJob methods.
111 LoadState GetLoadState() const override;
113 void GetAdditionalErrorState(ClientSocketHandle* handle) override;
115 private:
116 enum State {
117 STATE_TCP_CONNECT,
118 STATE_TCP_CONNECT_COMPLETE,
119 STATE_SSL_CONNECT,
120 STATE_SSL_CONNECT_COMPLETE,
121 STATE_HTTP_PROXY_CONNECT,
122 STATE_HTTP_PROXY_CONNECT_COMPLETE,
123 STATE_SPDY_PROXY_CREATE_STREAM,
124 STATE_SPDY_PROXY_CREATE_STREAM_COMPLETE,
125 STATE_SPDY_PROXY_CONNECT_COMPLETE,
126 STATE_NONE,
129 void OnIOComplete(int result);
131 // Runs the state transition loop.
132 int DoLoop(int result);
134 // Connecting to HTTP Proxy
135 int DoTransportConnect();
136 int DoTransportConnectComplete(int result);
137 // Connecting to HTTPS Proxy
138 int DoSSLConnect();
139 int DoSSLConnectComplete(int result);
141 int DoHttpProxyConnect();
142 int DoHttpProxyConnectComplete(int result);
144 int DoSpdyProxyCreateStream();
145 int DoSpdyProxyCreateStreamComplete(int result);
147 void NotifyProxyDelegateOfCompletion(int result);
149 // Begins the tcp connection and the optional Http proxy tunnel. If the
150 // request is not immediately servicable (likely), the request will return
151 // ERR_IO_PENDING. An OK return from this function or the callback means
152 // that the connection is established; ERR_PROXY_AUTH_REQUESTED means
153 // that the tunnel needs authentication credentials, the socket will be
154 // returned in this case, and must be release back to the pool; or
155 // a standard net error code will be returned.
156 int ConnectInternal() override;
158 scoped_refptr<HttpProxySocketParams> params_;
159 TransportClientSocketPool* const transport_pool_;
160 SSLClientSocketPool* const ssl_pool_;
162 State next_state_;
163 CompletionCallback callback_;
164 scoped_ptr<ClientSocketHandle> transport_socket_handle_;
165 scoped_ptr<ProxyClientSocket> transport_socket_;
166 bool using_spdy_;
167 // Protocol negotiated with the server.
168 NextProto protocol_negotiated_;
170 HttpResponseInfo error_response_info_;
172 SpdyStreamRequest spdy_stream_request_;
174 base::WeakPtrFactory<HttpProxyConnectJob> weak_ptr_factory_;
176 DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJob);
179 class NET_EXPORT_PRIVATE HttpProxyClientSocketPool
180 : public ClientSocketPool,
181 public HigherLayeredPool {
182 public:
183 typedef HttpProxySocketParams SocketParams;
185 HttpProxyClientSocketPool(int max_sockets,
186 int max_sockets_per_group,
187 TransportClientSocketPool* transport_pool,
188 SSLClientSocketPool* ssl_pool,
189 NetLog* net_log);
191 ~HttpProxyClientSocketPool() override;
193 // ClientSocketPool implementation.
194 int RequestSocket(const std::string& group_name,
195 const void* connect_params,
196 RequestPriority priority,
197 ClientSocketHandle* handle,
198 const CompletionCallback& callback,
199 const BoundNetLog& net_log) override;
201 void RequestSockets(const std::string& group_name,
202 const void* params,
203 int num_sockets,
204 const BoundNetLog& net_log) override;
206 void CancelRequest(const std::string& group_name,
207 ClientSocketHandle* handle) override;
209 void ReleaseSocket(const std::string& group_name,
210 scoped_ptr<StreamSocket> socket,
211 int id) override;
213 void FlushWithError(int error) override;
215 void CloseIdleSockets() override;
217 int IdleSocketCount() const override;
219 int IdleSocketCountInGroup(const std::string& group_name) const override;
221 LoadState GetLoadState(const std::string& group_name,
222 const ClientSocketHandle* handle) const override;
224 scoped_ptr<base::DictionaryValue> GetInfoAsValue(
225 const std::string& name,
226 const std::string& type,
227 bool include_nested_pools) const override;
229 base::TimeDelta ConnectionTimeout() const override;
231 // LowerLayeredPool implementation.
232 bool IsStalled() const override;
234 void AddHigherLayeredPool(HigherLayeredPool* higher_pool) override;
236 void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) override;
238 // HigherLayeredPool implementation.
239 bool CloseOneIdleConnection() override;
241 private:
242 typedef ClientSocketPoolBase<HttpProxySocketParams> PoolBase;
244 class HttpProxyConnectJobFactory : public PoolBase::ConnectJobFactory {
245 public:
246 HttpProxyConnectJobFactory(TransportClientSocketPool* transport_pool,
247 SSLClientSocketPool* ssl_pool,
248 NetLog* net_log);
250 // ClientSocketPoolBase::ConnectJobFactory methods.
251 scoped_ptr<ConnectJob> NewConnectJob(
252 const std::string& group_name,
253 const PoolBase::Request& request,
254 ConnectJob::Delegate* delegate) const override;
256 base::TimeDelta ConnectionTimeout() const override;
258 private:
259 TransportClientSocketPool* const transport_pool_;
260 SSLClientSocketPool* const ssl_pool_;
261 NetLog* net_log_;
262 base::TimeDelta timeout_;
264 DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJobFactory);
267 TransportClientSocketPool* const transport_pool_;
268 SSLClientSocketPool* const ssl_pool_;
269 PoolBase base_;
271 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocketPool);
274 } // namespace net
276 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_