Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: net/socket/transport_client_socket_pool.h

Issue 1376473003: Notify NQE of TCP RTT values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_TRANSPORT_CLIENT_SOCKET_POOL_H_ 5 #ifndef NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_
6 #define NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ 6 #define NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.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 "base/timer/timer.h" 14 #include "base/timer/timer.h"
15 #include "net/base/host_port_pair.h" 15 #include "net/base/host_port_pair.h"
16 #include "net/dns/host_resolver.h" 16 #include "net/dns/host_resolver.h"
17 #include "net/dns/single_request_host_resolver.h" 17 #include "net/dns/single_request_host_resolver.h"
18 #include "net/socket/client_socket_pool.h" 18 #include "net/socket/client_socket_pool.h"
19 #include "net/socket/client_socket_pool_base.h" 19 #include "net/socket/client_socket_pool_base.h"
20 #include "net/socket/connection_attempts.h" 20 #include "net/socket/connection_attempts.h"
21 21
22 namespace net { 22 namespace net {
23 23
24 class ClientSocketFactory; 24 class ClientSocketFactory;
25 class SocketPerformanceWatcherFactory;
25 26
26 typedef base::Callback<int(const AddressList&, const BoundNetLog& net_log)> 27 typedef base::Callback<int(const AddressList&, const BoundNetLog& net_log)>
27 OnHostResolutionCallback; 28 OnHostResolutionCallback;
28 29
29 class NET_EXPORT_PRIVATE TransportSocketParams 30 class NET_EXPORT_PRIVATE TransportSocketParams
30 : public base::RefCounted<TransportSocketParams> { 31 : public base::RefCounted<TransportSocketParams> {
31 public: 32 public:
32 // CombineConnectAndWrite currently translates to using TCP FastOpen. 33 // CombineConnectAndWrite currently translates to using TCP FastOpen.
33 // TCP FastOpen should not be used if the first write to the socket may 34 // TCP FastOpen should not be used if the first write to the socket may
34 // be non-idempotent, as the underlying socket could retransmit the data 35 // be non-idempotent, as the underlying socket could retransmit the data
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // TransportConnectJob handles the host resolution necessary for socket creation 150 // TransportConnectJob handles the host resolution necessary for socket creation
150 // and the transport (likely TCP) connect. TransportConnectJob also has fallback 151 // and the transport (likely TCP) connect. TransportConnectJob also has fallback
151 // logic for IPv6 connect() timeouts (which may happen due to networks / routers 152 // logic for IPv6 connect() timeouts (which may happen due to networks / routers
152 // with broken IPv6 support). Those timeouts take 20s, so rather than make the 153 // with broken IPv6 support). Those timeouts take 20s, so rather than make the
153 // user wait 20s for the timeout to fire, we use a fallback timer 154 // user wait 20s for the timeout to fire, we use a fallback timer
154 // (kIPv6FallbackTimerInMs) and start a connect() to a IPv4 address if the timer 155 // (kIPv6FallbackTimerInMs) and start a connect() to a IPv4 address if the timer
155 // fires. Then we race the IPv4 connect() against the IPv6 connect() (which has 156 // fires. Then we race the IPv4 connect() against the IPv6 connect() (which has
156 // a headstart) and return the one that completes first to the socket pool. 157 // a headstart) and return the one that completes first to the socket pool.
157 class NET_EXPORT_PRIVATE TransportConnectJob : public ConnectJob { 158 class NET_EXPORT_PRIVATE TransportConnectJob : public ConnectJob {
158 public: 159 public:
159 TransportConnectJob(const std::string& group_name, 160 TransportConnectJob(
160 RequestPriority priority, 161 const std::string& group_name,
161 const scoped_refptr<TransportSocketParams>& params, 162 RequestPriority priority,
162 base::TimeDelta timeout_duration, 163 const scoped_refptr<TransportSocketParams>& params,
163 ClientSocketFactory* client_socket_factory, 164 base::TimeDelta timeout_duration,
164 HostResolver* host_resolver, 165 ClientSocketFactory* client_socket_factory,
165 Delegate* delegate, 166 const SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
166 NetLog* net_log); 167 HostResolver* host_resolver,
168 Delegate* delegate,
169 NetLog* net_log);
167 ~TransportConnectJob() override; 170 ~TransportConnectJob() override;
168 171
169 // ConnectJob methods. 172 // ConnectJob methods.
170 LoadState GetLoadState() const override; 173 LoadState GetLoadState() const override;
171 void GetAdditionalErrorState(ClientSocketHandle* handle) override; 174 void GetAdditionalErrorState(ClientSocketHandle* handle) override;
172 175
173 // Rolls |addrlist| forward until the first IPv4 address, if any. 176 // Rolls |addrlist| forward until the first IPv4 address, if any.
174 // WARNING: this method should only be used to implement the prefer-IPv4 hack. 177 // WARNING: this method should only be used to implement the prefer-IPv4 hack.
175 static void MakeAddressListStartWithIPv4(AddressList* addrlist); 178 static void MakeAddressListStartWithIPv4(AddressList* addrlist);
176 179
(...skipping 23 matching lines...) Expand all
200 void CopyConnectionAttemptsFromSockets(); 203 void CopyConnectionAttemptsFromSockets();
201 204
202 TransportConnectJobHelper helper_; 205 TransportConnectJobHelper helper_;
203 206
204 scoped_ptr<StreamSocket> transport_socket_; 207 scoped_ptr<StreamSocket> transport_socket_;
205 208
206 scoped_ptr<StreamSocket> fallback_transport_socket_; 209 scoped_ptr<StreamSocket> fallback_transport_socket_;
207 scoped_ptr<AddressList> fallback_addresses_; 210 scoped_ptr<AddressList> fallback_addresses_;
208 base::TimeTicks fallback_connect_start_time_; 211 base::TimeTicks fallback_connect_start_time_;
209 base::OneShotTimer fallback_timer_; 212 base::OneShotTimer fallback_timer_;
213 const SocketPerformanceWatcherFactory* socket_performance_watcher_factory_;
210 214
211 // Track the interval between this connect and previous connect. 215 // Track the interval between this connect and previous connect.
212 ConnectInterval interval_between_connects_; 216 ConnectInterval interval_between_connects_;
213 217
214 int resolve_result_; 218 int resolve_result_;
215 219
216 // Used in the failure case to save connection attempts made on the main and 220 // Used in the failure case to save connection attempts made on the main and
217 // fallback sockets and pass them on in |GetAdditionalErrorState|. (In the 221 // fallback sockets and pass them on in |GetAdditionalErrorState|. (In the
218 // success case, connection attempts are passed through the returned socket; 222 // success case, connection attempts are passed through the returned socket;
219 // attempts are copied from the other socket, if one exists, into it before 223 // attempts are copied from the other socket, if one exists, into it before
220 // it is returned.) 224 // it is returned.)
221 ConnectionAttempts connection_attempts_; 225 ConnectionAttempts connection_attempts_;
222 ConnectionAttempts fallback_connection_attempts_; 226 ConnectionAttempts fallback_connection_attempts_;
223 227
224 DISALLOW_COPY_AND_ASSIGN(TransportConnectJob); 228 DISALLOW_COPY_AND_ASSIGN(TransportConnectJob);
225 }; 229 };
226 230
227 class NET_EXPORT_PRIVATE TransportClientSocketPool : public ClientSocketPool { 231 class NET_EXPORT_PRIVATE TransportClientSocketPool : public ClientSocketPool {
228 public: 232 public:
229 typedef TransportSocketParams SocketParams; 233 typedef TransportSocketParams SocketParams;
230 234
231 TransportClientSocketPool( 235 TransportClientSocketPool(
232 int max_sockets, 236 int max_sockets,
233 int max_sockets_per_group, 237 int max_sockets_per_group,
234 HostResolver* host_resolver, 238 HostResolver* host_resolver,
235 ClientSocketFactory* client_socket_factory, 239 ClientSocketFactory* client_socket_factory,
240 const SocketPerformanceWatcherFactory* socket_performance_watcher_factory,
236 NetLog* net_log); 241 NetLog* net_log);
237 242
238 ~TransportClientSocketPool() override; 243 ~TransportClientSocketPool() override;
239 244
240 // ClientSocketPool implementation. 245 // ClientSocketPool implementation.
241 int RequestSocket(const std::string& group_name, 246 int RequestSocket(const std::string& group_name,
242 const void* resolve_info, 247 const void* resolve_info,
243 RequestPriority priority, 248 RequestPriority priority,
244 ClientSocketHandle* handle, 249 ClientSocketHandle* handle,
245 const CompletionCallback& callback, 250 const CompletionCallback& callback,
(...skipping 30 matching lines...) Expand all
276 const BoundNetLog& net_log, 281 const BoundNetLog& net_log,
277 const scoped_refptr<TransportSocketParams>* casted_params); 282 const scoped_refptr<TransportSocketParams>* casted_params);
278 283
279 private: 284 private:
280 typedef ClientSocketPoolBase<TransportSocketParams> PoolBase; 285 typedef ClientSocketPoolBase<TransportSocketParams> PoolBase;
281 286
282 class TransportConnectJobFactory 287 class TransportConnectJobFactory
283 : public PoolBase::ConnectJobFactory { 288 : public PoolBase::ConnectJobFactory {
284 public: 289 public:
285 TransportConnectJobFactory(ClientSocketFactory* client_socket_factory, 290 TransportConnectJobFactory(ClientSocketFactory* client_socket_factory,
286 HostResolver* host_resolver, 291 const SocketPerformanceWatcherFactory*
287 NetLog* net_log) 292 socket_performance_watcher_factory,
293 HostResolver* host_resolver,
294 NetLog* net_log)
288 : client_socket_factory_(client_socket_factory), 295 : client_socket_factory_(client_socket_factory),
296 socket_performance_watcher_factory_(
297 socket_performance_watcher_factory),
289 host_resolver_(host_resolver), 298 host_resolver_(host_resolver),
290 net_log_(net_log) {} 299 net_log_(net_log) {}
291 300
292 ~TransportConnectJobFactory() override {} 301 ~TransportConnectJobFactory() override {}
293 302
294 // ClientSocketPoolBase::ConnectJobFactory methods. 303 // ClientSocketPoolBase::ConnectJobFactory methods.
295 304
296 scoped_ptr<ConnectJob> NewConnectJob( 305 scoped_ptr<ConnectJob> NewConnectJob(
297 const std::string& group_name, 306 const std::string& group_name,
298 const PoolBase::Request& request, 307 const PoolBase::Request& request,
299 ConnectJob::Delegate* delegate) const override; 308 ConnectJob::Delegate* delegate) const override;
300 309
301 base::TimeDelta ConnectionTimeout() const override; 310 base::TimeDelta ConnectionTimeout() const override;
302 311
303 private: 312 private:
304 ClientSocketFactory* const client_socket_factory_; 313 ClientSocketFactory* const client_socket_factory_;
314 const SocketPerformanceWatcherFactory* socket_performance_watcher_factory_;
305 HostResolver* const host_resolver_; 315 HostResolver* const host_resolver_;
306 NetLog* net_log_; 316 NetLog* net_log_;
307 317
308 DISALLOW_COPY_AND_ASSIGN(TransportConnectJobFactory); 318 DISALLOW_COPY_AND_ASSIGN(TransportConnectJobFactory);
309 }; 319 };
310 320
311 PoolBase base_; 321 PoolBase base_;
312 322
313 DISALLOW_COPY_AND_ASSIGN(TransportClientSocketPool); 323 DISALLOW_COPY_AND_ASSIGN(TransportClientSocketPool);
314 }; 324 };
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 break; 374 break;
365 } 375 }
366 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 376 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
367 377
368 return rv; 378 return rv;
369 } 379 }
370 380
371 } // namespace net 381 } // namespace net
372 382
373 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ 383 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698