| 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 26 matching lines...) Expand all Loading... |
| 37 #include "base/timer.h" | 37 #include "base/timer.h" |
| 38 #include "net/base/address_list.h" | 38 #include "net/base/address_list.h" |
| 39 #include "net/base/completion_callback.h" | 39 #include "net/base/completion_callback.h" |
| 40 #include "net/base/load_states.h" | 40 #include "net/base/load_states.h" |
| 41 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 42 #include "net/base/net_export.h" | 42 #include "net/base/net_export.h" |
| 43 #include "net/base/net_log.h" | 43 #include "net/base/net_log.h" |
| 44 #include "net/base/network_change_notifier.h" | 44 #include "net/base/network_change_notifier.h" |
| 45 #include "net/base/request_priority.h" | 45 #include "net/base/request_priority.h" |
| 46 #include "net/socket/client_socket_pool.h" | 46 #include "net/socket/client_socket_pool.h" |
| 47 #include "net/socket/connect_timing.h" |
| 47 #include "net/socket/stream_socket.h" | 48 #include "net/socket/stream_socket.h" |
| 48 | 49 |
| 49 namespace net { | 50 namespace net { |
| 50 | 51 |
| 51 class ClientSocketHandle; | 52 class ClientSocketHandle; |
| 52 | 53 |
| 53 // Returns the client socket reuse policy. | 54 // Returns the client socket reuse policy. |
| 54 NET_EXPORT_PRIVATE int GetSocketReusePolicy(); | 55 NET_EXPORT_PRIVATE int GetSocketReusePolicy(); |
| 55 | 56 |
| 56 // Sets the client socket reuse policy. | 57 // Sets the client socket reuse policy. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // if it succeeded. | 98 // if it succeeded. |
| 98 int Connect(); | 99 int Connect(); |
| 99 | 100 |
| 100 virtual LoadState GetLoadState() const = 0; | 101 virtual LoadState GetLoadState() const = 0; |
| 101 | 102 |
| 102 // If Connect returns an error (or OnConnectJobComplete reports an error | 103 // If Connect returns an error (or OnConnectJobComplete reports an error |
| 103 // result) this method will be called, allowing the pool to add | 104 // result) this method will be called, allowing the pool to add |
| 104 // additional error state to the ClientSocketHandle (post late-binding). | 105 // additional error state to the ClientSocketHandle (post late-binding). |
| 105 virtual void GetAdditionalErrorState(ClientSocketHandle* handle) {} | 106 virtual void GetAdditionalErrorState(ClientSocketHandle* handle) {} |
| 106 | 107 |
| 108 const ConnectTiming& connect_timing() const { return connect_timing_; } |
| 109 |
| 107 const BoundNetLog& net_log() const { return net_log_; } | 110 const BoundNetLog& net_log() const { return net_log_; } |
| 108 | 111 |
| 109 protected: | 112 protected: |
| 110 void set_socket(StreamSocket* socket); | 113 void set_socket(StreamSocket* socket); |
| 111 StreamSocket* socket() { return socket_.get(); } | 114 StreamSocket* socket() { return socket_.get(); } |
| 112 void NotifyDelegateOfCompletion(int rv); | 115 void NotifyDelegateOfCompletion(int rv); |
| 113 void ResetTimer(base::TimeDelta remainingTime); | 116 void ResetTimer(base::TimeDelta remainingTime); |
| 114 | 117 |
| 118 // Connection establishment timing information. |
| 119 ConnectTiming connect_timing_; |
| 120 |
| 115 private: | 121 private: |
| 116 virtual int ConnectInternal() = 0; | 122 virtual int ConnectInternal() = 0; |
| 117 | 123 |
| 118 void LogConnectStart(); | 124 void LogConnectStart(); |
| 119 void LogConnectCompletion(int net_error); | 125 void LogConnectCompletion(int net_error); |
| 120 | 126 |
| 121 // Alerts the delegate that the ConnectJob has timed out. | 127 // Alerts the delegate that the ConnectJob has timed out. |
| 122 void OnTimeout(); | 128 void OnTimeout(); |
| 123 | 129 |
| 124 const std::string group_name_; | 130 const std::string group_name_; |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 492 |
| 487 // Tries to see if we can handle any more requests for |group|. | 493 // Tries to see if we can handle any more requests for |group|. |
| 488 void OnAvailableSocketSlot(const std::string& group_name, Group* group); | 494 void OnAvailableSocketSlot(const std::string& group_name, Group* group); |
| 489 | 495 |
| 490 // Process a pending socket request for a group. | 496 // Process a pending socket request for a group. |
| 491 void ProcessPendingRequest(const std::string& group_name, Group* group); | 497 void ProcessPendingRequest(const std::string& group_name, Group* group); |
| 492 | 498 |
| 493 // Assigns |socket| to |handle| and updates |group|'s counters appropriately. | 499 // Assigns |socket| to |handle| and updates |group|'s counters appropriately. |
| 494 void HandOutSocket(StreamSocket* socket, | 500 void HandOutSocket(StreamSocket* socket, |
| 495 bool reused, | 501 bool reused, |
| 502 const ConnectTiming& connect_timing, |
| 496 ClientSocketHandle* handle, | 503 ClientSocketHandle* handle, |
| 497 base::TimeDelta time_idle, | 504 base::TimeDelta time_idle, |
| 498 Group* group, | 505 Group* group, |
| 499 const BoundNetLog& net_log); | 506 const BoundNetLog& net_log); |
| 500 | 507 |
| 501 // Adds |socket| to the list of idle sockets for |group|. | 508 // Adds |socket| to the list of idle sockets for |group|. |
| 502 void AddIdleSocket(StreamSocket* socket, Group* group); | 509 void AddIdleSocket(StreamSocket* socket, Group* group); |
| 503 | 510 |
| 504 // Iterates through |group_map_|, canceling all ConnectJobs and deleting | 511 // Iterates through |group_map_|, canceling all ConnectJobs and deleting |
| 505 // groups if they are no longer needed. | 512 // groups if they are no longer needed. |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 // Histograms for the pool | 812 // Histograms for the pool |
| 806 ClientSocketPoolHistograms* const histograms_; | 813 ClientSocketPoolHistograms* const histograms_; |
| 807 internal::ClientSocketPoolBaseHelper helper_; | 814 internal::ClientSocketPoolBaseHelper helper_; |
| 808 | 815 |
| 809 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 816 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
| 810 }; | 817 }; |
| 811 | 818 |
| 812 } // namespace net | 819 } // namespace net |
| 813 | 820 |
| 814 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 821 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |