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 // 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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 private: | 695 private: |
696 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); | 696 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); |
697 }; | 697 }; |
698 | 698 |
699 // |max_sockets| is the maximum number of sockets to be maintained by this | 699 // |max_sockets| is the maximum number of sockets to be maintained by this |
700 // ClientSocketPool. |max_sockets_per_group| specifies the maximum number of | 700 // ClientSocketPool. |max_sockets_per_group| specifies the maximum number of |
701 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how | 701 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how |
702 // long to leave an unused idle socket open before closing it. | 702 // long to leave an unused idle socket open before closing it. |
703 // |used_idle_socket_timeout| specifies how long to leave a previously used | 703 // |used_idle_socket_timeout| specifies how long to leave a previously used |
704 // idle socket open before closing it. | 704 // idle socket open before closing it. |
705 ClientSocketPoolBase( | 705 ClientSocketPoolBase(HigherLayeredPool* self, |
706 HigherLayeredPool* self, | 706 int max_sockets, |
707 int max_sockets, | 707 int max_sockets_per_group, |
708 int max_sockets_per_group, | 708 base::TimeDelta unused_idle_socket_timeout, |
709 ClientSocketPoolHistograms* histograms, | 709 base::TimeDelta used_idle_socket_timeout, |
710 base::TimeDelta unused_idle_socket_timeout, | 710 ConnectJobFactory* connect_job_factory) |
711 base::TimeDelta used_idle_socket_timeout, | 711 : helper_(self, |
712 ConnectJobFactory* connect_job_factory) | 712 max_sockets, |
713 : histograms_(histograms), | 713 max_sockets_per_group, |
714 helper_(self, max_sockets, max_sockets_per_group, | 714 unused_idle_socket_timeout, |
715 unused_idle_socket_timeout, used_idle_socket_timeout, | 715 used_idle_socket_timeout, |
716 new ConnectJobFactoryAdaptor(connect_job_factory)) {} | 716 new ConnectJobFactoryAdaptor(connect_job_factory)) {} |
717 | 717 |
718 virtual ~ClientSocketPoolBase() {} | 718 virtual ~ClientSocketPoolBase() {} |
719 | 719 |
720 // These member functions simply forward to ClientSocketPoolBaseHelper. | 720 // These member functions simply forward to ClientSocketPoolBaseHelper. |
721 void AddLowerLayeredPool(LowerLayeredPool* lower_pool) { | 721 void AddLowerLayeredPool(LowerLayeredPool* lower_pool) { |
722 helper_.AddLowerLayeredPool(lower_pool); | 722 helper_.AddLowerLayeredPool(lower_pool); |
723 } | 723 } |
724 | 724 |
725 void AddHigherLayeredPool(HigherLayeredPool* higher_pool) { | 725 void AddHigherLayeredPool(HigherLayeredPool* higher_pool) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 817 |
818 base::DictionaryValue* GetInfoAsValue(const std::string& name, | 818 base::DictionaryValue* GetInfoAsValue(const std::string& name, |
819 const std::string& type) const { | 819 const std::string& type) const { |
820 return helper_.GetInfoAsValue(name, type); | 820 return helper_.GetInfoAsValue(name, type); |
821 } | 821 } |
822 | 822 |
823 base::TimeDelta ConnectionTimeout() const { | 823 base::TimeDelta ConnectionTimeout() const { |
824 return helper_.ConnectionTimeout(); | 824 return helper_.ConnectionTimeout(); |
825 } | 825 } |
826 | 826 |
827 ClientSocketPoolHistograms* histograms() const { | |
828 return histograms_; | |
829 } | |
830 | |
831 void EnableConnectBackupJobs() { helper_.EnableConnectBackupJobs(); } | 827 void EnableConnectBackupJobs() { helper_.EnableConnectBackupJobs(); } |
832 | 828 |
833 bool CloseOneIdleSocket() { return helper_.CloseOneIdleSocket(); } | 829 bool CloseOneIdleSocket() { return helper_.CloseOneIdleSocket(); } |
834 | 830 |
835 bool CloseOneIdleConnectionInHigherLayeredPool() { | 831 bool CloseOneIdleConnectionInHigherLayeredPool() { |
836 return helper_.CloseOneIdleConnectionInHigherLayeredPool(); | 832 return helper_.CloseOneIdleConnectionInHigherLayeredPool(); |
837 } | 833 } |
838 | 834 |
839 private: | 835 private: |
840 // This adaptor class exists to bridge the | 836 // This adaptor class exists to bridge the |
(...skipping 20 matching lines...) Expand all Loading... |
861 group_name, casted_request, delegate); | 857 group_name, casted_request, delegate); |
862 } | 858 } |
863 | 859 |
864 base::TimeDelta ConnectionTimeout() const override { | 860 base::TimeDelta ConnectionTimeout() const override { |
865 return connect_job_factory_->ConnectionTimeout(); | 861 return connect_job_factory_->ConnectionTimeout(); |
866 } | 862 } |
867 | 863 |
868 const scoped_ptr<ConnectJobFactory> connect_job_factory_; | 864 const scoped_ptr<ConnectJobFactory> connect_job_factory_; |
869 }; | 865 }; |
870 | 866 |
871 // Histograms for the pool | |
872 ClientSocketPoolHistograms* const histograms_; | |
873 internal::ClientSocketPoolBaseHelper helper_; | 867 internal::ClientSocketPoolBaseHelper helper_; |
874 | 868 |
875 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 869 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
876 }; | 870 }; |
877 | 871 |
878 } // namespace net | 872 } // namespace net |
879 | 873 |
880 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 874 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |