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 #include "net/socket/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // Indicate whether or not we should establish a new transport layer connection | 47 // Indicate whether or not we should establish a new transport layer connection |
48 // after a certain timeout has passed without receiving an ACK. | 48 // after a certain timeout has passed without receiving an ACK. |
49 bool g_connect_backup_jobs_enabled = true; | 49 bool g_connect_backup_jobs_enabled = true; |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 ConnectJob::ConnectJob(const std::string& group_name, | 53 ConnectJob::ConnectJob(const std::string& group_name, |
54 base::TimeDelta timeout_duration, | 54 base::TimeDelta timeout_duration, |
55 RequestPriority priority, | 55 RequestPriority priority, |
| 56 ClientSocketPool::RespectLimits respect_limits, |
56 Delegate* delegate, | 57 Delegate* delegate, |
57 const BoundNetLog& net_log) | 58 const BoundNetLog& net_log) |
58 : group_name_(group_name), | 59 : group_name_(group_name), |
59 timeout_duration_(timeout_duration), | 60 timeout_duration_(timeout_duration), |
60 priority_(priority), | 61 priority_(priority), |
| 62 respect_limits_(respect_limits), |
61 delegate_(delegate), | 63 delegate_(delegate), |
62 net_log_(net_log), | 64 net_log_(net_log), |
63 idle_(true) { | 65 idle_(true) { |
64 DCHECK(!group_name.empty()); | 66 DCHECK(!group_name.empty()); |
65 DCHECK(delegate); | 67 DCHECK(delegate); |
66 net_log.BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, | 68 net_log.BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, |
67 NetLog::StringCallback("group_name", &group_name_)); | 69 NetLog::StringCallback("group_name", &group_name_)); |
68 } | 70 } |
69 | 71 |
70 ConnectJob::~ConnectJob() { | 72 ConnectJob::~ConnectJob() { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 136 |
135 NotifyDelegateOfCompletion(ERR_TIMED_OUT); | 137 NotifyDelegateOfCompletion(ERR_TIMED_OUT); |
136 } | 138 } |
137 | 139 |
138 namespace internal { | 140 namespace internal { |
139 | 141 |
140 ClientSocketPoolBaseHelper::Request::Request( | 142 ClientSocketPoolBaseHelper::Request::Request( |
141 ClientSocketHandle* handle, | 143 ClientSocketHandle* handle, |
142 const CompletionCallback& callback, | 144 const CompletionCallback& callback, |
143 RequestPriority priority, | 145 RequestPriority priority, |
144 bool ignore_limits, | 146 ClientSocketPool::RespectLimits respect_limits, |
145 Flags flags, | 147 Flags flags, |
146 const BoundNetLog& net_log) | 148 const BoundNetLog& net_log) |
147 : handle_(handle), | 149 : handle_(handle), |
148 callback_(callback), | 150 callback_(callback), |
149 priority_(priority), | 151 priority_(priority), |
150 ignore_limits_(ignore_limits), | 152 respect_limits_(respect_limits), |
151 flags_(flags), | 153 flags_(flags), |
152 net_log_(net_log) { | 154 net_log_(net_log) { |
153 if (ignore_limits_) | 155 if (respect_limits_ == ClientSocketPool::RespectLimits::DISABLED) |
154 DCHECK_EQ(priority_, MAXIMUM_PRIORITY); | 156 DCHECK_EQ(priority_, MAXIMUM_PRIORITY); |
155 } | 157 } |
156 | 158 |
157 ClientSocketPoolBaseHelper::Request::~Request() { | 159 ClientSocketPoolBaseHelper::Request::~Request() { |
158 liveness_ = DEAD; | 160 liveness_ = DEAD; |
159 } | 161 } |
160 | 162 |
161 void ClientSocketPoolBaseHelper::Request::CrashIfInvalid() const { | 163 void ClientSocketPoolBaseHelper::Request::CrashIfInvalid() const { |
162 CHECK_EQ(liveness_, ALIVE); | 164 CHECK_EQ(liveness_, ALIVE); |
163 } | 165 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 373 } |
372 | 374 |
373 // If there are more ConnectJobs than pending requests, don't need to do | 375 // If there are more ConnectJobs than pending requests, don't need to do |
374 // anything. Can just wait for the extra job to connect, and then assign it | 376 // anything. Can just wait for the extra job to connect, and then assign it |
375 // to the request. | 377 // to the request. |
376 if (!preconnecting && group->TryToUseUnassignedConnectJob()) | 378 if (!preconnecting && group->TryToUseUnassignedConnectJob()) |
377 return ERR_IO_PENDING; | 379 return ERR_IO_PENDING; |
378 | 380 |
379 // Can we make another active socket now? | 381 // Can we make another active socket now? |
380 if (!group->HasAvailableSocketSlot(max_sockets_per_group_) && | 382 if (!group->HasAvailableSocketSlot(max_sockets_per_group_) && |
381 !request.ignore_limits()) { | 383 request.respect_limits() == ClientSocketPool::RespectLimits::ENABLED) { |
382 // TODO(willchan): Consider whether or not we need to close a socket in a | 384 // TODO(willchan): Consider whether or not we need to close a socket in a |
383 // higher layered group. I don't think this makes sense since we would just | 385 // higher layered group. I don't think this makes sense since we would just |
384 // reuse that socket then if we needed one and wouldn't make it down to this | 386 // reuse that socket then if we needed one and wouldn't make it down to this |
385 // layer. | 387 // layer. |
386 request.net_log().AddEvent( | 388 request.net_log().AddEvent( |
387 NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP); | 389 NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP); |
388 return ERR_IO_PENDING; | 390 return ERR_IO_PENDING; |
389 } | 391 } |
390 | 392 |
391 if (ReachedMaxSocketsLimit() && !request.ignore_limits()) { | 393 if (ReachedMaxSocketsLimit() && |
| 394 request.respect_limits() == ClientSocketPool::RespectLimits::ENABLED) { |
392 // NOTE(mmenke): Wonder if we really need different code for each case | 395 // NOTE(mmenke): Wonder if we really need different code for each case |
393 // here. Only reason for them now seems to be preconnects. | 396 // here. Only reason for them now seems to be preconnects. |
394 if (idle_socket_count() > 0) { | 397 if (idle_socket_count() > 0) { |
395 // There's an idle socket in this pool. Either that's because there's | 398 // There's an idle socket in this pool. Either that's because there's |
396 // still one in this group, but we got here due to preconnecting bypassing | 399 // still one in this group, but we got here due to preconnecting bypassing |
397 // idle sockets, or because there's an idle socket in another group. | 400 // idle sockets, or because there's an idle socket in another group. |
398 bool closed = CloseOneIdleSocketExceptInGroup(group); | 401 bool closed = CloseOneIdleSocketExceptInGroup(group); |
399 if (preconnecting && !closed) | 402 if (preconnecting && !closed) |
400 return ERR_PRECONNECT_MAX_SOCKET_LIMIT; | 403 return ERR_PRECONNECT_MAX_SOCKET_LIMIT; |
401 } else { | 404 } else { |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 if (pointer.value()->handle() == handle) | 1298 if (pointer.value()->handle() == handle) |
1296 return true; | 1299 return true; |
1297 } | 1300 } |
1298 return false; | 1301 return false; |
1299 } | 1302 } |
1300 | 1303 |
1301 void ClientSocketPoolBaseHelper::Group::InsertPendingRequest( | 1304 void ClientSocketPoolBaseHelper::Group::InsertPendingRequest( |
1302 scoped_ptr<const Request> request) { | 1305 scoped_ptr<const Request> request) { |
1303 // This value must be cached before we release |request|. | 1306 // This value must be cached before we release |request|. |
1304 RequestPriority priority = request->priority(); | 1307 RequestPriority priority = request->priority(); |
1305 if (request->ignore_limits()) { | 1308 if (request->respect_limits() == ClientSocketPool::RespectLimits::DISABLED) { |
1306 // Put requests with ignore_limits == true (which should have | 1309 // Put requests with RespectLimits::DISABLED (which should have |
1307 // priority == MAXIMUM_PRIORITY) ahead of other requests with | 1310 // priority == MAXIMUM_PRIORITY) ahead of other requests with |
1308 // MAXIMUM_PRIORITY. | 1311 // MAXIMUM_PRIORITY. |
1309 DCHECK_EQ(priority, MAXIMUM_PRIORITY); | 1312 DCHECK_EQ(priority, MAXIMUM_PRIORITY); |
1310 pending_requests_.InsertAtFront(request.release(), priority); | 1313 pending_requests_.InsertAtFront(request.release(), priority); |
1311 } else { | 1314 } else { |
1312 pending_requests_.Insert(request.release(), priority); | 1315 pending_requests_.Insert(request.release(), priority); |
1313 } | 1316 } |
1314 } | 1317 } |
1315 | 1318 |
1316 scoped_ptr<const ClientSocketPoolBaseHelper::Request> | 1319 scoped_ptr<const ClientSocketPoolBaseHelper::Request> |
(...skipping 27 matching lines...) Expand all Loading... |
1344 // If there are no more requests, kill the backup timer. | 1347 // If there are no more requests, kill the backup timer. |
1345 if (pending_requests_.empty()) | 1348 if (pending_requests_.empty()) |
1346 backup_job_timer_.Stop(); | 1349 backup_job_timer_.Stop(); |
1347 request->CrashIfInvalid(); | 1350 request->CrashIfInvalid(); |
1348 return request; | 1351 return request; |
1349 } | 1352 } |
1350 | 1353 |
1351 } // namespace internal | 1354 } // namespace internal |
1352 | 1355 |
1353 } // namespace net | 1356 } // namespace net |
OLD | NEW |