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 <math.h> | 7 #include <math.h> |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {} | 215 ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {} |
216 | 216 |
217 // InsertRequestIntoQueue inserts the request into the queue based on | 217 // InsertRequestIntoQueue inserts the request into the queue based on |
218 // priority. Highest priorities are closest to the front. Older requests are | 218 // priority. Highest priorities are closest to the front. Older requests are |
219 // prioritized over requests of equal priority. | 219 // prioritized over requests of equal priority. |
220 // | 220 // |
221 // static | 221 // static |
222 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( | 222 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( |
223 const Request* r, RequestQueue* pending_requests) { | 223 const Request* r, RequestQueue* pending_requests) { |
224 RequestQueue::iterator it = pending_requests->begin(); | 224 RequestQueue::iterator it = pending_requests->begin(); |
225 while (it != pending_requests->end() && r->priority() >= (*it)->priority()) | 225 while (it != pending_requests->end() && r->priority() <= (*it)->priority()) |
226 ++it; | 226 ++it; |
227 pending_requests->insert(it, r); | 227 pending_requests->insert(it, r); |
228 } | 228 } |
229 | 229 |
230 // static | 230 // static |
231 const ClientSocketPoolBaseHelper::Request* | 231 const ClientSocketPoolBaseHelper::Request* |
232 ClientSocketPoolBaseHelper::RemoveRequestFromQueue( | 232 ClientSocketPoolBaseHelper::RemoveRequestFromQueue( |
233 const RequestQueue::iterator& it, Group* group) { | 233 const RequestQueue::iterator& it, Group* group) { |
234 const Request* req = *it; | 234 const Request* req = *it; |
235 group->mutable_pending_requests()->erase(it); | 235 group->mutable_pending_requests()->erase(it); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 | 325 |
326 if (rv == ERR_IO_PENDING) | 326 if (rv == ERR_IO_PENDING) |
327 rv = OK; | 327 rv = OK; |
328 request.net_log().EndEventWithNetErrorCode( | 328 request.net_log().EndEventWithNetErrorCode( |
329 NetLog::TYPE_SOCKET_POOL_CONNECTING_N_SOCKETS, rv); | 329 NetLog::TYPE_SOCKET_POOL_CONNECTING_N_SOCKETS, rv); |
330 } | 330 } |
331 | 331 |
332 int ClientSocketPoolBaseHelper::RequestSocketInternal( | 332 int ClientSocketPoolBaseHelper::RequestSocketInternal( |
333 const std::string& group_name, | 333 const std::string& group_name, |
334 const Request* request) { | 334 const Request* request) { |
335 DCHECK_GE(request->priority(), 0); | |
Ryan Hamilton
2012/04/23 22:51:05
Should we DCHECK that priority is between HIGHEST
| |
336 ClientSocketHandle* const handle = request->handle(); | 335 ClientSocketHandle* const handle = request->handle(); |
337 const bool preconnecting = !handle; | 336 const bool preconnecting = !handle; |
338 Group* group = GetOrCreateGroup(group_name); | 337 Group* group = GetOrCreateGroup(group_name); |
339 | 338 |
340 if (!(request->flags() & NO_IDLE_SOCKETS)) { | 339 if (!(request->flags() & NO_IDLE_SOCKETS)) { |
341 // Try to reuse a socket. | 340 // Try to reuse a socket. |
342 if (AssignIdleSocketToGroup(request, group)) | 341 if (AssignIdleSocketToGroup(request, group)) |
343 return OK; | 342 return OK; |
344 } | 343 } |
345 | 344 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 i != group_map_.end(); ++i) { | 826 i != group_map_.end(); ++i) { |
828 Group* curr_group = i->second; | 827 Group* curr_group = i->second; |
829 const RequestQueue& queue = curr_group->pending_requests(); | 828 const RequestQueue& queue = curr_group->pending_requests(); |
830 if (queue.empty()) | 829 if (queue.empty()) |
831 continue; | 830 continue; |
832 if (curr_group->IsStalledOnPoolMaxSockets(max_sockets_per_group_)) { | 831 if (curr_group->IsStalledOnPoolMaxSockets(max_sockets_per_group_)) { |
833 if (!group) | 832 if (!group) |
834 return true; | 833 return true; |
835 has_stalled_group = true; | 834 has_stalled_group = true; |
836 bool has_higher_priority = !top_group || | 835 bool has_higher_priority = !top_group || |
837 curr_group->TopPendingPriority() < top_group->TopPendingPriority(); | 836 curr_group->TopPendingPriority() > top_group->TopPendingPriority(); |
838 if (has_higher_priority) { | 837 if (has_higher_priority) { |
839 top_group = curr_group; | 838 top_group = curr_group; |
840 top_group_name = &i->first; | 839 top_group_name = &i->first; |
841 } | 840 } |
842 } | 841 } |
843 } | 842 } |
844 | 843 |
845 if (top_group) { | 844 if (top_group) { |
846 CHECK(group); | 845 CHECK(group); |
847 *group = top_group; | 846 *group = top_group; |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1213 // Delete active jobs. | 1212 // Delete active jobs. |
1214 STLDeleteElements(&jobs_); | 1213 STLDeleteElements(&jobs_); |
1215 | 1214 |
1216 // Cancel pending backup job. | 1215 // Cancel pending backup job. |
1217 weak_factory_.InvalidateWeakPtrs(); | 1216 weak_factory_.InvalidateWeakPtrs(); |
1218 } | 1217 } |
1219 | 1218 |
1220 } // namespace internal | 1219 } // namespace internal |
1221 | 1220 |
1222 } // namespace net | 1221 } // namespace net |
OLD | NEW |