Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 int NumConnectJobsInGroup(const std::string& group_name) const { | 286 int NumConnectJobsInGroup(const std::string& group_name) const { |
| 287 return group_map_.find(group_name)->second->jobs().size(); | 287 return group_map_.find(group_name)->second->jobs().size(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 int NumActiveSocketsInGroup(const std::string& group_name) const { | 290 int NumActiveSocketsInGroup(const std::string& group_name) const { |
| 291 return group_map_.find(group_name)->second->active_socket_count(); | 291 return group_map_.find(group_name)->second->active_socket_count(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 bool HasGroup(const std::string& group_name) const; | 294 bool HasGroup(const std::string& group_name) const; |
| 295 | 295 |
| 296 // Called to enable/disable cleaning up idle sockets. When enabled, | |
| 297 // idle sockets that have been around for longer than a period defined | |
| 298 // by kCleanupInterval are cleaned up using a timer. Otherwise they are | |
| 299 // closed next time client makes a request. This may reduce network | |
| 300 // activity and power consumption. | |
| 301 bool cleanup_timer_enabled() const { return use_cleanup_timer_; } | |
| 302 void SetCleanupTimerEnabled( bool enabled ); | |
|
mmenke
2011/11/11 20:19:20
nit: "(bool enabled)"
| |
| 303 | |
| 296 // Closes all idle sockets if |force| is true. Else, only closes idle | 304 // Closes all idle sockets if |force| is true. Else, only closes idle |
| 297 // sockets that timed out or can't be reused. Made public for testing. | 305 // sockets that timed out or can't be reused. Made public for testing. |
| 298 void CleanupIdleSockets(bool force); | 306 void CleanupIdleSockets(bool force); |
| 299 | 307 |
| 300 // See ClientSocketPool::GetInfoAsValue for documentation on this function. | 308 // See ClientSocketPool::GetInfoAsValue for documentation on this function. |
| 301 base::DictionaryValue* GetInfoAsValue(const std::string& name, | 309 base::DictionaryValue* GetInfoAsValue(const std::string& name, |
| 302 const std::string& type) const; | 310 const std::string& type) const; |
| 303 | 311 |
| 304 base::TimeDelta ConnectionTimeout() const { | 312 base::TimeDelta ConnectionTimeout() const { |
| 305 return connect_job_factory_->ConnectionTimeout(); | 313 return connect_job_factory_->ConnectionTimeout(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 Group* group); | 443 Group* group); |
| 436 | 444 |
| 437 Group* GetOrCreateGroup(const std::string& group_name); | 445 Group* GetOrCreateGroup(const std::string& group_name); |
| 438 void RemoveGroup(const std::string& group_name); | 446 void RemoveGroup(const std::string& group_name); |
| 439 void RemoveGroup(GroupMap::iterator it); | 447 void RemoveGroup(GroupMap::iterator it); |
| 440 | 448 |
| 441 // Called when the number of idle sockets changes. | 449 // Called when the number of idle sockets changes. |
| 442 void IncrementIdleCount(); | 450 void IncrementIdleCount(); |
| 443 void DecrementIdleCount(); | 451 void DecrementIdleCount(); |
| 444 | 452 |
| 453 // Start cleanup timer for idle sockets. | |
| 454 void StartIdleSocketTimer(); | |
| 455 | |
| 445 // Scans the group map for groups which have an available socket slot and | 456 // Scans the group map for groups which have an available socket slot and |
| 446 // at least one pending request. Returns true if any groups are stalled, and | 457 // at least one pending request. Returns true if any groups are stalled, and |
| 447 // if so, fills |group| and |group_name| with data of the stalled group | 458 // if so, fills |group| and |group_name| with data of the stalled group |
| 448 // having highest priority. | 459 // having highest priority. |
| 449 bool FindTopStalledGroup(Group** group, std::string* group_name); | 460 bool FindTopStalledGroup(Group** group, std::string* group_name); |
| 450 | 461 |
| 451 // Called when timer_ fires. This method scans the idle sockets removing | 462 // Called when timer_ fires. This method scans the idle sockets removing |
| 452 // sockets that timed out or can't be reused. | 463 // sockets that timed out or can't be reused. |
| 453 void OnCleanupTimerFired() { | 464 void OnCleanupTimerFired() { |
| 454 CleanupIdleSockets(false); | 465 CleanupIdleSockets(false); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 | 556 |
| 546 // Number of connected sockets we handed out across all groups. | 557 // Number of connected sockets we handed out across all groups. |
| 547 int handed_out_socket_count_; | 558 int handed_out_socket_count_; |
| 548 | 559 |
| 549 // The maximum total number of sockets. See ReachedMaxSocketsLimit. | 560 // The maximum total number of sockets. See ReachedMaxSocketsLimit. |
| 550 const int max_sockets_; | 561 const int max_sockets_; |
| 551 | 562 |
| 552 // The maximum number of sockets kept per group. | 563 // The maximum number of sockets kept per group. |
| 553 const int max_sockets_per_group_; | 564 const int max_sockets_per_group_; |
| 554 | 565 |
| 566 // Whether to use timer to cleanup idle sockets. | |
| 567 bool use_cleanup_timer_; | |
| 568 | |
| 555 // The time to wait until closing idle sockets. | 569 // The time to wait until closing idle sockets. |
| 556 const base::TimeDelta unused_idle_socket_timeout_; | 570 const base::TimeDelta unused_idle_socket_timeout_; |
| 557 const base::TimeDelta used_idle_socket_timeout_; | 571 const base::TimeDelta used_idle_socket_timeout_; |
| 558 | 572 |
| 559 const scoped_ptr<ConnectJobFactory> connect_job_factory_; | 573 const scoped_ptr<ConnectJobFactory> connect_job_factory_; |
| 560 | 574 |
| 561 // TODO(vandebo) Remove when backup jobs move to TransportClientSocketPool | 575 // TODO(vandebo) Remove when backup jobs move to TransportClientSocketPool |
| 562 bool connect_backup_jobs_enabled_; | 576 bool connect_backup_jobs_enabled_; |
| 563 | 577 |
| 564 // A unique id for the pool. It gets incremented every time we Flush() the | 578 // A unique id for the pool. It gets incremented every time we Flush() the |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 } | 712 } |
| 699 | 713 |
| 700 int NumActiveSocketsInGroup(const std::string& group_name) const { | 714 int NumActiveSocketsInGroup(const std::string& group_name) const { |
| 701 return helper_.NumActiveSocketsInGroup(group_name); | 715 return helper_.NumActiveSocketsInGroup(group_name); |
| 702 } | 716 } |
| 703 | 717 |
| 704 bool HasGroup(const std::string& group_name) const { | 718 bool HasGroup(const std::string& group_name) const { |
| 705 return helper_.HasGroup(group_name); | 719 return helper_.HasGroup(group_name); |
| 706 } | 720 } |
| 707 | 721 |
| 722 bool cleanup_timer_enabled() const { | |
| 723 return helper_.cleanup_timer_enabled(); | |
| 724 } | |
| 725 | |
| 726 void SetCleanupTimerEnabled(bool enabled) { | |
| 727 return helper_.SetCleanupTimerEnabled(enabled); | |
| 728 } | |
| 729 | |
| 708 void CleanupIdleSockets(bool force) { | 730 void CleanupIdleSockets(bool force) { |
| 709 return helper_.CleanupIdleSockets(force); | 731 return helper_.CleanupIdleSockets(force); |
| 710 } | 732 } |
| 711 | 733 |
| 712 base::DictionaryValue* GetInfoAsValue(const std::string& name, | 734 base::DictionaryValue* GetInfoAsValue(const std::string& name, |
| 713 const std::string& type) const { | 735 const std::string& type) const { |
| 714 return helper_.GetInfoAsValue(name, type); | 736 return helper_.GetInfoAsValue(name, type); |
| 715 } | 737 } |
| 716 | 738 |
| 717 base::TimeDelta ConnectionTimeout() const { | 739 base::TimeDelta ConnectionTimeout() const { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 761 // Histograms for the pool | 783 // Histograms for the pool |
| 762 ClientSocketPoolHistograms* const histograms_; | 784 ClientSocketPoolHistograms* const histograms_; |
| 763 internal::ClientSocketPoolBaseHelper helper_; | 785 internal::ClientSocketPoolBaseHelper helper_; |
| 764 | 786 |
| 765 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 787 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
| 766 }; | 788 }; |
| 767 | 789 |
| 768 } // namespace net | 790 } // namespace net |
| 769 | 791 |
| 770 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 792 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |