OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // A ClientSocketPoolBase is used to restrict the number of sockets open at | 5 // A ClientSocketPoolBase is used to restrict the number of sockets open at |
6 // a time. It also maintains a list of idle persistent sockets for reuse. | 6 // a time. It also maintains a list of idle persistent sockets for reuse. |
7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle | 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle |
8 // the core logic of (1) restricting the number of active (connected or | 8 // the core logic of (1) restricting the number of active (connected or |
9 // connecting) sockets per "group" (generally speaking, the hostname), (2) | 9 // connecting) sockets per "group" (generally speaking, the hostname), (2) |
10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) | 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 167 |
168 private: | 168 private: |
169 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); | 169 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); |
170 }; | 170 }; |
171 | 171 |
172 ClientSocketPoolBaseHelper( | 172 ClientSocketPoolBaseHelper( |
173 int max_sockets, | 173 int max_sockets, |
174 int max_sockets_per_group, | 174 int max_sockets_per_group, |
175 base::TimeDelta unused_idle_socket_timeout, | 175 base::TimeDelta unused_idle_socket_timeout, |
176 base::TimeDelta used_idle_socket_timeout, | 176 base::TimeDelta used_idle_socket_timeout, |
177 ConnectJobFactory* connect_job_factory, | 177 ConnectJobFactory* connect_job_factory); |
178 NetworkChangeNotifier* network_change_notifier); | |
179 | 178 |
180 // See ClientSocketPool::RequestSocket for documentation on this function. | 179 // See ClientSocketPool::RequestSocket for documentation on this function. |
181 // ClientSocketPoolBaseHelper takes ownership of |request|, which must be | 180 // ClientSocketPoolBaseHelper takes ownership of |request|, which must be |
182 // heap allocated. | 181 // heap allocated. |
183 int RequestSocket(const std::string& group_name, const Request* request); | 182 int RequestSocket(const std::string& group_name, const Request* request); |
184 | 183 |
185 // See ClientSocketPool::CancelRequest for documentation on this function. | 184 // See ClientSocketPool::CancelRequest for documentation on this function. |
186 void CancelRequest(const std::string& group_name, | 185 void CancelRequest(const std::string& group_name, |
187 const ClientSocketHandle* handle); | 186 const ClientSocketHandle* handle); |
188 | 187 |
(...skipping 24 matching lines...) Expand all Loading... |
213 int ConnectRetryIntervalMs() const { | 212 int ConnectRetryIntervalMs() const { |
214 // TODO(mbelshe): Make this tuned dynamically based on measured RTT. | 213 // TODO(mbelshe): Make this tuned dynamically based on measured RTT. |
215 // For now, just use the max retry interval. | 214 // For now, just use the max retry interval. |
216 return ClientSocketPool::kMaxConnectRetryIntervalMs; | 215 return ClientSocketPool::kMaxConnectRetryIntervalMs; |
217 } | 216 } |
218 | 217 |
219 // ConnectJob::Delegate methods: | 218 // ConnectJob::Delegate methods: |
220 virtual void OnConnectJobComplete(int result, ConnectJob* job); | 219 virtual void OnConnectJobComplete(int result, ConnectJob* job); |
221 | 220 |
222 // NetworkChangeNotifier::Observer methods: | 221 // NetworkChangeNotifier::Observer methods: |
223 virtual void OnIPAddressChanged() { Flush(); } | 222 virtual void OnIPAddressChanged(); |
224 | 223 |
225 // For testing. | 224 // For testing. |
226 bool may_have_stalled_group() const { return may_have_stalled_group_; } | 225 bool may_have_stalled_group() const { return may_have_stalled_group_; } |
227 | 226 |
228 int NumConnectJobsInGroup(const std::string& group_name) const { | 227 int NumConnectJobsInGroup(const std::string& group_name) const { |
229 return group_map_.find(group_name)->second.jobs.size(); | 228 return group_map_.find(group_name)->second.jobs.size(); |
230 } | 229 } |
231 | 230 |
232 // Closes all idle sockets if |force| is true. Else, only closes idle | 231 // Closes all idle sockets if |force| is true. Else, only closes idle |
233 // sockets that timed out or can't be reused. Made public for testing. | 232 // sockets that timed out or can't be reused. Made public for testing. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 // requests, we may reach the situation where we have the maximum number of | 452 // requests, we may reach the situation where we have the maximum number of |
454 // sockets, but no request is stalled because of the global socket limit | 453 // sockets, but no request is stalled because of the global socket limit |
455 // (although some requests may be blocked on the socket per group limit). | 454 // (although some requests may be blocked on the socket per group limit). |
456 // We don't strictly maintain |may_have_stalled_group_|, since that would | 455 // We don't strictly maintain |may_have_stalled_group_|, since that would |
457 // require a linear search through all groups in |group_map_| to see if one | 456 // require a linear search through all groups in |group_map_| to see if one |
458 // of them is stalled. | 457 // of them is stalled. |
459 bool may_have_stalled_group_; | 458 bool may_have_stalled_group_; |
460 | 459 |
461 const scoped_ptr<ConnectJobFactory> connect_job_factory_; | 460 const scoped_ptr<ConnectJobFactory> connect_job_factory_; |
462 | 461 |
463 NetworkChangeNotifier* const network_change_notifier_; | |
464 | |
465 // TODO(vandebo) Remove when backup jobs move to TCPClientSocketPool | 462 // TODO(vandebo) Remove when backup jobs move to TCPClientSocketPool |
466 bool backup_jobs_enabled_; | 463 bool backup_jobs_enabled_; |
467 | 464 |
468 // A factory to pin the backup_job tasks. | 465 // A factory to pin the backup_job tasks. |
469 ScopedRunnableMethodFactory<ClientSocketPoolBaseHelper> method_factory_; | 466 ScopedRunnableMethodFactory<ClientSocketPoolBaseHelper> method_factory_; |
470 | 467 |
471 // A unique id for the pool. It gets incremented every time we Flush() the | 468 // A unique id for the pool. It gets incremented every time we Flush() the |
472 // pool. This is so that when sockets get released back to the pool, we can | 469 // pool. This is so that when sockets get released back to the pool, we can |
473 // make sure that they are discarded rather than reused. | 470 // make sure that they are discarded rather than reused. |
474 int pool_generation_number_; | 471 int pool_generation_number_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how | 517 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how |
521 // long to leave an unused idle socket open before closing it. | 518 // long to leave an unused idle socket open before closing it. |
522 // |used_idle_socket_timeout| specifies how long to leave a previously used | 519 // |used_idle_socket_timeout| specifies how long to leave a previously used |
523 // idle socket open before closing it. | 520 // idle socket open before closing it. |
524 ClientSocketPoolBase( | 521 ClientSocketPoolBase( |
525 int max_sockets, | 522 int max_sockets, |
526 int max_sockets_per_group, | 523 int max_sockets_per_group, |
527 const scoped_refptr<ClientSocketPoolHistograms>& histograms, | 524 const scoped_refptr<ClientSocketPoolHistograms>& histograms, |
528 base::TimeDelta unused_idle_socket_timeout, | 525 base::TimeDelta unused_idle_socket_timeout, |
529 base::TimeDelta used_idle_socket_timeout, | 526 base::TimeDelta used_idle_socket_timeout, |
530 ConnectJobFactory* connect_job_factory, | 527 ConnectJobFactory* connect_job_factory) |
531 NetworkChangeNotifier* network_change_notifier) | |
532 : histograms_(histograms), | 528 : histograms_(histograms), |
533 helper_(new internal::ClientSocketPoolBaseHelper( | 529 helper_(new internal::ClientSocketPoolBaseHelper( |
534 max_sockets, max_sockets_per_group, | 530 max_sockets, max_sockets_per_group, |
535 unused_idle_socket_timeout, used_idle_socket_timeout, | 531 unused_idle_socket_timeout, used_idle_socket_timeout, |
536 new ConnectJobFactoryAdaptor(connect_job_factory), | 532 new ConnectJobFactoryAdaptor(connect_job_factory))) {} |
537 network_change_notifier)) {} | |
538 | 533 |
539 virtual ~ClientSocketPoolBase() {} | 534 virtual ~ClientSocketPoolBase() {} |
540 | 535 |
541 // These member functions simply forward to ClientSocketPoolBaseHelper. | 536 // These member functions simply forward to ClientSocketPoolBaseHelper. |
542 | 537 |
543 // RequestSocket bundles up the parameters into a Request and then forwards to | 538 // RequestSocket bundles up the parameters into a Request and then forwards to |
544 // ClientSocketPoolBaseHelper::RequestSocket(). Note that the memory | 539 // ClientSocketPoolBaseHelper::RequestSocket(). Note that the memory |
545 // ownership is transferred in the asynchronous (ERR_IO_PENDING) case. | 540 // ownership is transferred in the asynchronous (ERR_IO_PENDING) case. |
546 int RequestSocket(const std::string& group_name, | 541 int RequestSocket(const std::string& group_name, |
547 const SocketParams& params, | 542 const SocketParams& params, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 // the posting of the task and the execution, then we'll hit the DCHECK that | 642 // the posting of the task and the execution, then we'll hit the DCHECK that |
648 // |ClientSocketPoolBaseHelper::group_map_| is empty. | 643 // |ClientSocketPoolBaseHelper::group_map_| is empty. |
649 scoped_refptr<internal::ClientSocketPoolBaseHelper> helper_; | 644 scoped_refptr<internal::ClientSocketPoolBaseHelper> helper_; |
650 | 645 |
651 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 646 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
652 }; | 647 }; |
653 | 648 |
654 } // namespace net | 649 } // namespace net |
655 | 650 |
656 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 651 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |