| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // A |timeout_duration| of 0 corresponds to no timeout. | 63 // A |timeout_duration| of 0 corresponds to no timeout. |
| 64 ConnectJob(const std::string& group_name, | 64 ConnectJob(const std::string& group_name, |
| 65 const ClientSocketHandle* key_handle, | 65 const ClientSocketHandle* key_handle, |
| 66 base::TimeDelta timeout_duration, | 66 base::TimeDelta timeout_duration, |
| 67 Delegate* delegate, | 67 Delegate* delegate, |
| 68 LoadLog* load_log); | 68 LoadLog* load_log); |
| 69 virtual ~ConnectJob(); | 69 virtual ~ConnectJob(); |
| 70 | 70 |
| 71 // Accessors | 71 // Accessors |
| 72 const std::string& group_name() const { return group_name_; } | 72 const std::string& group_name() const { return group_name_; } |
| 73 LoadState load_state() const { return load_state_; } | |
| 74 const ClientSocketHandle* key_handle() const { return key_handle_; } | 73 const ClientSocketHandle* key_handle() const { return key_handle_; } |
| 74 LoadLog* load_log() { return load_log_; } |
| 75 | 75 |
| 76 // Releases |socket_| to the client. On connection error, this should return | 76 // Releases |socket_| to the client. On connection error, this should return |
| 77 // NULL. | 77 // NULL. |
| 78 ClientSocket* ReleaseSocket() { return socket_.release(); } | 78 ClientSocket* ReleaseSocket() { return socket_.release(); } |
| 79 | 79 |
| 80 // Begins connecting the socket. Returns OK on success, ERR_IO_PENDING if it | 80 // Begins connecting the socket. Returns OK on success, ERR_IO_PENDING if it |
| 81 // cannot complete synchronously without blocking, or another net error code | 81 // cannot complete synchronously without blocking, or another net error code |
| 82 // on error. In asynchronous completion, the ConnectJob will notify | 82 // on error. In asynchronous completion, the ConnectJob will notify |
| 83 // |delegate_| via OnConnectJobComplete. In both asynchronous and synchronous | 83 // |delegate_| via OnConnectJobComplete. In both asynchronous and synchronous |
| 84 // completion, ReleaseSocket() can be called to acquire the connected socket | 84 // completion, ReleaseSocket() can be called to acquire the connected socket |
| 85 // if it succeeded. | 85 // if it succeeded. |
| 86 int Connect(); | 86 int Connect(); |
| 87 | 87 |
| 88 LoadLog* load_log() { return load_log_; } | 88 virtual LoadState GetLoadState() const = 0; |
| 89 | 89 |
| 90 protected: | 90 protected: |
| 91 void set_load_state(LoadState load_state) { load_state_ = load_state; } | |
| 92 void set_socket(ClientSocket* socket) { socket_.reset(socket); } | 91 void set_socket(ClientSocket* socket) { socket_.reset(socket); } |
| 93 ClientSocket* socket() { return socket_.get(); } | 92 ClientSocket* socket() { return socket_.get(); } |
| 94 void NotifyDelegateOfCompletion(int rv); | 93 void NotifyDelegateOfCompletion(int rv); |
| 95 | 94 |
| 96 private: | 95 private: |
| 97 virtual int ConnectInternal() = 0; | 96 virtual int ConnectInternal() = 0; |
| 98 | 97 |
| 99 // Alerts the delegate that the ConnectJob has timed out. | 98 // Alerts the delegate that the ConnectJob has timed out. |
| 100 void OnTimeout(); | 99 void OnTimeout(); |
| 101 | 100 |
| 102 const std::string group_name_; | 101 const std::string group_name_; |
| 103 // Temporarily needed until we switch to late binding. | 102 // Temporarily needed until we switch to late binding. |
| 104 const ClientSocketHandle* const key_handle_; | 103 const ClientSocketHandle* const key_handle_; |
| 105 const base::TimeDelta timeout_duration_; | 104 const base::TimeDelta timeout_duration_; |
| 106 // Timer to abort jobs that take too long. | 105 // Timer to abort jobs that take too long. |
| 107 base::OneShotTimer<ConnectJob> timer_; | 106 base::OneShotTimer<ConnectJob> timer_; |
| 108 Delegate* delegate_; | 107 Delegate* delegate_; |
| 109 LoadState load_state_; | |
| 110 scoped_ptr<ClientSocket> socket_; | 108 scoped_ptr<ClientSocket> socket_; |
| 111 scoped_refptr<LoadLog> load_log_; | 109 scoped_refptr<LoadLog> load_log_; |
| 112 | 110 |
| 113 DISALLOW_COPY_AND_ASSIGN(ConnectJob); | 111 DISALLOW_COPY_AND_ASSIGN(ConnectJob); |
| 114 }; | 112 }; |
| 115 | 113 |
| 116 namespace internal { | 114 namespace internal { |
| 117 | 115 |
| 118 // ClientSocketPoolBaseHelper is an internal class that implements almost all | 116 // ClientSocketPoolBaseHelper is an internal class that implements almost all |
| 119 // the functionality from ClientSocketPoolBase without using templates. | 117 // the functionality from ClientSocketPoolBase without using templates. |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 // decoupled from socket connection jobs. A socket request may initiate a | 527 // decoupled from socket connection jobs. A socket request may initiate a |
| 530 // socket connection job, but there is no guarantee that that socket | 528 // socket connection job, but there is no guarantee that that socket |
| 531 // connection will service the request (for example, a released socket may | 529 // connection will service the request (for example, a released socket may |
| 532 // service the request sooner, or a higher priority request may come in | 530 // service the request sooner, or a higher priority request may come in |
| 533 // afterward and receive the socket from the job). | 531 // afterward and receive the socket from the job). |
| 534 void EnableLateBindingOfSockets(bool enabled); | 532 void EnableLateBindingOfSockets(bool enabled); |
| 535 | 533 |
| 536 } // namespace net | 534 } // namespace net |
| 537 | 535 |
| 538 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 536 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |