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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 static bool set_connect_backup_jobs_enabled(bool enabled); | 309 static bool set_connect_backup_jobs_enabled(bool enabled); |
| 310 | 310 |
| 311 void EnableConnectBackupJobs(); | 311 void EnableConnectBackupJobs(); |
| 312 | 312 |
| 313 // ConnectJob::Delegate methods: | 313 // ConnectJob::Delegate methods: |
| 314 virtual void OnConnectJobComplete(int result, ConnectJob* job); | 314 virtual void OnConnectJobComplete(int result, ConnectJob* job); |
| 315 | 315 |
| 316 // NetworkChangeNotifier::IPAddressObserver methods: | 316 // NetworkChangeNotifier::IPAddressObserver methods: |
| 317 virtual void OnIPAddressChanged(); | 317 virtual void OnIPAddressChanged(); |
| 318 | 318 |
| 319 // Called to enable/disable cleaning up idle sockets. When enabled, | |
| 320 // idle sockets that has been around for longer than a period | |
|
mmenke
2011/11/11 03:33:01
nit: Maybe 'idle sockets that have been around to
selim
2011/11/11 19:30:58
done
| |
| 321 // are cleaned up using a timer. Otherwise they are closed next time | |
| 322 // client makes a request. This may reduce network activity and power | |
| 323 // consumption. | |
| 324 bool cleanup_timer_enabled(); | |
|
mmenke
2011/11/11 03:33:01
Put these functions in the same location relative
mmenke
2011/11/11 03:33:01
nit: Use const whenever appropriate.
selim
2011/11/11 19:30:58
done
selim
2011/11/11 19:30:58
done
| |
| 325 void set_cleanup_timer_enabled( bool enabled ); | |
|
mmenke
2011/11/11 03:33:01
Since this is more than a simple setter, use SetCl
mmenke
2011/11/11 03:33:01
nit: Google style is "(bool enabled)". See http:
selim
2011/11/11 19:30:58
done
| |
| 326 | |
| 319 private: | 327 private: |
| 320 friend class base::RefCounted<ClientSocketPoolBaseHelper>; | 328 friend class base::RefCounted<ClientSocketPoolBaseHelper>; |
| 321 | 329 |
| 322 // Entry for a persistent socket which became idle at time |start_time|. | 330 // Entry for a persistent socket which became idle at time |start_time|. |
| 323 struct IdleSocket { | 331 struct IdleSocket { |
| 324 IdleSocket() : socket(NULL) {} | 332 IdleSocket() : socket(NULL) {} |
| 325 | 333 |
| 326 // An idle socket should be removed if it can't be reused, or has been idle | 334 // An idle socket should be removed if it can't be reused, or has been idle |
| 327 // for too long. |now| is the current time value (TimeTicks::Now()). | 335 // for too long. |now| is the current time value (TimeTicks::Now()). |
| 328 // |timeout| is the length of time to wait before timing out an idle socket. | 336 // |timeout| is the length of time to wait before timing out an idle socket. |
| (...skipping 106 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(); | |
|
mmenke
2011/11/11 03:33:01
nit: Google style is "StartIdleSocketTimer()". S
selim
2011/11/11 19:30:58
done
| |
| 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() { | |
|
mmenke
2011/11/11 03:33:01
nit: const
selim
2011/11/11 19:30:58
done
| |
| 723 return helper_.cleanup_timer_enabled(); | |
| 724 } | |
| 725 | |
| 726 void set_cleanup_timer_enabled( bool enabled ) { | |
|
mmenke
2011/11/11 03:33:01
nit: Google style is "(bool enabled)"
selim
2011/11/11 19:30:58
done
| |
| 727 return helper_.set_cleanup_timer_enabled( enabled ); | |
|
mmenke
2011/11/11 03:33:01
nit: Google style is "(enabled)"
selim
2011/11/11 19:30:58
done
| |
| 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 |