[email protected] | 5acdce1 | 2011-03-30 13:00:20 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/socket/client_socket_pool_base.h" |
| 6 | |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 7 | #include <math.h> |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 9 | #include "base/format_macros.h" |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 11 | #include "base/message_loop.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 12 | #include "base/metrics/stats_counters.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 13 | #include "base/stl_util.h" |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 14 | #include "base/string_number_conversions.h" |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 15 | #include "base/string_util.h" |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 16 | #include "base/time.h" |
[email protected] | 9349cfb | 2010-08-31 18:00:53 | [diff] [blame] | 17 | #include "base/values.h" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 18 | #include "net/base/net_log.h" |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 19 | #include "net/base/net_errors.h" |
| 20 | #include "net/socket/client_socket_handle.h" |
| 21 | |
| 22 | using base::TimeDelta; |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | // The timeout value, in seconds, used to clean up idle sockets that can't be |
| 27 | // reused. |
| 28 | // |
| 29 | // Note: It's important to close idle sockets that have received data as soon |
| 30 | // as possible because the received data may cause BSOD on Windows XP under |
| 31 | // some conditions. See http://crbug.com/4606. |
| 32 | const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT. |
| 33 | |
[email protected] | c847c2a | 2011-04-08 13:56:14 | [diff] [blame] | 34 | // Indicate whether or not we should establish a new transport layer connection |
| 35 | // after a certain timeout has passed without receiving an ACK. |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 36 | bool g_connect_backup_jobs_enabled = true; |
| 37 | |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 38 | double g_socket_reuse_policy_penalty_exponent = -1; |
| 39 | int g_socket_reuse_policy = -1; |
| 40 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 41 | } // namespace |
| 42 | |
| 43 | namespace net { |
| 44 | |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 45 | int GetSocketReusePolicy() { |
| 46 | return g_socket_reuse_policy; |
| 47 | } |
| 48 | |
| 49 | void SetSocketReusePolicy(int policy) { |
| 50 | DCHECK_GE(policy, 0); |
| 51 | DCHECK_LE(policy, 2); |
| 52 | if (policy > 2 || policy < 0) { |
| 53 | LOG(ERROR) << "Invalid socket reuse policy"; |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | double exponents[] = { 0, 0.25, -1 }; |
| 58 | g_socket_reuse_policy_penalty_exponent = exponents[policy]; |
| 59 | g_socket_reuse_policy = policy; |
| 60 | |
| 61 | VLOG(1) << "Setting g_socket_reuse_policy_penalty_exponent = " |
| 62 | << g_socket_reuse_policy_penalty_exponent; |
| 63 | } |
| 64 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 65 | ConnectJob::ConnectJob(const std::string& group_name, |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 66 | base::TimeDelta timeout_duration, |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 67 | Delegate* delegate, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 68 | const BoundNetLog& net_log) |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 69 | : group_name_(group_name), |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 70 | timeout_duration_(timeout_duration), |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 71 | delegate_(delegate), |
[email protected] | a2006ece | 2010-04-23 16:44:02 | [diff] [blame] | 72 | net_log_(net_log), |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 73 | idle_(true), |
| 74 | preconnect_state_(NOT_PRECONNECT) { |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 75 | DCHECK(!group_name.empty()); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 76 | DCHECK(delegate); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 77 | net_log.BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 80 | ConnectJob::~ConnectJob() { |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 81 | net_log().EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 82 | } |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 83 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 84 | void ConnectJob::Initialize(bool is_preconnect) { |
| 85 | if (is_preconnect) |
| 86 | preconnect_state_ = UNUSED_PRECONNECT; |
| 87 | else |
| 88 | preconnect_state_ = NOT_PRECONNECT; |
| 89 | } |
| 90 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 91 | int ConnectJob::Connect() { |
| 92 | if (timeout_duration_ != base::TimeDelta()) |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 93 | timer_.Start(FROM_HERE, timeout_duration_, this, &ConnectJob::OnTimeout); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 94 | |
[email protected] | a2006ece | 2010-04-23 16:44:02 | [diff] [blame] | 95 | idle_ = false; |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 96 | |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 97 | LogConnectStart(); |
| 98 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 99 | int rv = ConnectInternal(); |
| 100 | |
| 101 | if (rv != ERR_IO_PENDING) { |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 102 | LogConnectCompletion(rv); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 103 | delegate_ = NULL; |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | return rv; |
| 107 | } |
| 108 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 109 | void ConnectJob::UseForNormalRequest() { |
| 110 | DCHECK_EQ(UNUSED_PRECONNECT, preconnect_state_); |
| 111 | preconnect_state_ = USED_PRECONNECT; |
| 112 | } |
| 113 | |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 114 | void ConnectJob::set_socket(StreamSocket* socket) { |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 115 | if (socket) { |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 116 | net_log().AddEvent(NetLog::TYPE_CONNECT_JOB_SET_SOCKET, make_scoped_refptr( |
| 117 | new NetLogSourceParameter("source_dependency", |
| 118 | socket->NetLog().source()))); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 119 | } |
| 120 | socket_.reset(socket); |
| 121 | } |
| 122 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 123 | void ConnectJob::NotifyDelegateOfCompletion(int rv) { |
| 124 | // The delegate will delete |this|. |
| 125 | Delegate *delegate = delegate_; |
| 126 | delegate_ = NULL; |
| 127 | |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 128 | LogConnectCompletion(rv); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 129 | delegate->OnConnectJobComplete(rv, this); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 130 | } |
| 131 | |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 132 | void ConnectJob::ResetTimer(base::TimeDelta remaining_time) { |
| 133 | timer_.Stop(); |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 134 | timer_.Start(FROM_HERE, remaining_time, this, &ConnectJob::OnTimeout); |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 137 | void ConnectJob::LogConnectStart() { |
| 138 | net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT, |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 139 | make_scoped_refptr(new NetLogStringParameter("group_name", group_name_))); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void ConnectJob::LogConnectCompletion(int net_error) { |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 143 | net_log().EndEventWithNetErrorCode( |
| 144 | NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT, net_error); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 145 | } |
| 146 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 147 | void ConnectJob::OnTimeout() { |
[email protected] | 6e713f0 | 2009-08-06 02:56:40 | [diff] [blame] | 148 | // Make sure the socket is NULL before calling into |delegate|. |
| 149 | set_socket(NULL); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 150 | |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 151 | net_log_.AddEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT, NULL); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 152 | |
| 153 | NotifyDelegateOfCompletion(ERR_TIMED_OUT); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 154 | } |
| 155 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 156 | namespace internal { |
| 157 | |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 158 | ClientSocketPoolBaseHelper::Request::Request( |
| 159 | ClientSocketHandle* handle, |
[email protected] | f1f3f0f8 | 2011-10-01 20:38:10 | [diff] [blame] | 160 | OldCompletionCallback* callback, |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 161 | RequestPriority priority, |
[email protected] | 5acdce1 | 2011-03-30 13:00:20 | [diff] [blame] | 162 | bool ignore_limits, |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 163 | Flags flags, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 164 | const BoundNetLog& net_log) |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 165 | : handle_(handle), |
| 166 | callback_(callback), |
| 167 | priority_(priority), |
[email protected] | 5acdce1 | 2011-03-30 13:00:20 | [diff] [blame] | 168 | ignore_limits_(ignore_limits), |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 169 | flags_(flags), |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 170 | net_log_(net_log) {} |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 171 | |
| 172 | ClientSocketPoolBaseHelper::Request::~Request() {} |
| 173 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 174 | ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 175 | int max_sockets, |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 176 | int max_sockets_per_group, |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 177 | base::TimeDelta unused_idle_socket_timeout, |
| 178 | base::TimeDelta used_idle_socket_timeout, |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 179 | ConnectJobFactory* connect_job_factory) |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 180 | : idle_socket_count_(0), |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 181 | connecting_socket_count_(0), |
| 182 | handed_out_socket_count_(0), |
| 183 | max_sockets_(max_sockets), |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 184 | max_sockets_per_group_(max_sockets_per_group), |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 185 | unused_idle_socket_timeout_(unused_idle_socket_timeout), |
| 186 | used_idle_socket_timeout_(used_idle_socket_timeout), |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 187 | connect_job_factory_(connect_job_factory), |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 188 | connect_backup_jobs_enabled_(false), |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 189 | pool_generation_number_(0), |
| 190 | method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 191 | DCHECK_LE(0, max_sockets_per_group); |
| 192 | DCHECK_LE(max_sockets_per_group, max_sockets); |
[email protected] | a554a826 | 2010-05-20 00:13:52 | [diff] [blame] | 193 | |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 194 | NetworkChangeNotifier::AddIPAddressObserver(this); |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 195 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 196 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 197 | ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 198 | // Clean up any idle sockets and pending connect jobs. Assert that we have no |
| 199 | // remaining active sockets or pending requests. They should have all been |
| 200 | // cleaned up prior to |this| being destroyed. |
| 201 | Flush(); |
| 202 | DCHECK(group_map_.empty()); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 203 | DCHECK(pending_callback_map_.empty()); |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 204 | DCHECK_EQ(0, connecting_socket_count_); |
[email protected] | a554a826 | 2010-05-20 00:13:52 | [diff] [blame] | 205 | |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 206 | NetworkChangeNotifier::RemoveIPAddressObserver(this); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | // InsertRequestIntoQueue inserts the request into the queue based on |
| 210 | // priority. Highest priorities are closest to the front. Older requests are |
| 211 | // prioritized over requests of equal priority. |
| 212 | // |
| 213 | // static |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 214 | void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( |
| 215 | const Request* r, RequestQueue* pending_requests) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 216 | RequestQueue::iterator it = pending_requests->begin(); |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 217 | while (it != pending_requests->end() && r->priority() >= (*it)->priority()) |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 218 | ++it; |
| 219 | pending_requests->insert(it, r); |
| 220 | } |
| 221 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 222 | // static |
| 223 | const ClientSocketPoolBaseHelper::Request* |
| 224 | ClientSocketPoolBaseHelper::RemoveRequestFromQueue( |
[email protected] | 417da10 | 2011-03-11 17:45:05 | [diff] [blame] | 225 | const RequestQueue::iterator& it, Group* group) { |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 226 | const Request* req = *it; |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 227 | group->mutable_pending_requests()->erase(it); |
| 228 | // If there are no more requests, we kill the backup timer. |
| 229 | if (group->pending_requests().empty()) |
[email protected] | e4d9a972 | 2011-05-12 00:16:00 | [diff] [blame] | 230 | group->CleanupBackupJob(); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 231 | return req; |
| 232 | } |
| 233 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 234 | int ClientSocketPoolBaseHelper::RequestSocket( |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 235 | const std::string& group_name, |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 236 | const Request* request) { |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 237 | CHECK(request->callback()); |
| 238 | CHECK(request->handle()); |
| 239 | |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 240 | request->net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL, NULL); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 241 | Group* group = GetOrCreateGroup(group_name); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 242 | |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 243 | int rv = RequestSocketInternal(group_name, request); |
[email protected] | e7e9932 | 2010-05-04 23:30:17 | [diff] [blame] | 244 | if (rv != ERR_IO_PENDING) { |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 245 | request->net_log().EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_POOL, rv); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 246 | CHECK(!request->handle()->is_initialized()); |
[email protected] | e7e9932 | 2010-05-04 23:30:17 | [diff] [blame] | 247 | delete request; |
| 248 | } else { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 249 | InsertRequestIntoQueue(request, group->mutable_pending_requests()); |
[email protected] | e7e9932 | 2010-05-04 23:30:17 | [diff] [blame] | 250 | } |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 251 | return rv; |
| 252 | } |
| 253 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 254 | void ClientSocketPoolBaseHelper::RequestSockets( |
| 255 | const std::string& group_name, |
| 256 | const Request& request, |
| 257 | int num_sockets) { |
| 258 | DCHECK(!request.callback()); |
| 259 | DCHECK(!request.handle()); |
| 260 | |
| 261 | if (num_sockets > max_sockets_per_group_) { |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 262 | num_sockets = max_sockets_per_group_; |
| 263 | } |
| 264 | |
| 265 | request.net_log().BeginEvent( |
| 266 | NetLog::TYPE_SOCKET_POOL_CONNECTING_N_SOCKETS, |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 267 | make_scoped_refptr(new NetLogIntegerParameter( |
| 268 | "num_sockets", num_sockets))); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 269 | |
| 270 | Group* group = GetOrCreateGroup(group_name); |
| 271 | |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 272 | // RequestSocketsInternal() may delete the group. |
| 273 | bool deleted_group = false; |
| 274 | |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 275 | int rv = OK; |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 276 | for (int num_iterations_left = num_sockets; |
| 277 | group->NumActiveSocketSlots() < num_sockets && |
| 278 | num_iterations_left > 0 ; num_iterations_left--) { |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 279 | rv = RequestSocketInternal(group_name, &request); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 280 | if (rv < 0 && rv != ERR_IO_PENDING) { |
| 281 | // We're encountering a synchronous error. Give up. |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 282 | if (!ContainsKey(group_map_, group_name)) |
| 283 | deleted_group = true; |
| 284 | break; |
| 285 | } |
| 286 | if (!ContainsKey(group_map_, group_name)) { |
| 287 | // Unexpected. The group should only be getting deleted on synchronous |
| 288 | // error. |
| 289 | NOTREACHED(); |
| 290 | deleted_group = true; |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 291 | break; |
| 292 | } |
| 293 | } |
| 294 | |
[email protected] | 3c819f52 | 2010-12-02 02:03:12 | [diff] [blame] | 295 | if (!deleted_group && group->IsEmpty()) |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 296 | RemoveGroup(group_name); |
| 297 | |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 298 | if (rv == ERR_IO_PENDING) |
| 299 | rv = OK; |
| 300 | request.net_log().EndEventWithNetErrorCode( |
| 301 | NetLog::TYPE_SOCKET_POOL_CONNECTING_N_SOCKETS, rv); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 304 | int ClientSocketPoolBaseHelper::RequestSocketInternal( |
| 305 | const std::string& group_name, |
| 306 | const Request* request) { |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 307 | DCHECK_GE(request->priority(), 0); |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 308 | ClientSocketHandle* const handle = request->handle(); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 309 | const bool preconnecting = !handle; |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 310 | Group* group = GetOrCreateGroup(group_name); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 311 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 312 | if (!(request->flags() & NO_IDLE_SOCKETS)) { |
| 313 | // Try to reuse a socket. |
| 314 | if (AssignIdleSocketToGroup(request, group)) |
| 315 | return OK; |
| 316 | } |
| 317 | |
| 318 | if (!preconnecting && group->TryToUsePreconnectConnectJob()) |
| 319 | return ERR_IO_PENDING; |
[email protected] | 6555210 | 2010-04-09 22:58:10 | [diff] [blame] | 320 | |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 321 | // Can we make another active socket now? |
[email protected] | 5acdce1 | 2011-03-30 13:00:20 | [diff] [blame] | 322 | if (!group->HasAvailableSocketSlot(max_sockets_per_group_) && |
| 323 | !request->ignore_limits()) { |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 324 | request->net_log().AddEvent( |
| 325 | NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP, NULL); |
| 326 | return ERR_IO_PENDING; |
| 327 | } |
| 328 | |
[email protected] | 5acdce1 | 2011-03-30 13:00:20 | [diff] [blame] | 329 | if (ReachedMaxSocketsLimit() && !request->ignore_limits()) { |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 330 | if (idle_socket_count() > 0) { |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 331 | bool closed = CloseOneIdleSocketExceptInGroup(group); |
| 332 | if (preconnecting && !closed) |
| 333 | return ERR_PRECONNECT_MAX_SOCKET_LIMIT; |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 334 | } else { |
| 335 | // We could check if we really have a stalled group here, but it requires |
| 336 | // a scan of all groups, so just flip a flag here, and do the check later. |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 337 | request->net_log().AddEvent( |
| 338 | NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS, NULL); |
| 339 | return ERR_IO_PENDING; |
| 340 | } |
| 341 | } |
| 342 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 343 | // We couldn't find a socket to reuse, so allocate and connect a new one. |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 344 | scoped_ptr<ConnectJob> connect_job( |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 345 | connect_job_factory_->NewConnectJob(group_name, *request, this)); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 346 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 347 | connect_job->Initialize(preconnecting); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 348 | int rv = connect_job->Connect(); |
| 349 | if (rv == OK) { |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 350 | LogBoundConnectJobToRequest(connect_job->net_log().source(), request); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 351 | if (!preconnecting) { |
| 352 | HandOutSocket(connect_job->ReleaseSocket(), false /* not reused */, |
| 353 | handle, base::TimeDelta(), group, request->net_log()); |
| 354 | } else { |
| 355 | AddIdleSocket(connect_job->ReleaseSocket(), group); |
| 356 | } |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 357 | } else if (rv == ERR_IO_PENDING) { |
[email protected] | 6b624c6 | 2010-03-14 08:37:32 | [diff] [blame] | 358 | // If we don't have any sockets in this group, set a timer for potentially |
| 359 | // creating a new one. If the SYN is lost, this backup socket may complete |
| 360 | // before the slow socket, improving end user latency. |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 361 | if (connect_backup_jobs_enabled_ && |
[email protected] | e4d9a972 | 2011-05-12 00:16:00 | [diff] [blame] | 362 | group->IsEmpty() && !group->HasBackupJob()) { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 363 | group->StartBackupSocketTimer(group_name, this); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 364 | } |
[email protected] | 6b624c6 | 2010-03-14 08:37:32 | [diff] [blame] | 365 | |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 366 | connecting_socket_count_++; |
| 367 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 368 | group->AddJob(connect_job.release()); |
[email protected] | a2006ece | 2010-04-23 16:44:02 | [diff] [blame] | 369 | } else { |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 370 | LogBoundConnectJobToRequest(connect_job->net_log().source(), request); |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 371 | StreamSocket* error_socket = NULL; |
[email protected] | fd2e53e | 2011-01-14 20:40:52 | [diff] [blame] | 372 | if (!preconnecting) { |
| 373 | DCHECK(handle); |
| 374 | connect_job->GetAdditionalErrorState(handle); |
| 375 | error_socket = connect_job->ReleaseSocket(); |
| 376 | } |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 377 | if (error_socket) { |
| 378 | HandOutSocket(error_socket, false /* not reused */, handle, |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 379 | base::TimeDelta(), group, request->net_log()); |
| 380 | } else if (group->IsEmpty()) { |
| 381 | RemoveGroup(group_name); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 382 | } |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 383 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 384 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 385 | return rv; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 386 | } |
| 387 | |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 388 | bool ClientSocketPoolBaseHelper::AssignIdleSocketToGroup( |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 389 | const Request* request, Group* group) { |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 390 | std::list<IdleSocket>* idle_sockets = group->mutable_idle_sockets(); |
| 391 | std::list<IdleSocket>::iterator idle_socket_it = idle_sockets->end(); |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 392 | double max_score = -1; |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 393 | |
| 394 | // Iterate through the idle sockets forwards (oldest to newest) |
| 395 | // * Delete any disconnected ones. |
| 396 | // * If we find a used idle socket, assign to |idle_socket|. At the end, |
| 397 | // the |idle_socket_it| will be set to the newest used idle socket. |
| 398 | for (std::list<IdleSocket>::iterator it = idle_sockets->begin(); |
| 399 | it != idle_sockets->end();) { |
| 400 | if (!it->socket->IsConnectedAndIdle()) { |
| 401 | DecrementIdleCount(); |
| 402 | delete it->socket; |
| 403 | it = idle_sockets->erase(it); |
| 404 | continue; |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 405 | } |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 406 | |
| 407 | if (it->socket->WasEverUsed()) { |
| 408 | // We found one we can reuse! |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 409 | double score = 0; |
| 410 | int64 bytes_read = it->socket->NumBytesRead(); |
| 411 | double num_kb = static_cast<double>(bytes_read) / 1024.0; |
| 412 | int idle_time_sec = (base::TimeTicks::Now() - it->start_time).InSeconds(); |
| 413 | idle_time_sec = std::max(1, idle_time_sec); |
| 414 | |
| 415 | if (g_socket_reuse_policy_penalty_exponent >= 0 && num_kb >= 0) { |
| 416 | score = num_kb / pow(idle_time_sec, |
| 417 | g_socket_reuse_policy_penalty_exponent); |
| 418 | } |
| 419 | |
| 420 | // Equality to prefer recently used connection. |
| 421 | if (score >= max_score) { |
| 422 | idle_socket_it = it; |
| 423 | max_score = score; |
| 424 | } |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | ++it; |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 428 | } |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 429 | |
| 430 | // If we haven't found an idle socket, that means there are no used idle |
| 431 | // sockets. Pick the oldest (first) idle socket (FIFO). |
| 432 | |
| 433 | if (idle_socket_it == idle_sockets->end() && !idle_sockets->empty()) |
| 434 | idle_socket_it = idle_sockets->begin(); |
| 435 | |
| 436 | if (idle_socket_it != idle_sockets->end()) { |
| 437 | DecrementIdleCount(); |
| 438 | base::TimeDelta idle_time = |
| 439 | base::TimeTicks::Now() - idle_socket_it->start_time; |
| 440 | IdleSocket idle_socket = *idle_socket_it; |
| 441 | idle_sockets->erase(idle_socket_it); |
| 442 | HandOutSocket( |
| 443 | idle_socket.socket, |
| 444 | idle_socket.socket->WasEverUsed(), |
| 445 | request->handle(), |
| 446 | idle_time, |
| 447 | group, |
| 448 | request->net_log()); |
| 449 | return true; |
| 450 | } |
| 451 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 452 | return false; |
| 453 | } |
| 454 | |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 455 | // static |
| 456 | void ClientSocketPoolBaseHelper::LogBoundConnectJobToRequest( |
| 457 | const NetLog::Source& connect_job_source, const Request* request) { |
| 458 | request->net_log().AddEvent( |
| 459 | NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 460 | make_scoped_refptr(new NetLogSourceParameter( |
| 461 | "source_dependency", connect_job_source))); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 462 | } |
| 463 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 464 | void ClientSocketPoolBaseHelper::CancelRequest( |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 465 | const std::string& group_name, ClientSocketHandle* handle) { |
| 466 | PendingCallbackMap::iterator callback_it = pending_callback_map_.find(handle); |
| 467 | if (callback_it != pending_callback_map_.end()) { |
| 468 | int result = callback_it->second.result; |
| 469 | pending_callback_map_.erase(callback_it); |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 470 | StreamSocket* socket = handle->release_socket(); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 471 | if (socket) { |
| 472 | if (result != OK) |
| 473 | socket->Disconnect(); |
| 474 | ReleaseSocket(handle->group_name(), socket, handle->id()); |
| 475 | } |
| 476 | return; |
| 477 | } |
[email protected] | b6501d3d | 2010-06-03 23:53:34 | [diff] [blame] | 478 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 479 | CHECK(ContainsKey(group_map_, group_name)); |
| 480 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 481 | Group* group = GetOrCreateGroup(group_name); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 482 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 483 | // Search pending_requests for matching handle. |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 484 | RequestQueue::iterator it = group->mutable_pending_requests()->begin(); |
| 485 | for (; it != group->pending_requests().end(); ++it) { |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 486 | if ((*it)->handle() == handle) { |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 487 | scoped_ptr<const Request> req(RemoveRequestFromQueue(it, group)); |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 488 | req->net_log().AddEvent(NetLog::TYPE_CANCELLED, NULL); |
| 489 | req->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 490 | |
| 491 | // We let the job run, unless we're at the socket limit. |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 492 | if (group->jobs().size() && ReachedMaxSocketsLimit()) { |
| 493 | RemoveConnectJob(*group->jobs().begin(), group); |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 494 | CheckForStalledSocketGroups(); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 495 | } |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 496 | break; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 497 | } |
| 498 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 501 | bool ClientSocketPoolBaseHelper::HasGroup(const std::string& group_name) const { |
| 502 | return ContainsKey(group_map_, group_name); |
| 503 | } |
| 504 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 505 | void ClientSocketPoolBaseHelper::CloseIdleSockets() { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 506 | CleanupIdleSockets(true); |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 507 | DCHECK_EQ(0, idle_socket_count_); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 508 | } |
| 509 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 510 | int ClientSocketPoolBaseHelper::IdleSocketCountInGroup( |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 511 | const std::string& group_name) const { |
| 512 | GroupMap::const_iterator i = group_map_.find(group_name); |
| 513 | CHECK(i != group_map_.end()); |
| 514 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 515 | return i->second->idle_sockets().size(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 516 | } |
| 517 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 518 | LoadState ClientSocketPoolBaseHelper::GetLoadState( |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 519 | const std::string& group_name, |
| 520 | const ClientSocketHandle* handle) const { |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 521 | if (ContainsKey(pending_callback_map_, handle)) |
| 522 | return LOAD_STATE_CONNECTING; |
| 523 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 524 | if (!ContainsKey(group_map_, group_name)) { |
| 525 | NOTREACHED() << "ClientSocketPool does not contain group: " << group_name |
| 526 | << " for handle: " << handle; |
| 527 | return LOAD_STATE_IDLE; |
| 528 | } |
| 529 | |
| 530 | // Can't use operator[] since it is non-const. |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 531 | const Group& group = *group_map_.find(group_name)->second; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 532 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 533 | // Search pending_requests for matching handle. |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 534 | RequestQueue::const_iterator it = group.pending_requests().begin(); |
| 535 | for (size_t i = 0; it != group.pending_requests().end(); ++it, ++i) { |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 536 | if ((*it)->handle() == handle) { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 537 | if (i < group.jobs().size()) { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 538 | LoadState max_state = LOAD_STATE_IDLE; |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 539 | for (ConnectJobSet::const_iterator job_it = group.jobs().begin(); |
| 540 | job_it != group.jobs().end(); ++job_it) { |
[email protected] | 4645135 | 2009-09-01 14:54:21 | [diff] [blame] | 541 | max_state = std::max(max_state, (*job_it)->GetLoadState()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 542 | } |
| 543 | return max_state; |
| 544 | } else { |
| 545 | // TODO(wtc): Add a state for being on the wait list. |
| 546 | // See http://www.crbug.com/5077. |
| 547 | return LOAD_STATE_IDLE; |
| 548 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
| 552 | NOTREACHED(); |
| 553 | return LOAD_STATE_IDLE; |
| 554 | } |
| 555 | |
[email protected] | ba00b49 | 2010-09-08 14:53:38 | [diff] [blame] | 556 | DictionaryValue* ClientSocketPoolBaseHelper::GetInfoAsValue( |
[email protected] | 59d7a5a | 2010-08-30 16:44:27 | [diff] [blame] | 557 | const std::string& name, const std::string& type) const { |
| 558 | DictionaryValue* dict = new DictionaryValue(); |
| 559 | dict->SetString("name", name); |
| 560 | dict->SetString("type", type); |
| 561 | dict->SetInteger("handed_out_socket_count", handed_out_socket_count_); |
| 562 | dict->SetInteger("connecting_socket_count", connecting_socket_count_); |
| 563 | dict->SetInteger("idle_socket_count", idle_socket_count_); |
| 564 | dict->SetInteger("max_socket_count", max_sockets_); |
| 565 | dict->SetInteger("max_sockets_per_group", max_sockets_per_group_); |
| 566 | dict->SetInteger("pool_generation_number", pool_generation_number_); |
| 567 | |
| 568 | if (group_map_.empty()) |
| 569 | return dict; |
| 570 | |
| 571 | DictionaryValue* all_groups_dict = new DictionaryValue(); |
| 572 | for (GroupMap::const_iterator it = group_map_.begin(); |
| 573 | it != group_map_.end(); it++) { |
| 574 | const Group* group = it->second; |
| 575 | DictionaryValue* group_dict = new DictionaryValue(); |
| 576 | |
| 577 | group_dict->SetInteger("pending_request_count", |
| 578 | group->pending_requests().size()); |
| 579 | if (!group->pending_requests().empty()) { |
| 580 | group_dict->SetInteger("top_pending_priority", |
| 581 | group->TopPendingPriority()); |
| 582 | } |
| 583 | |
| 584 | group_dict->SetInteger("active_socket_count", group->active_socket_count()); |
[email protected] | 0496f9a3 | 2010-09-30 16:08:07 | [diff] [blame] | 585 | |
| 586 | ListValue* idle_socket_list = new ListValue(); |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 587 | std::list<IdleSocket>::const_iterator idle_socket; |
[email protected] | 0496f9a3 | 2010-09-30 16:08:07 | [diff] [blame] | 588 | for (idle_socket = group->idle_sockets().begin(); |
| 589 | idle_socket != group->idle_sockets().end(); |
| 590 | idle_socket++) { |
| 591 | int source_id = idle_socket->socket->NetLog().source().id; |
| 592 | idle_socket_list->Append(Value::CreateIntegerValue(source_id)); |
| 593 | } |
| 594 | group_dict->Set("idle_sockets", idle_socket_list); |
| 595 | |
| 596 | ListValue* connect_jobs_list = new ListValue(); |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 597 | std::set<ConnectJob*>::const_iterator job = group->jobs().begin(); |
[email protected] | 0496f9a3 | 2010-09-30 16:08:07 | [diff] [blame] | 598 | for (job = group->jobs().begin(); job != group->jobs().end(); job++) { |
| 599 | int source_id = (*job)->net_log().source().id; |
| 600 | connect_jobs_list->Append(Value::CreateIntegerValue(source_id)); |
| 601 | } |
| 602 | group_dict->Set("connect_jobs", connect_jobs_list); |
[email protected] | 59d7a5a | 2010-08-30 16:44:27 | [diff] [blame] | 603 | |
| 604 | group_dict->SetBoolean("is_stalled", |
| 605 | group->IsStalled(max_sockets_per_group_)); |
[email protected] | e4d9a972 | 2011-05-12 00:16:00 | [diff] [blame] | 606 | group_dict->SetBoolean("has_backup_job", group->HasBackupJob()); |
[email protected] | 59d7a5a | 2010-08-30 16:44:27 | [diff] [blame] | 607 | |
| 608 | all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); |
| 609 | } |
| 610 | dict->Set("groups", all_groups_dict); |
| 611 | return dict; |
| 612 | } |
| 613 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 614 | bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup( |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 615 | base::TimeTicks now, |
| 616 | base::TimeDelta timeout) const { |
| 617 | bool timed_out = (now - start_time) >= timeout; |
[email protected] | 0f873e8 | 2010-09-02 16:09:01 | [diff] [blame] | 618 | if (timed_out) |
| 619 | return true; |
| 620 | if (socket->WasEverUsed()) |
| 621 | return !socket->IsConnectedAndIdle(); |
| 622 | return !socket->IsConnected(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 623 | } |
| 624 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 625 | void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 626 | if (idle_socket_count_ == 0) |
| 627 | return; |
| 628 | |
| 629 | // Current time value. Retrieving it once at the function start rather than |
| 630 | // inside the inner loop, since it shouldn't change by any meaningful amount. |
| 631 | base::TimeTicks now = base::TimeTicks::Now(); |
| 632 | |
| 633 | GroupMap::iterator i = group_map_.begin(); |
| 634 | while (i != group_map_.end()) { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 635 | Group* group = i->second; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 636 | |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 637 | std::list<IdleSocket>::iterator j = group->mutable_idle_sockets()->begin(); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 638 | while (j != group->idle_sockets().end()) { |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 639 | base::TimeDelta timeout = |
[email protected] | 0f873e8 | 2010-09-02 16:09:01 | [diff] [blame] | 640 | j->socket->WasEverUsed() ? |
| 641 | used_idle_socket_timeout_ : unused_idle_socket_timeout_; |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 642 | if (force || j->ShouldCleanup(now, timeout)) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 643 | delete j->socket; |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 644 | j = group->mutable_idle_sockets()->erase(j); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 645 | DecrementIdleCount(); |
| 646 | } else { |
| 647 | ++j; |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | // Delete group if no longer needed. |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 652 | if (group->IsEmpty()) { |
| 653 | RemoveGroup(i++); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 654 | } else { |
| 655 | ++i; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 660 | ClientSocketPoolBaseHelper::Group* ClientSocketPoolBaseHelper::GetOrCreateGroup( |
| 661 | const std::string& group_name) { |
| 662 | GroupMap::iterator it = group_map_.find(group_name); |
| 663 | if (it != group_map_.end()) |
| 664 | return it->second; |
| 665 | Group* group = new Group; |
| 666 | group_map_[group_name] = group; |
| 667 | return group; |
| 668 | } |
| 669 | |
| 670 | void ClientSocketPoolBaseHelper::RemoveGroup(const std::string& group_name) { |
| 671 | GroupMap::iterator it = group_map_.find(group_name); |
| 672 | CHECK(it != group_map_.end()); |
| 673 | |
| 674 | RemoveGroup(it); |
| 675 | } |
| 676 | |
| 677 | void ClientSocketPoolBaseHelper::RemoveGroup(GroupMap::iterator it) { |
| 678 | delete it->second; |
| 679 | group_map_.erase(it); |
| 680 | } |
| 681 | |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 682 | // static |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 683 | bool ClientSocketPoolBaseHelper::connect_backup_jobs_enabled() { |
| 684 | return g_connect_backup_jobs_enabled; |
| 685 | } |
| 686 | |
| 687 | // static |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 688 | bool ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(bool enabled) { |
| 689 | bool old_value = g_connect_backup_jobs_enabled; |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 690 | g_connect_backup_jobs_enabled = enabled; |
[email protected] | 636b825 | 2011-04-08 19:56:54 | [diff] [blame] | 691 | return old_value; |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | void ClientSocketPoolBaseHelper::EnableConnectBackupJobs() { |
| 695 | connect_backup_jobs_enabled_ = g_connect_backup_jobs_enabled; |
| 696 | } |
| 697 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 698 | void ClientSocketPoolBaseHelper::IncrementIdleCount() { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 699 | if (++idle_socket_count_ == 1) |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 700 | timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kCleanupInterval), this, |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 701 | &ClientSocketPoolBaseHelper::OnCleanupTimerFired); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 702 | } |
| 703 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 704 | void ClientSocketPoolBaseHelper::DecrementIdleCount() { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 705 | if (--idle_socket_count_ == 0) |
| 706 | timer_.Stop(); |
| 707 | } |
| 708 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 709 | void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name, |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 710 | StreamSocket* socket, |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 711 | int id) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 712 | GroupMap::iterator i = group_map_.find(group_name); |
| 713 | CHECK(i != group_map_.end()); |
| 714 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 715 | Group* group = i->second; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 716 | |
[email protected] | b1f031dd | 2010-03-02 23:19:33 | [diff] [blame] | 717 | CHECK_GT(handed_out_socket_count_, 0); |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 718 | handed_out_socket_count_--; |
| 719 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 720 | CHECK_GT(group->active_socket_count(), 0); |
| 721 | group->DecrementActiveSocketCount(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 722 | |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 723 | const bool can_reuse = socket->IsConnectedAndIdle() && |
| 724 | id == pool_generation_number_; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 725 | if (can_reuse) { |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 726 | // Add it to the idle list. |
[email protected] | 0f873e8 | 2010-09-02 16:09:01 | [diff] [blame] | 727 | AddIdleSocket(socket, group); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 728 | OnAvailableSocketSlot(group_name, group); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 729 | } else { |
| 730 | delete socket; |
| 731 | } |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 732 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 733 | CheckForStalledSocketGroups(); |
| 734 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 735 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 736 | void ClientSocketPoolBaseHelper::CheckForStalledSocketGroups() { |
| 737 | // If we have idle sockets, see if we can give one to the top-stalled group. |
| 738 | std::string top_group_name; |
| 739 | Group* top_group = NULL; |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 740 | if (!FindTopStalledGroup(&top_group, &top_group_name)) |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 741 | return; |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 742 | |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 743 | if (ReachedMaxSocketsLimit()) { |
| 744 | if (idle_socket_count() > 0) { |
| 745 | CloseOneIdleSocket(); |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 746 | } else { |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 747 | // We can't activate more sockets since we're already at our global |
| 748 | // limit. |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 749 | return; |
[email protected] | d7027bb | 2010-05-10 18:58:54 | [diff] [blame] | 750 | } |
[email protected] | 4f2abec | 2010-02-03 18:10:16 | [diff] [blame] | 751 | } |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 752 | |
| 753 | // Note: we don't loop on waking stalled groups. If the stalled group is at |
| 754 | // its limit, may be left with other stalled groups that could be |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 755 | // woken. This isn't optimal, but there is no starvation, so to avoid |
[email protected] | eb5a9938 | 2010-07-11 03:18:26 | [diff] [blame] | 756 | // the looping we leave it at this. |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 757 | OnAvailableSocketSlot(top_group_name, top_group); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 758 | } |
| 759 | |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 760 | // Search for the highest priority pending request, amongst the groups that |
| 761 | // are not at the |max_sockets_per_group_| limit. Note: for requests with |
| 762 | // the same priority, the winner is based on group hash ordering (and not |
| 763 | // insertion order). |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 764 | bool ClientSocketPoolBaseHelper::FindTopStalledGroup(Group** group, |
| 765 | std::string* group_name) { |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 766 | Group* top_group = NULL; |
| 767 | const std::string* top_group_name = NULL; |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 768 | bool has_stalled_group = false; |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 769 | for (GroupMap::iterator i = group_map_.begin(); |
| 770 | i != group_map_.end(); ++i) { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 771 | Group* curr_group = i->second; |
| 772 | const RequestQueue& queue = curr_group->pending_requests(); |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 773 | if (queue.empty()) |
| 774 | continue; |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 775 | if (curr_group->IsStalled(max_sockets_per_group_)) { |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 776 | has_stalled_group = true; |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 777 | bool has_higher_priority = !top_group || |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 778 | curr_group->TopPendingPriority() < top_group->TopPendingPriority(); |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 779 | if (has_higher_priority) { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 780 | top_group = curr_group; |
[email protected] | 6427fe2 | 2010-04-16 22:27:41 | [diff] [blame] | 781 | top_group_name = &i->first; |
| 782 | } |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 783 | } |
| 784 | } |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 785 | |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 786 | if (top_group) { |
| 787 | *group = top_group; |
| 788 | *group_name = *top_group_name; |
| 789 | } |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 790 | return has_stalled_group; |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 791 | } |
| 792 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 793 | void ClientSocketPoolBaseHelper::OnConnectJobComplete( |
| 794 | int result, ConnectJob* job) { |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 795 | DCHECK_NE(ERR_IO_PENDING, result); |
| 796 | const std::string group_name = job->group_name(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 797 | GroupMap::iterator group_it = group_map_.find(group_name); |
| 798 | CHECK(group_it != group_map_.end()); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 799 | Group* group = group_it->second; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 800 | |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 801 | scoped_ptr<StreamSocket> socket(job->ReleaseSocket()); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 802 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 803 | BoundNetLog job_log = job->net_log(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 804 | |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 805 | if (result == OK) { |
| 806 | DCHECK(socket.get()); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 807 | RemoveConnectJob(job, group); |
| 808 | if (!group->pending_requests().empty()) { |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 809 | scoped_ptr<const Request> r(RemoveRequestFromQueue( |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 810 | group->mutable_pending_requests()->begin(), group)); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 811 | LogBoundConnectJobToRequest(job_log.source(), r.get()); |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 812 | HandOutSocket( |
| 813 | socket.release(), false /* unused socket */, r->handle(), |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 814 | base::TimeDelta(), group, r->net_log()); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 815 | r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 816 | InvokeUserCallbackLater(r->handle(), r->callback(), result); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 817 | } else { |
[email protected] | 0f873e8 | 2010-09-02 16:09:01 | [diff] [blame] | 818 | AddIdleSocket(socket.release(), group); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 819 | OnAvailableSocketSlot(group_name, group); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 820 | CheckForStalledSocketGroups(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 821 | } |
[email protected] | 94c2047 | 2010-01-14 08:14:36 | [diff] [blame] | 822 | } else { |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 823 | // If we got a socket, it must contain error information so pass that |
| 824 | // up so that the caller can retrieve it. |
| 825 | bool handed_out_socket = false; |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 826 | if (!group->pending_requests().empty()) { |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 827 | scoped_ptr<const Request> r(RemoveRequestFromQueue( |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 828 | group->mutable_pending_requests()->begin(), group)); |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 829 | LogBoundConnectJobToRequest(job_log.source(), r.get()); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 830 | job->GetAdditionalErrorState(r->handle()); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 831 | RemoveConnectJob(job, group); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 832 | if (socket.get()) { |
| 833 | handed_out_socket = true; |
| 834 | HandOutSocket(socket.release(), false /* unused socket */, r->handle(), |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 835 | base::TimeDelta(), group, r->net_log()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 836 | } |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 837 | r->net_log().EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_POOL, |
| 838 | result); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 839 | InvokeUserCallbackLater(r->handle(), r->callback(), result); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 840 | } else { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 841 | RemoveConnectJob(job, group); |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 842 | } |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 843 | if (!handed_out_socket) { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 844 | OnAvailableSocketSlot(group_name, group); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 845 | CheckForStalledSocketGroups(); |
| 846 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 847 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 848 | } |
| 849 | |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 850 | void ClientSocketPoolBaseHelper::OnIPAddressChanged() { |
| 851 | Flush(); |
| 852 | } |
| 853 | |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 854 | void ClientSocketPoolBaseHelper::Flush() { |
| 855 | pool_generation_number_++; |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 856 | CancelAllConnectJobs(); |
[email protected] | a554a826 | 2010-05-20 00:13:52 | [diff] [blame] | 857 | CloseIdleSockets(); |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 858 | AbortAllRequests(); |
[email protected] | a554a826 | 2010-05-20 00:13:52 | [diff] [blame] | 859 | } |
| 860 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 861 | void ClientSocketPoolBaseHelper::RemoveConnectJob(ConnectJob* job, |
[email protected] | 4d3b05d | 2010-01-27 21:27:29 | [diff] [blame] | 862 | Group* group) { |
[email protected] | b1f031dd | 2010-03-02 23:19:33 | [diff] [blame] | 863 | CHECK_GT(connecting_socket_count_, 0); |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 864 | connecting_socket_count_--; |
| 865 | |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 866 | DCHECK(group); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 867 | DCHECK(ContainsKey(group->jobs(), job)); |
| 868 | group->RemoveJob(job); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 869 | |
| 870 | // If we've got no more jobs for this group, then we no longer need a |
| 871 | // backup job either. |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 872 | if (group->jobs().empty()) |
[email protected] | e4d9a972 | 2011-05-12 00:16:00 | [diff] [blame] | 873 | group->CleanupBackupJob(); |
[email protected] | 25eea38 | 2010-07-10 23:55:26 | [diff] [blame] | 874 | |
[email protected] | 8ae03f4 | 2010-07-07 19:08:10 | [diff] [blame] | 875 | DCHECK(job); |
| 876 | delete job; |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 877 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 878 | |
[email protected] | 8ae03f4 | 2010-07-07 19:08:10 | [diff] [blame] | 879 | void ClientSocketPoolBaseHelper::OnAvailableSocketSlot( |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 880 | const std::string& group_name, Group* group) { |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 881 | DCHECK(ContainsKey(group_map_, group_name)); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 882 | if (group->IsEmpty()) |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 883 | RemoveGroup(group_name); |
| 884 | else if (!group->pending_requests().empty()) |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 885 | ProcessPendingRequest(group_name, group); |
[email protected] | 8ae03f4 | 2010-07-07 19:08:10 | [diff] [blame] | 886 | } |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 887 | |
[email protected] | 8ae03f4 | 2010-07-07 19:08:10 | [diff] [blame] | 888 | void ClientSocketPoolBaseHelper::ProcessPendingRequest( |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 889 | const std::string& group_name, Group* group) { |
| 890 | int rv = RequestSocketInternal(group_name, |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 891 | *group->pending_requests().begin()); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 892 | if (rv != ERR_IO_PENDING) { |
| 893 | scoped_ptr<const Request> request(RemoveRequestFromQueue( |
[email protected] | 3f00be8 | 2010-09-27 19:50:02 | [diff] [blame] | 894 | group->mutable_pending_requests()->begin(), group)); |
[email protected] | 2abfe90a | 2010-08-25 17:49:51 | [diff] [blame] | 895 | if (group->IsEmpty()) |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 896 | RemoveGroup(group_name); |
[email protected] | 8ae03f4 | 2010-07-07 19:08:10 | [diff] [blame] | 897 | |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 898 | request->net_log().EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_POOL, rv); |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 899 | InvokeUserCallbackLater( |
| 900 | request->handle(), request->callback(), rv); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 904 | void ClientSocketPoolBaseHelper::HandOutSocket( |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 905 | StreamSocket* socket, |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 906 | bool reused, |
| 907 | ClientSocketHandle* handle, |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 908 | base::TimeDelta idle_time, |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 909 | Group* group, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 910 | const BoundNetLog& net_log) { |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 911 | DCHECK(socket); |
| 912 | handle->set_socket(socket); |
| 913 | handle->set_is_reused(reused); |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 914 | handle->set_idle_time(idle_time); |
[email protected] | a7e3857 | 2010-06-07 18:22:24 | [diff] [blame] | 915 | handle->set_pool_id(pool_generation_number_); |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 916 | |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 917 | if (reused) { |
[email protected] | ec11be6 | 2010-04-28 19:28:09 | [diff] [blame] | 918 | net_log.AddEvent( |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 919 | NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET, |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 920 | make_scoped_refptr(new NetLogIntegerParameter( |
| 921 | "idle_ms", static_cast<int>(idle_time.InMilliseconds())))); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 922 | } |
[email protected] | d13f51b | 2010-04-27 23:20:45 | [diff] [blame] | 923 | |
[email protected] | 06650c5 | 2010-06-03 00:49:17 | [diff] [blame] | 924 | net_log.AddEvent(NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 925 | make_scoped_refptr(new NetLogSourceParameter( |
| 926 | "source_dependency", socket->NetLog().source()))); |
[email protected] | fd4fe0b | 2010-02-08 23:02:15 | [diff] [blame] | 927 | |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 928 | handed_out_socket_count_++; |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 929 | group->IncrementActiveSocketCount(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 930 | } |
| 931 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 932 | void ClientSocketPoolBaseHelper::AddIdleSocket( |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 933 | StreamSocket* socket, Group* group) { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 934 | DCHECK(socket); |
| 935 | IdleSocket idle_socket; |
| 936 | idle_socket.socket = socket; |
| 937 | idle_socket.start_time = base::TimeTicks::Now(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 938 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 939 | group->mutable_idle_sockets()->push_back(idle_socket); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 940 | IncrementIdleCount(); |
| 941 | } |
| 942 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 943 | void ClientSocketPoolBaseHelper::CancelAllConnectJobs() { |
[email protected] | 74d75e0b | 2010-08-23 20:39:54 | [diff] [blame] | 944 | for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 945 | Group* group = i->second; |
| 946 | connecting_socket_count_ -= group->jobs().size(); |
| 947 | group->RemoveAllJobs(); |
[email protected] | 6b624c6 | 2010-03-14 08:37:32 | [diff] [blame] | 948 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 949 | // Delete group if no longer needed. |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 950 | if (group->IsEmpty()) { |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 951 | // RemoveGroup() will call .erase() which will invalidate the iterator, |
| 952 | // but i will already have been incremented to a valid iterator before |
| 953 | // RemoveGroup() is called. |
| 954 | RemoveGroup(i++); |
| 955 | } else { |
| 956 | ++i; |
| 957 | } |
| 958 | } |
| 959 | DCHECK_EQ(0, connecting_socket_count_); |
| 960 | } |
| 961 | |
| 962 | void ClientSocketPoolBaseHelper::AbortAllRequests() { |
| 963 | for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { |
| 964 | Group* group = i->second; |
| 965 | |
| 966 | RequestQueue pending_requests; |
| 967 | pending_requests.swap(*group->mutable_pending_requests()); |
| 968 | for (RequestQueue::iterator it2 = pending_requests.begin(); |
| 969 | it2 != pending_requests.end(); ++it2) { |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 970 | scoped_ptr<const Request> request(*it2); |
[email protected] | 06f9246 | 2010-08-31 19:24:14 | [diff] [blame] | 971 | InvokeUserCallbackLater( |
| 972 | request->handle(), request->callback(), ERR_ABORTED); |
| 973 | } |
| 974 | |
| 975 | // Delete group if no longer needed. |
| 976 | if (group->IsEmpty()) { |
| 977 | // RemoveGroup() will call .erase() which will invalidate the iterator, |
| 978 | // but i will already have been incremented to a valid iterator before |
| 979 | // RemoveGroup() is called. |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 980 | RemoveGroup(i++); |
[email protected] | 74d75e0b | 2010-08-23 20:39:54 | [diff] [blame] | 981 | } else { |
| 982 | ++i; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | } |
| 986 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 987 | bool ClientSocketPoolBaseHelper::ReachedMaxSocketsLimit() const { |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 988 | // Each connecting socket will eventually connect and be handed out. |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 989 | int total = handed_out_socket_count_ + connecting_socket_count_ + |
| 990 | idle_socket_count(); |
[email protected] | 5acdce1 | 2011-03-30 13:00:20 | [diff] [blame] | 991 | // There can be more sockets than the limit since some requests can ignore |
| 992 | // the limit |
[email protected] | c901f6d | 2010-04-27 17:48:28 | [diff] [blame] | 993 | if (total < max_sockets_) |
| 994 | return false; |
[email protected] | c901f6d | 2010-04-27 17:48:28 | [diff] [blame] | 995 | return true; |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 996 | } |
| 997 | |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 998 | void ClientSocketPoolBaseHelper::CloseOneIdleSocket() { |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 999 | CloseOneIdleSocketExceptInGroup(NULL); |
| 1000 | } |
| 1001 | |
| 1002 | bool ClientSocketPoolBaseHelper::CloseOneIdleSocketExceptInGroup( |
| 1003 | const Group* exception_group) { |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1004 | CHECK_GT(idle_socket_count(), 0); |
| 1005 | |
| 1006 | for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end(); ++i) { |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 1007 | Group* group = i->second; |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 1008 | if (exception_group == group) |
| 1009 | continue; |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 1010 | std::list<IdleSocket>* idle_sockets = group->mutable_idle_sockets(); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1011 | |
[email protected] | e1b54dc | 2010-10-06 21:27:22 | [diff] [blame] | 1012 | if (!idle_sockets->empty()) { |
| 1013 | delete idle_sockets->front().socket; |
| 1014 | idle_sockets->pop_front(); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1015 | DecrementIdleCount(); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 1016 | if (group->IsEmpty()) |
| 1017 | RemoveGroup(i); |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1018 | |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 1019 | return true; |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
[email protected] | dcbe168a | 2010-12-02 03:14:46 | [diff] [blame] | 1023 | if (!exception_group) |
| 1024 | LOG(DFATAL) << "No idle socket found to close!."; |
| 1025 | |
| 1026 | return false; |
[email protected] | 43a21b8 | 2010-06-10 21:30:54 | [diff] [blame] | 1027 | } |
| 1028 | |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 1029 | void ClientSocketPoolBaseHelper::InvokeUserCallbackLater( |
[email protected] | f1f3f0f8 | 2011-10-01 20:38:10 | [diff] [blame] | 1030 | ClientSocketHandle* handle, OldCompletionCallback* callback, int rv) { |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 1031 | CHECK(!ContainsKey(pending_callback_map_, handle)); |
| 1032 | pending_callback_map_[handle] = CallbackResultPair(callback, rv); |
| 1033 | MessageLoop::current()->PostTask( |
| 1034 | FROM_HERE, |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 1035 | method_factory_.NewRunnableMethod( |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 1036 | &ClientSocketPoolBaseHelper::InvokeUserCallback, |
| 1037 | handle)); |
| 1038 | } |
| 1039 | |
| 1040 | void ClientSocketPoolBaseHelper::InvokeUserCallback( |
| 1041 | ClientSocketHandle* handle) { |
| 1042 | PendingCallbackMap::iterator it = pending_callback_map_.find(handle); |
| 1043 | |
| 1044 | // Exit if the request has already been cancelled. |
| 1045 | if (it == pending_callback_map_.end()) |
| 1046 | return; |
| 1047 | |
| 1048 | CHECK(!handle->is_initialized()); |
[email protected] | f1f3f0f8 | 2011-10-01 20:38:10 | [diff] [blame] | 1049 | OldCompletionCallback* callback = it->second.callback; |
[email protected] | 05ea9ff | 2010-07-15 19:08:21 | [diff] [blame] | 1050 | int result = it->second.result; |
| 1051 | pending_callback_map_.erase(it); |
| 1052 | callback->Run(result); |
| 1053 | } |
| 1054 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 1055 | ClientSocketPoolBaseHelper::Group::Group() |
| 1056 | : active_socket_count_(0), |
| 1057 | ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} |
| 1058 | |
[email protected] | e4d9a972 | 2011-05-12 00:16:00 | [diff] [blame] | 1059 | ClientSocketPoolBaseHelper::Group::~Group() { |
| 1060 | CleanupBackupJob(); |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | void ClientSocketPoolBaseHelper::Group::StartBackupSocketTimer( |
| 1064 | const std::string& group_name, |
| 1065 | ClientSocketPoolBaseHelper* pool) { |
| 1066 | // Only allow one timer pending to create a backup socket. |
| 1067 | if (!method_factory_.empty()) |
| 1068 | return; |
| 1069 | |
| 1070 | MessageLoop::current()->PostDelayedTask( |
| 1071 | FROM_HERE, |
| 1072 | method_factory_.NewRunnableMethod( |
| 1073 | &Group::OnBackupSocketTimerFired, group_name, pool), |
| 1074 | pool->ConnectRetryIntervalMs()); |
| 1075 | } |
| 1076 | |
[email protected] | 2c2bef15 | 2010-10-13 00:55:03 | [diff] [blame] | 1077 | bool ClientSocketPoolBaseHelper::Group::TryToUsePreconnectConnectJob() { |
| 1078 | for (std::set<ConnectJob*>::iterator it = jobs_.begin(); |
| 1079 | it != jobs_.end(); ++it) { |
| 1080 | ConnectJob* job = *it; |
| 1081 | if (job->is_unused_preconnect()) { |
| 1082 | job->UseForNormalRequest(); |
| 1083 | return true; |
| 1084 | } |
| 1085 | } |
| 1086 | return false; |
| 1087 | } |
| 1088 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 1089 | void ClientSocketPoolBaseHelper::Group::OnBackupSocketTimerFired( |
| 1090 | std::string group_name, |
| 1091 | ClientSocketPoolBaseHelper* pool) { |
| 1092 | // If there are no more jobs pending, there is no work to do. |
| 1093 | // If we've done our cleanups correctly, this should not happen. |
| 1094 | if (jobs_.empty()) { |
| 1095 | NOTREACHED(); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | // If our backup job is waiting on DNS, or if we can't create any sockets |
| 1100 | // right now due to limits, just reset the timer. |
| 1101 | if (pool->ReachedMaxSocketsLimit() || |
| 1102 | !HasAvailableSocketSlot(pool->max_sockets_per_group_) || |
| 1103 | (*jobs_.begin())->GetLoadState() == LOAD_STATE_RESOLVING_HOST) { |
| 1104 | StartBackupSocketTimer(group_name, pool); |
| 1105 | return; |
| 1106 | } |
| 1107 | |
[email protected] | a9fc8fc | 2011-05-10 02:41:07 | [diff] [blame] | 1108 | if (pending_requests_.empty()) |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 1109 | return; |
[email protected] | 4baaf9d | 2010-08-31 15:15:44 | [diff] [blame] | 1110 | |
[email protected] | aed99ef0 | 2010-08-26 14:04:32 | [diff] [blame] | 1111 | ConnectJob* backup_job = pool->connect_job_factory_->NewConnectJob( |
| 1112 | group_name, **pending_requests_.begin(), pool); |
| 1113 | backup_job->net_log().AddEvent(NetLog::TYPE_SOCKET_BACKUP_CREATED, NULL); |
| 1114 | SIMPLE_STATS_COUNTER("socket.backup_created"); |
| 1115 | int rv = backup_job->Connect(); |
| 1116 | pool->connecting_socket_count_++; |
| 1117 | AddJob(backup_job); |
| 1118 | if (rv != ERR_IO_PENDING) |
| 1119 | pool->OnConnectJobComplete(rv, backup_job); |
| 1120 | } |
| 1121 | |
| 1122 | void ClientSocketPoolBaseHelper::Group::RemoveAllJobs() { |
| 1123 | // Delete active jobs. |
| 1124 | STLDeleteElements(&jobs_); |
| 1125 | |
| 1126 | // Cancel pending backup job. |
| 1127 | method_factory_.RevokeAll(); |
| 1128 | } |
| 1129 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 1130 | } // namespace internal |
| 1131 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 1132 | } // namespace net |