| 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) |
| 11 // limiting the total number of active sockets in the system. | 11 // limiting the total number of active sockets in the system. |
| 12 // | 12 // |
| 13 // ClientSocketPoolBase abstracts socket connection details behind ConnectJob, | 13 // ClientSocketPoolBase abstracts socket connection details behind ConnectJob, |
| 14 // ConnectJobFactory, and SocketParams. When a socket "slot" becomes available, | 14 // ConnectJobFactory, and SocketParams. When a socket "slot" becomes available, |
| 15 // the ClientSocketPoolBase will ask the ConnectJobFactory to create a | 15 // the ClientSocketPoolBase will ask the ConnectJobFactory to create a |
| 16 // ConnectJob with a SocketParams. Subclasses of ClientSocketPool should | 16 // ConnectJob with a SocketParams. Subclasses of ClientSocketPool should |
| 17 // implement their socket specific connection by subclassing ConnectJob and | 17 // implement their socket specific connection by subclassing ConnectJob and |
| 18 // implementing ConnectJob::ConnectInternal(). They can control the parameters | 18 // implementing ConnectJob::ConnectInternal(). They can control the parameters |
| 19 // passed to each new ConnectJob instance via their ConnectJobFactory subclass | 19 // passed to each new ConnectJob instance via their ConnectJobFactory subclass |
| 20 // and templated SocketParams parameter. | 20 // and templated SocketParams parameter. |
| 21 // | 21 // |
| 22 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 22 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| 23 #define NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 23 #define NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| 24 | 24 |
| 25 #include <stddef.h> | 25 #include <stddef.h> |
| 26 #include <stdint.h> | 26 #include <stdint.h> |
| 27 | |
| 28 #include <cstddef> | 27 #include <cstddef> |
| 29 #include <deque> | 28 #include <deque> |
| 30 #include <list> | 29 #include <list> |
| 31 #include <map> | 30 #include <map> |
| 32 #include <set> | 31 #include <set> |
| 33 #include <string> | 32 #include <string> |
| 33 #include <utility> |
| 34 #include <vector> | 34 #include <vector> |
| 35 | 35 |
| 36 #include "base/macros.h" | 36 #include "base/macros.h" |
| 37 #include "base/memory/ref_counted.h" | 37 #include "base/memory/ref_counted.h" |
| 38 #include "base/memory/scoped_ptr.h" | 38 #include "base/memory/scoped_ptr.h" |
| 39 #include "base/memory/weak_ptr.h" | 39 #include "base/memory/weak_ptr.h" |
| 40 #include "base/time/time.h" | 40 #include "base/time/time.h" |
| 41 #include "base/timer/timer.h" | 41 #include "base/timer/timer.h" |
| 42 #include "net/base/address_list.h" | 42 #include "net/base/address_list.h" |
| 43 #include "net/base/completion_callback.h" | 43 #include "net/base/completion_callback.h" |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 const scoped_refptr<SocketParams>& params, | 750 const scoped_refptr<SocketParams>& params, |
| 751 RequestPriority priority, | 751 RequestPriority priority, |
| 752 ClientSocketHandle* handle, | 752 ClientSocketHandle* handle, |
| 753 const CompletionCallback& callback, | 753 const CompletionCallback& callback, |
| 754 const BoundNetLog& net_log) { | 754 const BoundNetLog& net_log) { |
| 755 scoped_ptr<const Request> request( | 755 scoped_ptr<const Request> request( |
| 756 new Request(handle, callback, priority, | 756 new Request(handle, callback, priority, |
| 757 internal::ClientSocketPoolBaseHelper::NORMAL, | 757 internal::ClientSocketPoolBaseHelper::NORMAL, |
| 758 params->ignore_limits(), | 758 params->ignore_limits(), |
| 759 params, net_log)); | 759 params, net_log)); |
| 760 return helper_.RequestSocket(group_name, request.Pass()); | 760 return helper_.RequestSocket(group_name, std::move(request)); |
| 761 } | 761 } |
| 762 | 762 |
| 763 // RequestSockets bundles up the parameters into a Request and then forwards | 763 // RequestSockets bundles up the parameters into a Request and then forwards |
| 764 // to ClientSocketPoolBaseHelper::RequestSockets(). Note that it assigns the | 764 // to ClientSocketPoolBaseHelper::RequestSockets(). Note that it assigns the |
| 765 // priority to IDLE and specifies the NO_IDLE_SOCKETS flag. | 765 // priority to IDLE and specifies the NO_IDLE_SOCKETS flag. |
| 766 void RequestSockets(const std::string& group_name, | 766 void RequestSockets(const std::string& group_name, |
| 767 const scoped_refptr<SocketParams>& params, | 767 const scoped_refptr<SocketParams>& params, |
| 768 int num_sockets, | 768 int num_sockets, |
| 769 const BoundNetLog& net_log) { | 769 const BoundNetLog& net_log) { |
| 770 const Request request(NULL /* no handle */, CompletionCallback(), IDLE, | 770 const Request request(NULL /* no handle */, CompletionCallback(), IDLE, |
| 771 internal::ClientSocketPoolBaseHelper::NO_IDLE_SOCKETS, | 771 internal::ClientSocketPoolBaseHelper::NO_IDLE_SOCKETS, |
| 772 params->ignore_limits(), params, net_log); | 772 params->ignore_limits(), params, net_log); |
| 773 helper_.RequestSockets(group_name, request, num_sockets); | 773 helper_.RequestSockets(group_name, request, num_sockets); |
| 774 } | 774 } |
| 775 | 775 |
| 776 void CancelRequest(const std::string& group_name, | 776 void CancelRequest(const std::string& group_name, |
| 777 ClientSocketHandle* handle) { | 777 ClientSocketHandle* handle) { |
| 778 return helper_.CancelRequest(group_name, handle); | 778 return helper_.CancelRequest(group_name, handle); |
| 779 } | 779 } |
| 780 | 780 |
| 781 void ReleaseSocket(const std::string& group_name, | 781 void ReleaseSocket(const std::string& group_name, |
| 782 scoped_ptr<StreamSocket> socket, | 782 scoped_ptr<StreamSocket> socket, |
| 783 int id) { | 783 int id) { |
| 784 return helper_.ReleaseSocket(group_name, socket.Pass(), id); | 784 return helper_.ReleaseSocket(group_name, std::move(socket), id); |
| 785 } | 785 } |
| 786 | 786 |
| 787 void FlushWithError(int error) { helper_.FlushWithError(error); } | 787 void FlushWithError(int error) { helper_.FlushWithError(error); } |
| 788 | 788 |
| 789 bool IsStalled() const { return helper_.IsStalled(); } | 789 bool IsStalled() const { return helper_.IsStalled(); } |
| 790 | 790 |
| 791 void CloseIdleSockets() { return helper_.CloseIdleSockets(); } | 791 void CloseIdleSockets() { return helper_.CloseIdleSockets(); } |
| 792 | 792 |
| 793 int idle_socket_count() const { return helper_.idle_socket_count(); } | 793 int idle_socket_count() const { return helper_.idle_socket_count(); } |
| 794 | 794 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 }; | 875 }; |
| 876 | 876 |
| 877 internal::ClientSocketPoolBaseHelper helper_; | 877 internal::ClientSocketPoolBaseHelper helper_; |
| 878 | 878 |
| 879 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 879 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
| 880 }; | 880 }; |
| 881 | 881 |
| 882 } // namespace net | 882 } // namespace net |
| 883 | 883 |
| 884 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 884 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |