OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_CLIENT_SOCKET_HANDLE_H_ | 5 #ifndef NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
6 #define NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ | 6 #define NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/base/ip_endpoint.h" | |
15 #include "net/base/load_states.h" | 16 #include "net/base/load_states.h" |
16 #include "net/base/load_timing_info.h" | 17 #include "net/base/load_timing_info.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
19 #include "net/base/net_log.h" | 20 #include "net/base/net_log.h" |
20 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
21 #include "net/http/http_response_info.h" | 22 #include "net/http/http_response_info.h" |
22 #include "net/socket/client_socket_pool.h" | 23 #include "net/socket/client_socket_pool.h" |
23 #include "net/socket/stream_socket.h" | 24 #include "net/socket/stream_socket.h" |
24 | 25 |
25 namespace net { | 26 namespace net { |
26 | 27 |
27 // A container for a StreamSocket. | 28 // A container for a StreamSocket. |
28 // | 29 // |
29 // The handle's |group_name| uniquely identifies the origin and type of the | 30 // The handle's |group_name| uniquely identifies the origin and type of the |
30 // connection. It is used by the ClientSocketPool to group similar connected | 31 // connection. It is used by the ClientSocketPool to group similar connected |
31 // client socket objects. | 32 // client socket objects. |
32 // | 33 // |
33 class NET_EXPORT ClientSocketHandle { | 34 class NET_EXPORT ClientSocketHandle { |
34 public: | 35 public: |
35 enum SocketReuseType { | 36 enum SocketReuseType { |
36 UNUSED = 0, // unused socket that just finished connecting | 37 UNUSED = 0, // unused socket that just finished connecting |
37 UNUSED_IDLE, // unused socket that has been idle for awhile | 38 UNUSED_IDLE, // unused socket that has been idle for awhile |
38 REUSED_IDLE, // previously used socket | 39 REUSED_IDLE, // previously used socket |
39 NUM_TYPES, | 40 NUM_TYPES, |
40 }; | 41 }; |
41 | 42 |
43 // A record of a TCP connection attempt made to connect to the host. | |
Ryan Hamilton
2015/03/24 19:20:19
Can you update the comment to mention TLS errors?
Deprecated (see juliatuttle)
2015/04/08 19:17:19
Done.
| |
44 struct ConnectionAttempt { | |
45 ConnectionAttempt(const IPEndPoint endpoint, int result) | |
46 : endpoint(endpoint), result(result) {} | |
47 | |
48 // Address and port the socket layer attempted to connect to. | |
49 IPEndPoint endpoint; | |
50 | |
51 // Net error indicating the result of that attempt. | |
52 int result; | |
53 }; | |
54 | |
55 typedef std::vector<ConnectionAttempt> ConnectionAttempts; | |
56 | |
42 ClientSocketHandle(); | 57 ClientSocketHandle(); |
43 ~ClientSocketHandle(); | 58 ~ClientSocketHandle(); |
44 | 59 |
45 // Initializes a ClientSocketHandle object, which involves talking to the | 60 // Initializes a ClientSocketHandle object, which involves talking to the |
46 // ClientSocketPool to obtain a connected socket, possibly reusing one. This | 61 // ClientSocketPool to obtain a connected socket, possibly reusing one. This |
47 // method returns either OK or ERR_IO_PENDING. On ERR_IO_PENDING, |priority| | 62 // method returns either OK or ERR_IO_PENDING. On ERR_IO_PENDING, |priority| |
48 // is used to determine the placement in ClientSocketPool's wait list. | 63 // is used to determine the placement in ClientSocketPool's wait list. |
49 // | 64 // |
50 // If this method succeeds, then the socket member will be set to an existing | 65 // If this method succeeds, then the socket member will be set to an existing |
51 // connected socket if an existing connected socket was available to reuse, | 66 // connected socket if an existing connected socket was available to reuse, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 void set_reuse_type(SocketReuseType reuse_type) { reuse_type_ = reuse_type; } | 144 void set_reuse_type(SocketReuseType reuse_type) { reuse_type_ = reuse_type; } |
130 void set_idle_time(base::TimeDelta idle_time) { idle_time_ = idle_time; } | 145 void set_idle_time(base::TimeDelta idle_time) { idle_time_ = idle_time; } |
131 void set_pool_id(int id) { pool_id_ = id; } | 146 void set_pool_id(int id) { pool_id_ = id; } |
132 void set_is_ssl_error(bool is_ssl_error) { is_ssl_error_ = is_ssl_error; } | 147 void set_is_ssl_error(bool is_ssl_error) { is_ssl_error_ = is_ssl_error; } |
133 void set_ssl_error_response_info(const HttpResponseInfo& ssl_error_state) { | 148 void set_ssl_error_response_info(const HttpResponseInfo& ssl_error_state) { |
134 ssl_error_response_info_ = ssl_error_state; | 149 ssl_error_response_info_ = ssl_error_state; |
135 } | 150 } |
136 void set_pending_http_proxy_connection(ClientSocketHandle* connection) { | 151 void set_pending_http_proxy_connection(ClientSocketHandle* connection) { |
137 pending_http_proxy_connection_.reset(connection); | 152 pending_http_proxy_connection_.reset(connection); |
138 } | 153 } |
154 void set_connection_attempts(ConnectionAttempts attempts) { | |
155 connection_attempts_ = attempts; | |
156 } | |
139 | 157 |
140 // Only valid if there is no |socket_|. | 158 // Only valid if there is no |socket_|. |
141 bool is_ssl_error() const { | 159 bool is_ssl_error() const { |
142 DCHECK(socket_.get() == NULL); | 160 DCHECK(socket_.get() == NULL); |
143 return is_ssl_error_; | 161 return is_ssl_error_; |
144 } | 162 } |
145 // On an ERR_PROXY_AUTH_REQUESTED error, the |headers| and |auth_challenge| | 163 // On an ERR_PROXY_AUTH_REQUESTED error, the |headers| and |auth_challenge| |
146 // fields are filled in. On an ERR_SSL_CLIENT_AUTH_CERT_NEEDED error, | 164 // fields are filled in. On an ERR_SSL_CLIENT_AUTH_CERT_NEEDED error, |
147 // the |cert_request_info| field is set. | 165 // the |cert_request_info| field is set. |
148 const HttpResponseInfo& ssl_error_response_info() const { | 166 const HttpResponseInfo& ssl_error_response_info() const { |
149 return ssl_error_response_info_; | 167 return ssl_error_response_info_; |
150 } | 168 } |
151 ClientSocketHandle* release_pending_http_proxy_connection() { | 169 ClientSocketHandle* release_pending_http_proxy_connection() { |
152 return pending_http_proxy_connection_.release(); | 170 return pending_http_proxy_connection_.release(); |
153 } | 171 } |
172 const ConnectionAttempts& connection_attempts() { | |
173 return connection_attempts_; | |
174 } | |
154 | 175 |
155 StreamSocket* socket() { return socket_.get(); } | 176 StreamSocket* socket() { return socket_.get(); } |
156 | 177 |
157 // SetSocket() must be called with a new socket before this handle | 178 // SetSocket() must be called with a new socket before this handle |
158 // is destroyed if is_initialized() is true. | 179 // is destroyed if is_initialized() is true. |
159 scoped_ptr<StreamSocket> PassSocket(); | 180 scoped_ptr<StreamSocket> PassSocket(); |
160 | 181 |
161 // These may only be used if is_initialized() is true. | 182 // These may only be used if is_initialized() is true. |
162 const std::string& group_name() const { return group_name_; } | 183 const std::string& group_name() const { return group_name_; } |
163 int id() const { return pool_id_; } | 184 int id() const { return pool_id_; } |
(...skipping 29 matching lines...) Expand all Loading... | |
193 scoped_ptr<StreamSocket> socket_; | 214 scoped_ptr<StreamSocket> socket_; |
194 std::string group_name_; | 215 std::string group_name_; |
195 SocketReuseType reuse_type_; | 216 SocketReuseType reuse_type_; |
196 CompletionCallback callback_; | 217 CompletionCallback callback_; |
197 CompletionCallback user_callback_; | 218 CompletionCallback user_callback_; |
198 base::TimeDelta idle_time_; | 219 base::TimeDelta idle_time_; |
199 int pool_id_; // See ClientSocketPool::ReleaseSocket() for an explanation. | 220 int pool_id_; // See ClientSocketPool::ReleaseSocket() for an explanation. |
200 bool is_ssl_error_; | 221 bool is_ssl_error_; |
201 HttpResponseInfo ssl_error_response_info_; | 222 HttpResponseInfo ssl_error_response_info_; |
202 scoped_ptr<ClientSocketHandle> pending_http_proxy_connection_; | 223 scoped_ptr<ClientSocketHandle> pending_http_proxy_connection_; |
224 std::vector<ConnectionAttempt> connection_attempts_; | |
203 base::TimeTicks init_time_; | 225 base::TimeTicks init_time_; |
204 base::TimeDelta setup_time_; | 226 base::TimeDelta setup_time_; |
205 | 227 |
206 NetLog::Source requesting_source_; | 228 NetLog::Source requesting_source_; |
207 | 229 |
208 // Timing information is set when a connection is successfully established. | 230 // Timing information is set when a connection is successfully established. |
209 LoadTimingInfo::ConnectTiming connect_timing_; | 231 LoadTimingInfo::ConnectTiming connect_timing_; |
210 | 232 |
211 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); | 233 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); |
212 }; | 234 }; |
(...skipping 21 matching lines...) Expand all Loading... | |
234 user_callback_ = callback; | 256 user_callback_ = callback; |
235 } else { | 257 } else { |
236 HandleInitCompletion(rv); | 258 HandleInitCompletion(rv); |
237 } | 259 } |
238 return rv; | 260 return rv; |
239 } | 261 } |
240 | 262 |
241 } // namespace net | 263 } // namespace net |
242 | 264 |
243 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ | 265 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
OLD | NEW |