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