1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_WRAPPER_H_
#define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_WRAPPER_H_
#include <string>
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "net/base/completion_callback.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_timing_info.h"
#include "net/http/http_auth_controller.h"
#include "net/http/proxy_client_socket.h"
#include "net/log/net_log.h"
#include "net/socket/next_proto.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/ssl_client_socket_pool.h"
#include "net/socket/transport_client_socket_pool.h"
#include "net/spdy/spdy_session.h"
namespace net {
class ClientSocketHandle;
class IOBuffer;
class HttpAuthCache;
class HttpResponseInfo;
class HttpStream;
class IOBuffer;
class ProxyDelegate;
class SpdySessionPool;
class SSLClientSocketPool;
class TransportClientSocketPool;
// Class that establishes connections by calling into the lower layer socket
// pools, creates a HttpProxyClientSocket / SpdyProxyClientSocket, and then
// wraps the resulting socket.
//
// This class is needed to handle auth state across multiple connection. On
// auth challenge, this class retains auth state in its AuthController, and can
// either send the auth response to the old connection, or establish a new
// connection and send the response there.
//
// TODO(mmenke): Ideally, we'd have a central location store auth state across
// multiple connections to the same server instead.
class HttpProxyClientSocketWrapper : public ProxyClientSocket {
public:
HttpProxyClientSocketWrapper(
const std::string& group_name,
RequestPriority priority,
base::TimeDelta connect_timeout_duration,
base::TimeDelta proxy_negotiation_timeout_duration,
TransportClientSocketPool* transport_pool,
SSLClientSocketPool* ssl_pool,
const scoped_refptr<TransportSocketParams>& transport_params,
const scoped_refptr<SSLSocketParams>& ssl_params,
const std::string& user_agent,
const HostPortPair& endpoint,
HttpAuthCache* http_auth_cache,
HttpAuthHandlerFactory* http_auth_handler_factory,
SpdySessionPool* spdy_session_pool,
bool tunnel,
ProxyDelegate* proxy_delegate,
const BoundNetLog& net_log);
// On destruction Disconnect() is called.
~HttpProxyClientSocketWrapper() override;
// Returns load state while establishing a connection. Returns
// LOAD_STATE_IDLE at other times.
LoadState GetConnectLoadState() const;
scoped_ptr<HttpResponseInfo> GetAdditionalErrorState();
// ProxyClientSocket implementation.
const HttpResponseInfo* GetConnectResponseInfo() const override;
HttpStream* CreateConnectResponseStream() override;
int RestartWithAuth(const CompletionCallback& callback) override;
const scoped_refptr<HttpAuthController>& GetAuthController() const override;
bool IsUsingSpdy() const override;
NextProto GetProtocolNegotiated() const override;
// StreamSocket implementation.
int Connect(const CompletionCallback& callback) override;
void Disconnect() override;
bool IsConnected() const override;
bool IsConnectedAndIdle() const override;
const BoundNetLog& NetLog() const override;
void SetSubresourceSpeculation() override;
void SetOmniboxSpeculation() override;
bool WasEverUsed() const override;
bool UsingTCPFastOpen() const override;
bool WasNpnNegotiated() const override;
NextProto GetNegotiatedProtocol() const override;
bool GetSSLInfo(SSLInfo* ssl_info) override;
void GetConnectionAttempts(ConnectionAttempts* out) const override;
void ClearConnectionAttempts() override;
void AddConnectionAttempts(const ConnectionAttempts& attempts) override;
int64_t GetTotalReceivedBytes() const override;
// Socket implementation.
int Read(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
int Write(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
int SetReceiveBufferSize(int32 size) override;
int SetSendBufferSize(int32 size) override;
int GetPeerAddress(IPEndPoint* address) const override;
int GetLocalAddress(IPEndPoint* address) const override;
private:
enum State {
STATE_BEGIN_CONNECT,
STATE_TCP_CONNECT,
STATE_TCP_CONNECT_COMPLETE,
STATE_SSL_CONNECT,
STATE_SSL_CONNECT_COMPLETE,
STATE_HTTP_PROXY_CONNECT,
STATE_HTTP_PROXY_CONNECT_COMPLETE,
STATE_SPDY_PROXY_CREATE_STREAM,
STATE_SPDY_PROXY_CREATE_STREAM_COMPLETE,
STATE_SPDY_PROXY_CONNECT_COMPLETE,
STATE_RESTART_WITH_AUTH,
STATE_RESTART_WITH_AUTH_COMPLETE,
STATE_NONE,
};
void OnIOComplete(int result);
// Runs the state transition loop.
int DoLoop(int result);
// Determine if need to go through TCP or SSL path.
int DoBeginConnect();
// Connecting to HTTP Proxy
int DoTransportConnect();
int DoTransportConnectComplete(int result);
// Connecting to HTTPS Proxy
int DoSSLConnect();
int DoSSLConnectComplete(int result);
int DoHttpProxyConnect();
int DoHttpProxyConnectComplete(int result);
int DoSpdyProxyCreateStream();
int DoSpdyProxyCreateStreamComplete(int result);
int DoRestartWithAuth();
int DoRestartWithAuthComplete(int result);
void NotifyProxyDelegateOfCompletion(int result);
void SetConnectTimer(base::TimeDelta duration);
void ConnectTimeout();
const HostResolver::RequestInfo& GetDestination();
State next_state_;
const std::string group_name_;
RequestPriority priority_;
const base::TimeDelta connect_timeout_duration_;
const base::TimeDelta proxy_negotiation_timeout_duration_;
TransportClientSocketPool* const transport_pool_;
SSLClientSocketPool* const ssl_pool_;
const scoped_refptr<TransportSocketParams> transport_params_;
const scoped_refptr<SSLSocketParams> ssl_params_;
const std::string user_agent_;
const HostPortPair endpoint_;
HttpAuthCache* const http_auth_cache_;
HttpAuthHandlerFactory* const http_auth_handler_factory_;
SpdySessionPool* const spdy_session_pool_;
const bool tunnel_;
ProxyDelegate* const proxy_delegate_;
bool using_spdy_;
NextProto protocol_negotiated_;
scoped_ptr<HttpResponseInfo> error_response_info_;
scoped_ptr<ClientSocketHandle> transport_socket_handle_;
scoped_ptr<ProxyClientSocket> transport_socket_;
// Called when a connection is established. Also used when restarting with
// AUTH, which will invoke this when ready to restart, after reconnecting
// if necessary.
CompletionCallback connect_callback_;
SpdyStreamRequest spdy_stream_request_;
scoped_refptr<HttpAuthController> http_auth_controller_;
BoundNetLog net_log_;
base::OneShotTimer connect_timer_;
DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocketWrapper);
};
} // namespace net
#endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_WRAPPER_H_
|