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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 const CompletionCallback& callback, | 133 const CompletionCallback& callback, |
134 RequestPriority priority, | 134 RequestPriority priority, |
135 bool ignore_limits, | 135 bool ignore_limits, |
136 Flags flags, | 136 Flags flags, |
137 const BoundNetLog& net_log) | 137 const BoundNetLog& net_log) |
138 : handle_(handle), | 138 : handle_(handle), |
139 callback_(callback), | 139 callback_(callback), |
140 priority_(priority), | 140 priority_(priority), |
141 ignore_limits_(ignore_limits), | 141 ignore_limits_(ignore_limits), |
142 flags_(flags), | 142 flags_(flags), |
143 net_log_(net_log) { | 143 net_log_(net_log) {} |
144 if (ignore_limits_) | |
145 DCHECK_EQ(priority_, MAXIMUM_PRIORITY); | |
146 } | |
147 | 144 |
148 ClientSocketPoolBaseHelper::Request::~Request() {} | 145 ClientSocketPoolBaseHelper::Request::~Request() {} |
149 | 146 |
150 ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( | 147 ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( |
151 HigherLayeredPool* pool, | 148 HigherLayeredPool* pool, |
152 int max_sockets, | 149 int max_sockets, |
153 int max_sockets_per_group, | 150 int max_sockets_per_group, |
154 base::TimeDelta unused_idle_socket_timeout, | 151 base::TimeDelta unused_idle_socket_timeout, |
155 base::TimeDelta used_idle_socket_timeout, | 152 base::TimeDelta used_idle_socket_timeout, |
156 ConnectJobFactory* connect_job_factory) | 153 ConnectJobFactory* connect_job_factory) |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 while (IsStalled()) { | 1124 while (IsStalled()) { |
1128 // Closing a socket will result in calling back into |this| to use the freed | 1125 // Closing a socket will result in calling back into |this| to use the freed |
1129 // socket slot, so nothing else is needed. | 1126 // socket slot, so nothing else is needed. |
1130 if (!CloseOneIdleConnectionInHigherLayeredPool()) | 1127 if (!CloseOneIdleConnectionInHigherLayeredPool()) |
1131 return; | 1128 return; |
1132 } | 1129 } |
1133 } | 1130 } |
1134 | 1131 |
1135 ClientSocketPoolBaseHelper::Group::Group() | 1132 ClientSocketPoolBaseHelper::Group::Group() |
1136 : unassigned_job_count_(0), | 1133 : unassigned_job_count_(0), |
1137 pending_requests_(NUM_PRIORITIES), | 1134 // The number of priorities is doubled since requests with |
| 1135 // |ignore_limits| are prioritized over other requests. |
| 1136 pending_requests_(2 * NUM_PRIORITIES), |
1138 active_socket_count_(0) {} | 1137 active_socket_count_(0) {} |
1139 | 1138 |
1140 ClientSocketPoolBaseHelper::Group::~Group() { | 1139 ClientSocketPoolBaseHelper::Group::~Group() { |
1141 DCHECK_EQ(0u, unassigned_job_count_); | 1140 DCHECK_EQ(0u, unassigned_job_count_); |
1142 } | 1141 } |
1143 | 1142 |
1144 void ClientSocketPoolBaseHelper::Group::StartBackupJobTimer( | 1143 void ClientSocketPoolBaseHelper::Group::StartBackupJobTimer( |
1145 const std::string& group_name, | 1144 const std::string& group_name, |
1146 ClientSocketPoolBaseHelper* pool) { | 1145 ClientSocketPoolBaseHelper* pool) { |
1147 // Only allow one timer to run at a time. | 1146 // Only allow one timer to run at a time. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 !pointer.is_null() && i < jobs_.size(); | 1263 !pointer.is_null() && i < jobs_.size(); |
1265 pointer = pending_requests_.GetNextTowardsLastMin(pointer), ++i) { | 1264 pointer = pending_requests_.GetNextTowardsLastMin(pointer), ++i) { |
1266 if (pointer.value()->handle() == handle) | 1265 if (pointer.value()->handle() == handle) |
1267 return true; | 1266 return true; |
1268 } | 1267 } |
1269 return false; | 1268 return false; |
1270 } | 1269 } |
1271 | 1270 |
1272 void ClientSocketPoolBaseHelper::Group::InsertPendingRequest( | 1271 void ClientSocketPoolBaseHelper::Group::InsertPendingRequest( |
1273 scoped_ptr<const Request> request) { | 1272 scoped_ptr<const Request> request) { |
1274 // This value must be cached before we release |request|. | 1273 RequestQueue::Priority queue_priority = request->priority(); |
1275 RequestPriority priority = request->priority(); | 1274 // Prioritize requests with |ignore_limits| over ones that don't. |
1276 if (request->ignore_limits()) { | 1275 if (request->ignore_limits()) |
1277 // Put requests with ignore_limits == true (which should have | 1276 queue_priority += NUM_PRIORITIES; |
1278 // priority == MAXIMUM_PRIORITY) ahead of other requests with | 1277 pending_requests_.Insert(request.release(), queue_priority); |
1279 // MAXIMUM_PRIORITY. | |
1280 DCHECK_EQ(priority, MAXIMUM_PRIORITY); | |
1281 pending_requests_.InsertAtFront(request.release(), priority); | |
1282 } else { | |
1283 pending_requests_.Insert(request.release(), priority); | |
1284 } | |
1285 } | 1278 } |
1286 | 1279 |
1287 scoped_ptr<const ClientSocketPoolBaseHelper::Request> | 1280 scoped_ptr<const ClientSocketPoolBaseHelper::Request> |
1288 ClientSocketPoolBaseHelper::Group::PopNextPendingRequest() { | 1281 ClientSocketPoolBaseHelper::Group::PopNextPendingRequest() { |
1289 if (pending_requests_.empty()) | 1282 if (pending_requests_.empty()) |
1290 return scoped_ptr<const ClientSocketPoolBaseHelper::Request>(); | 1283 return scoped_ptr<const ClientSocketPoolBaseHelper::Request>(); |
1291 return RemovePendingRequest(pending_requests_.FirstMax()); | 1284 return RemovePendingRequest(pending_requests_.FirstMax()); |
1292 } | 1285 } |
1293 | 1286 |
1294 scoped_ptr<const ClientSocketPoolBaseHelper::Request> | 1287 scoped_ptr<const ClientSocketPoolBaseHelper::Request> |
(...skipping 17 matching lines...) Expand all Loading... |
1312 pending_requests_.Erase(pointer); | 1305 pending_requests_.Erase(pointer); |
1313 // If there are no more requests, kill the backup timer. | 1306 // If there are no more requests, kill the backup timer. |
1314 if (pending_requests_.empty()) | 1307 if (pending_requests_.empty()) |
1315 backup_job_timer_.Stop(); | 1308 backup_job_timer_.Stop(); |
1316 return request.Pass(); | 1309 return request.Pass(); |
1317 } | 1310 } |
1318 | 1311 |
1319 } // namespace internal | 1312 } // namespace internal |
1320 | 1313 |
1321 } // namespace net | 1314 } // namespace net |
OLD | NEW |