PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/external/chromium/net/http/http_proxy_client_socket_pool.h

https://gitlab.com/brian0218/rk3066_r-box_android4.2.2_sdk
C Header | 265 lines | 192 code | 50 blank | 23 comment | 0 complexity | f3e0f8638d05fc1caf588eeadd95e5bf MD5 | raw file
  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
  3. // found in the LICENSE file.
  4. #ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_
  5. #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_
  6. #pragma once
  7. #include <string>
  8. #include "base/basictypes.h"
  9. #include "base/memory/ref_counted.h"
  10. #include "base/memory/scoped_ptr.h"
  11. #include "base/time.h"
  12. #include "net/base/host_port_pair.h"
  13. #include "net/http/http_auth.h"
  14. #include "net/http/http_response_info.h"
  15. #include "net/http/proxy_client_socket.h"
  16. #include "net/socket/client_socket_pool_base.h"
  17. #include "net/socket/client_socket_pool_histograms.h"
  18. #include "net/socket/client_socket_pool.h"
  19. namespace net {
  20. class HostResolver;
  21. class HttpAuthCache;
  22. class HttpAuthHandlerFactory;
  23. class SSLClientSocketPool;
  24. class SSLSocketParams;
  25. class SpdySessionPool;
  26. class SpdyStream;
  27. class TransportClientSocketPool;
  28. class TransportSocketParams;
  29. // HttpProxySocketParams only needs the socket params for one of the proxy
  30. // types. The other param must be NULL. When using an HTTP Proxy,
  31. // |transport_params| must be set. When using an HTTPS Proxy, |ssl_params|
  32. // must be set.
  33. class HttpProxySocketParams : public base::RefCounted<HttpProxySocketParams> {
  34. public:
  35. HttpProxySocketParams(
  36. const scoped_refptr<TransportSocketParams>& transport_params,
  37. const scoped_refptr<SSLSocketParams>& ssl_params,
  38. const GURL& request_url,
  39. const std::string& user_agent,
  40. HostPortPair endpoint,
  41. HttpAuthCache* http_auth_cache,
  42. HttpAuthHandlerFactory* http_auth_handler_factory,
  43. SpdySessionPool* spdy_session_pool,
  44. bool tunnel);
  45. const scoped_refptr<TransportSocketParams>& transport_params() const {
  46. return transport_params_;
  47. }
  48. const scoped_refptr<SSLSocketParams>& ssl_params() const {
  49. return ssl_params_;
  50. }
  51. const GURL& request_url() const { return request_url_; }
  52. const std::string& user_agent() const { return user_agent_; }
  53. const HostPortPair& endpoint() const { return endpoint_; }
  54. HttpAuthCache* http_auth_cache() const { return http_auth_cache_; }
  55. HttpAuthHandlerFactory* http_auth_handler_factory() const {
  56. return http_auth_handler_factory_;
  57. }
  58. SpdySessionPool* spdy_session_pool() {
  59. return spdy_session_pool_;
  60. }
  61. const HostResolver::RequestInfo& destination() const;
  62. bool tunnel() const { return tunnel_; }
  63. bool ignore_limits() const { return ignore_limits_; }
  64. #ifdef ANDROID
  65. // Gets the UID of the calling process
  66. bool getUID(uid_t *uid) const;
  67. void setUID(uid_t uid);
  68. #endif
  69. private:
  70. friend class base::RefCounted<HttpProxySocketParams>;
  71. ~HttpProxySocketParams();
  72. const scoped_refptr<TransportSocketParams> transport_params_;
  73. const scoped_refptr<SSLSocketParams> ssl_params_;
  74. SpdySessionPool* spdy_session_pool_;
  75. const GURL request_url_;
  76. const std::string user_agent_;
  77. const HostPortPair endpoint_;
  78. HttpAuthCache* const http_auth_cache_;
  79. HttpAuthHandlerFactory* const http_auth_handler_factory_;
  80. const bool tunnel_;
  81. bool ignore_limits_;
  82. DISALLOW_COPY_AND_ASSIGN(HttpProxySocketParams);
  83. };
  84. // HttpProxyConnectJob optionally establishes a tunnel through the proxy
  85. // server after connecting the underlying transport socket.
  86. class HttpProxyConnectJob : public ConnectJob {
  87. public:
  88. HttpProxyConnectJob(const std::string& group_name,
  89. const scoped_refptr<HttpProxySocketParams>& params,
  90. const base::TimeDelta& timeout_duration,
  91. TransportClientSocketPool* transport_pool,
  92. SSLClientSocketPool* ssl_pool,
  93. HostResolver* host_resolver,
  94. Delegate* delegate,
  95. NetLog* net_log);
  96. virtual ~HttpProxyConnectJob();
  97. // ConnectJob methods.
  98. virtual LoadState GetLoadState() const;
  99. virtual void GetAdditionalErrorState(ClientSocketHandle* handle);
  100. private:
  101. enum State {
  102. STATE_TCP_CONNECT,
  103. STATE_TCP_CONNECT_COMPLETE,
  104. STATE_SSL_CONNECT,
  105. STATE_SSL_CONNECT_COMPLETE,
  106. STATE_HTTP_PROXY_CONNECT,
  107. STATE_HTTP_PROXY_CONNECT_COMPLETE,
  108. STATE_SPDY_PROXY_CREATE_STREAM,
  109. STATE_SPDY_PROXY_CREATE_STREAM_COMPLETE,
  110. STATE_SPDY_PROXY_CONNECT_COMPLETE,
  111. STATE_NONE,
  112. };
  113. void OnIOComplete(int result);
  114. // Runs the state transition loop.
  115. int DoLoop(int result);
  116. // Connecting to HTTP Proxy
  117. int DoTransportConnect();
  118. int DoTransportConnectComplete(int result);
  119. // Connecting to HTTPS Proxy
  120. int DoSSLConnect();
  121. int DoSSLConnectComplete(int result);
  122. int DoHttpProxyConnect();
  123. int DoHttpProxyConnectComplete(int result);
  124. int DoSpdyProxyCreateStream();
  125. int DoSpdyProxyCreateStreamComplete(int result);
  126. // Begins the tcp connection and the optional Http proxy tunnel. If the
  127. // request is not immediately servicable (likely), the request will return
  128. // ERR_IO_PENDING. An OK return from this function or the callback means
  129. // that the connection is established; ERR_PROXY_AUTH_REQUESTED means
  130. // that the tunnel needs authentication credentials, the socket will be
  131. // returned in this case, and must be release back to the pool; or
  132. // a standard net error code will be returned.
  133. virtual int ConnectInternal();
  134. scoped_refptr<HttpProxySocketParams> params_;
  135. TransportClientSocketPool* const transport_pool_;
  136. SSLClientSocketPool* const ssl_pool_;
  137. HostResolver* const resolver_;
  138. State next_state_;
  139. CompletionCallbackImpl<HttpProxyConnectJob> callback_;
  140. scoped_ptr<ClientSocketHandle> transport_socket_handle_;
  141. scoped_ptr<ProxyClientSocket> transport_socket_;
  142. bool using_spdy_;
  143. HttpResponseInfo error_response_info_;
  144. scoped_refptr<SpdyStream> spdy_stream_;
  145. DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJob);
  146. };
  147. class HttpProxyClientSocketPool : public ClientSocketPool {
  148. public:
  149. HttpProxyClientSocketPool(
  150. int max_sockets,
  151. int max_sockets_per_group,
  152. ClientSocketPoolHistograms* histograms,
  153. HostResolver* host_resolver,
  154. TransportClientSocketPool* transport_pool,
  155. SSLClientSocketPool* ssl_pool,
  156. NetLog* net_log);
  157. virtual ~HttpProxyClientSocketPool();
  158. // ClientSocketPool methods:
  159. virtual int RequestSocket(const std::string& group_name,
  160. const void* connect_params,
  161. RequestPriority priority,
  162. ClientSocketHandle* handle,
  163. CompletionCallback* callback,
  164. const BoundNetLog& net_log);
  165. virtual void RequestSockets(const std::string& group_name,
  166. const void* params,
  167. int num_sockets,
  168. const BoundNetLog& net_log);
  169. virtual void CancelRequest(const std::string& group_name,
  170. ClientSocketHandle* handle);
  171. virtual void ReleaseSocket(const std::string& group_name,
  172. ClientSocket* socket,
  173. int id);
  174. virtual void Flush();
  175. virtual void CloseIdleSockets();
  176. virtual int IdleSocketCount() const;
  177. virtual int IdleSocketCountInGroup(const std::string& group_name) const;
  178. virtual LoadState GetLoadState(const std::string& group_name,
  179. const ClientSocketHandle* handle) const;
  180. virtual DictionaryValue* GetInfoAsValue(const std::string& name,
  181. const std::string& type,
  182. bool include_nested_pools) const;
  183. virtual base::TimeDelta ConnectionTimeout() const;
  184. virtual ClientSocketPoolHistograms* histograms() const;
  185. private:
  186. typedef ClientSocketPoolBase<HttpProxySocketParams> PoolBase;
  187. class HttpProxyConnectJobFactory : public PoolBase::ConnectJobFactory {
  188. public:
  189. HttpProxyConnectJobFactory(
  190. TransportClientSocketPool* transport_pool,
  191. SSLClientSocketPool* ssl_pool,
  192. HostResolver* host_resolver,
  193. NetLog* net_log);
  194. // ClientSocketPoolBase::ConnectJobFactory methods.
  195. virtual ConnectJob* NewConnectJob(const std::string& group_name,
  196. const PoolBase::Request& request,
  197. ConnectJob::Delegate* delegate) const;
  198. virtual base::TimeDelta ConnectionTimeout() const { return timeout_; }
  199. private:
  200. TransportClientSocketPool* const transport_pool_;
  201. SSLClientSocketPool* const ssl_pool_;
  202. HostResolver* const host_resolver_;
  203. NetLog* net_log_;
  204. base::TimeDelta timeout_;
  205. DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJobFactory);
  206. };
  207. TransportClientSocketPool* const transport_pool_;
  208. SSLClientSocketPool* const ssl_pool_;
  209. PoolBase base_;
  210. DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocketPool);
  211. };
  212. REGISTER_SOCKET_PARAMS_FOR_POOL(HttpProxyClientSocketPool,
  213. HttpProxySocketParams);
  214. } // namespace net
  215. #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_