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. |
| 44 struct ConnectionAttempt { |
| 45 // Address and port the socket layer attempted to connect to. |
| 46 IPEndPoint endpoint; |
| 47 |
| 48 // Net error indicating the result of that attempt. |
| 49 int result; |
| 50 }; |
| 51 |
42 ClientSocketHandle(); | 52 ClientSocketHandle(); |
43 ~ClientSocketHandle(); | 53 ~ClientSocketHandle(); |
44 | 54 |
45 // Initializes a ClientSocketHandle object, which involves talking to the | 55 // Initializes a ClientSocketHandle object, which involves talking to the |
46 // ClientSocketPool to obtain a connected socket, possibly reusing one. This | 56 // ClientSocketPool to obtain a connected socket, possibly reusing one. This |
47 // method returns either OK or ERR_IO_PENDING. On ERR_IO_PENDING, |priority| | 57 // 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. | 58 // is used to determine the placement in ClientSocketPool's wait list. |
49 // | 59 // |
50 // If this method succeeds, then the socket member will be set to an existing | 60 // 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, | 61 // 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; } | 139 void set_reuse_type(SocketReuseType reuse_type) { reuse_type_ = reuse_type; } |
130 void set_idle_time(base::TimeDelta idle_time) { idle_time_ = idle_time; } | 140 void set_idle_time(base::TimeDelta idle_time) { idle_time_ = idle_time; } |
131 void set_pool_id(int id) { pool_id_ = id; } | 141 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; } | 142 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) { | 143 void set_ssl_error_response_info(const HttpResponseInfo& ssl_error_state) { |
134 ssl_error_response_info_ = ssl_error_state; | 144 ssl_error_response_info_ = ssl_error_state; |
135 } | 145 } |
136 void set_pending_http_proxy_connection(ClientSocketHandle* connection) { | 146 void set_pending_http_proxy_connection(ClientSocketHandle* connection) { |
137 pending_http_proxy_connection_.reset(connection); | 147 pending_http_proxy_connection_.reset(connection); |
138 } | 148 } |
| 149 void set_connection_attempts(std::vector<ConnectionAttempt> attempts) { |
| 150 connection_attempts_ = attempts; |
| 151 } |
139 | 152 |
140 // Only valid if there is no |socket_|. | 153 // Only valid if there is no |socket_|. |
141 bool is_ssl_error() const { | 154 bool is_ssl_error() const { |
142 DCHECK(socket_.get() == NULL); | 155 DCHECK(socket_.get() == NULL); |
143 return is_ssl_error_; | 156 return is_ssl_error_; |
144 } | 157 } |
145 // On an ERR_PROXY_AUTH_REQUESTED error, the |headers| and |auth_challenge| | 158 // 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, | 159 // fields are filled in. On an ERR_SSL_CLIENT_AUTH_CERT_NEEDED error, |
147 // the |cert_request_info| field is set. | 160 // the |cert_request_info| field is set. |
148 const HttpResponseInfo& ssl_error_response_info() const { | 161 const HttpResponseInfo& ssl_error_response_info() const { |
149 return ssl_error_response_info_; | 162 return ssl_error_response_info_; |
150 } | 163 } |
151 ClientSocketHandle* release_pending_http_proxy_connection() { | 164 ClientSocketHandle* release_pending_http_proxy_connection() { |
152 return pending_http_proxy_connection_.release(); | 165 return pending_http_proxy_connection_.release(); |
153 } | 166 } |
| 167 const std::vector<ConnectionAttempt>& connection_attempts() { |
| 168 return connection_attempts_; |
| 169 } |
154 | 170 |
155 StreamSocket* socket() { return socket_.get(); } | 171 StreamSocket* socket() { return socket_.get(); } |
156 | 172 |
157 // SetSocket() must be called with a new socket before this handle | 173 // SetSocket() must be called with a new socket before this handle |
158 // is destroyed if is_initialized() is true. | 174 // is destroyed if is_initialized() is true. |
159 scoped_ptr<StreamSocket> PassSocket(); | 175 scoped_ptr<StreamSocket> PassSocket(); |
160 | 176 |
161 // These may only be used if is_initialized() is true. | 177 // These may only be used if is_initialized() is true. |
162 const std::string& group_name() const { return group_name_; } | 178 const std::string& group_name() const { return group_name_; } |
163 int id() const { return pool_id_; } | 179 int id() const { return pool_id_; } |
(...skipping 29 matching lines...) Expand all Loading... |
193 scoped_ptr<StreamSocket> socket_; | 209 scoped_ptr<StreamSocket> socket_; |
194 std::string group_name_; | 210 std::string group_name_; |
195 SocketReuseType reuse_type_; | 211 SocketReuseType reuse_type_; |
196 CompletionCallback callback_; | 212 CompletionCallback callback_; |
197 CompletionCallback user_callback_; | 213 CompletionCallback user_callback_; |
198 base::TimeDelta idle_time_; | 214 base::TimeDelta idle_time_; |
199 int pool_id_; // See ClientSocketPool::ReleaseSocket() for an explanation. | 215 int pool_id_; // See ClientSocketPool::ReleaseSocket() for an explanation. |
200 bool is_ssl_error_; | 216 bool is_ssl_error_; |
201 HttpResponseInfo ssl_error_response_info_; | 217 HttpResponseInfo ssl_error_response_info_; |
202 scoped_ptr<ClientSocketHandle> pending_http_proxy_connection_; | 218 scoped_ptr<ClientSocketHandle> pending_http_proxy_connection_; |
| 219 std::vector<ConnectionAttempt> connection_attempts_; |
203 base::TimeTicks init_time_; | 220 base::TimeTicks init_time_; |
204 base::TimeDelta setup_time_; | 221 base::TimeDelta setup_time_; |
205 | 222 |
206 NetLog::Source requesting_source_; | 223 NetLog::Source requesting_source_; |
207 | 224 |
208 // Timing information is set when a connection is successfully established. | 225 // Timing information is set when a connection is successfully established. |
209 LoadTimingInfo::ConnectTiming connect_timing_; | 226 LoadTimingInfo::ConnectTiming connect_timing_; |
210 | 227 |
211 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); | 228 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); |
212 }; | 229 }; |
(...skipping 21 matching lines...) Expand all Loading... |
234 user_callback_ = callback; | 251 user_callback_ = callback; |
235 } else { | 252 } else { |
236 HandleInitCompletion(rv); | 253 HandleInitCompletion(rv); |
237 } | 254 } |
238 return rv; | 255 return rv; |
239 } | 256 } |
240 | 257 |
241 } // namespace net | 258 } // namespace net |
242 | 259 |
243 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ | 260 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
OLD | NEW |