| 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 const Request& request, | 270 const Request& request, |
| 271 int num_sockets); | 271 int num_sockets); |
| 272 | 272 |
| 273 // See ClientSocketPool::CancelRequest for documentation on this function. | 273 // See ClientSocketPool::CancelRequest for documentation on this function. |
| 274 void CancelRequest(const std::string& group_name, | 274 void CancelRequest(const std::string& group_name, |
| 275 ClientSocketHandle* handle); | 275 ClientSocketHandle* handle); |
| 276 | 276 |
| 277 // See ClientSocketPool::ReleaseSocket for documentation on this function. | 277 // See ClientSocketPool::ReleaseSocket for documentation on this function. |
| 278 void ReleaseSocket(const std::string& group_name, | 278 void ReleaseSocket(const std::string& group_name, |
| 279 std::unique_ptr<StreamSocket> socket, | 279 std::unique_ptr<StreamSocket> socket, |
| 280 int id); | 280 int id, |
| 281 const LoadTimingInfo::ConnectTiming& connect_timing); |
| 281 | 282 |
| 282 // See ClientSocketPool::FlushWithError for documentation on this function. | 283 // See ClientSocketPool::FlushWithError for documentation on this function. |
| 283 void FlushWithError(int error); | 284 void FlushWithError(int error); |
| 284 | 285 |
| 285 // See ClientSocketPool::CloseIdleSockets for documentation on this function. | 286 // See ClientSocketPool::CloseIdleSockets for documentation on this function. |
| 286 void CloseIdleSockets(); | 287 void CloseIdleSockets(); |
| 287 | 288 |
| 288 // See ClientSocketPool::IdleSocketCount() for documentation on this function. | 289 // See ClientSocketPool::IdleSocketCount() for documentation on this function. |
| 289 int idle_socket_count() const { | 290 int idle_socket_count() const { |
| 290 return idle_socket_count_; | 291 return idle_socket_count_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 // unread data would be mistaken for the beginning of the next response if | 364 // unread data would be mistaken for the beginning of the next response if |
| 364 // we were to use the socket for a new request. | 365 // we were to use the socket for a new request. |
| 365 // | 366 // |
| 366 // Note that a socket that has never been used before (like a preconnected | 367 // Note that a socket that has never been used before (like a preconnected |
| 367 // socket) may be used even with unread data. This may be, e.g., a SPDY | 368 // socket) may be used even with unread data. This may be, e.g., a SPDY |
| 368 // SETTINGS frame. | 369 // SETTINGS frame. |
| 369 bool IsUsable() const; | 370 bool IsUsable() const; |
| 370 | 371 |
| 371 StreamSocket* socket; | 372 StreamSocket* socket; |
| 372 base::TimeTicks start_time; | 373 base::TimeTicks start_time; |
| 374 // ConnectTiming of the connection establishment. |
| 375 LoadTimingInfo::ConnectTiming connect_timing; |
| 373 }; | 376 }; |
| 374 | 377 |
| 375 typedef PriorityQueue<const Request*> RequestQueue; | 378 typedef PriorityQueue<const Request*> RequestQueue; |
| 376 typedef std::map<const ClientSocketHandle*, const Request*> RequestMap; | 379 typedef std::map<const ClientSocketHandle*, const Request*> RequestMap; |
| 377 | 380 |
| 378 // A Group is allocated per group_name when there are idle sockets or pending | 381 // A Group is allocated per group_name when there are idle sockets or pending |
| 379 // requests. Otherwise, the Group object is removed from the map. | 382 // requests. Otherwise, the Group object is removed from the map. |
| 380 // |active_socket_count| tracks the number of sockets held by clients. | 383 // |active_socket_count| tracks the number of sockets held by clients. |
| 381 class Group { | 384 class Group { |
| 382 public: | 385 public: |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 // Assigns |socket| to |handle| and updates |group|'s counters appropriately. | 548 // Assigns |socket| to |handle| and updates |group|'s counters appropriately. |
| 546 void HandOutSocket(std::unique_ptr<StreamSocket> socket, | 549 void HandOutSocket(std::unique_ptr<StreamSocket> socket, |
| 547 ClientSocketHandle::SocketReuseType reuse_type, | 550 ClientSocketHandle::SocketReuseType reuse_type, |
| 548 const LoadTimingInfo::ConnectTiming& connect_timing, | 551 const LoadTimingInfo::ConnectTiming& connect_timing, |
| 549 ClientSocketHandle* handle, | 552 ClientSocketHandle* handle, |
| 550 base::TimeDelta time_idle, | 553 base::TimeDelta time_idle, |
| 551 Group* group, | 554 Group* group, |
| 552 const NetLogWithSource& net_log); | 555 const NetLogWithSource& net_log); |
| 553 | 556 |
| 554 // Adds |socket| to the list of idle sockets for |group|. | 557 // Adds |socket| to the list of idle sockets for |group|. |
| 555 void AddIdleSocket(std::unique_ptr<StreamSocket> socket, Group* group); | 558 // |connect_timing| is the connect timing of the connection establishment; |
| 559 void AddIdleSocket(std::unique_ptr<StreamSocket> socket, |
| 560 Group* group, |
| 561 const LoadTimingInfo::ConnectTiming& connect_timing); |
| 556 | 562 |
| 557 // Iterates through |group_map_|, canceling all ConnectJobs and deleting | 563 // Iterates through |group_map_|, canceling all ConnectJobs and deleting |
| 558 // groups if they are no longer needed. | 564 // groups if they are no longer needed. |
| 559 void CancelAllConnectJobs(); | 565 void CancelAllConnectJobs(); |
| 560 | 566 |
| 561 // Iterates through |group_map_|, posting |error| callbacks for all | 567 // Iterates through |group_map_|, posting |error| callbacks for all |
| 562 // requests, and then deleting groups if they are no longer needed. | 568 // requests, and then deleting groups if they are no longer needed. |
| 563 void CancelAllRequestsWithError(int error); | 569 void CancelAllRequestsWithError(int error); |
| 564 | 570 |
| 565 // Returns true if we can't create any more sockets due to the total limit. | 571 // Returns true if we can't create any more sockets due to the total limit. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 helper_.RequestSockets(group_name, request, num_sockets); | 771 helper_.RequestSockets(group_name, request, num_sockets); |
| 766 } | 772 } |
| 767 | 773 |
| 768 void CancelRequest(const std::string& group_name, | 774 void CancelRequest(const std::string& group_name, |
| 769 ClientSocketHandle* handle) { | 775 ClientSocketHandle* handle) { |
| 770 return helper_.CancelRequest(group_name, handle); | 776 return helper_.CancelRequest(group_name, handle); |
| 771 } | 777 } |
| 772 | 778 |
| 773 void ReleaseSocket(const std::string& group_name, | 779 void ReleaseSocket(const std::string& group_name, |
| 774 std::unique_ptr<StreamSocket> socket, | 780 std::unique_ptr<StreamSocket> socket, |
| 775 int id) { | 781 int id, |
| 776 return helper_.ReleaseSocket(group_name, std::move(socket), id); | 782 const LoadTimingInfo::ConnectTiming& connect_timing) { |
| 783 return helper_.ReleaseSocket(group_name, std::move(socket), id, |
| 784 connect_timing); |
| 777 } | 785 } |
| 778 | 786 |
| 779 void FlushWithError(int error) { helper_.FlushWithError(error); } | 787 void FlushWithError(int error) { helper_.FlushWithError(error); } |
| 780 | 788 |
| 781 bool IsStalled() const { return helper_.IsStalled(); } | 789 bool IsStalled() const { return helper_.IsStalled(); } |
| 782 | 790 |
| 783 void CloseIdleSockets() { return helper_.CloseIdleSockets(); } | 791 void CloseIdleSockets() { return helper_.CloseIdleSockets(); } |
| 784 | 792 |
| 785 int idle_socket_count() const { return helper_.idle_socket_count(); } | 793 int idle_socket_count() const { return helper_.idle_socket_count(); } |
| 786 | 794 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 }; | 876 }; |
| 869 | 877 |
| 870 internal::ClientSocketPoolBaseHelper helper_; | 878 internal::ClientSocketPoolBaseHelper helper_; |
| 871 | 879 |
| 872 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 880 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
| 873 }; | 881 }; |
| 874 | 882 |
| 875 } // namespace net | 883 } // namespace net |
| 876 | 884 |
| 877 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 885 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |