| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stats_counters.h" | 10 #include "base/stats_counters.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 pending_requests->erase(it); | 168 pending_requests->erase(it); |
| 169 return req; | 169 return req; |
| 170 } | 170 } |
| 171 | 171 |
| 172 int ClientSocketPoolBaseHelper::RequestSocket( | 172 int ClientSocketPoolBaseHelper::RequestSocket( |
| 173 const std::string& group_name, | 173 const std::string& group_name, |
| 174 const Request* request) { | 174 const Request* request) { |
| 175 request->net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL, NULL); | 175 request->net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL, NULL); |
| 176 Group& group = group_map_[group_name]; | 176 Group& group = group_map_[group_name]; |
| 177 int rv = RequestSocketInternal(group_name, request); | 177 int rv = RequestSocketInternal(group_name, request); |
| 178 if (rv != ERR_IO_PENDING) | 178 if (rv != ERR_IO_PENDING) { |
| 179 request->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); | 179 request->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); |
| 180 else | 180 delete request; |
| 181 } else { |
| 181 InsertRequestIntoQueue(request, &group.pending_requests); | 182 InsertRequestIntoQueue(request, &group.pending_requests); |
| 183 } |
| 182 return rv; | 184 return rv; |
| 183 } | 185 } |
| 184 | 186 |
| 185 int ClientSocketPoolBaseHelper::RequestSocketInternal( | 187 int ClientSocketPoolBaseHelper::RequestSocketInternal( |
| 186 const std::string& group_name, | 188 const std::string& group_name, |
| 187 const Request* request) { | 189 const Request* request) { |
| 188 DCHECK_GE(request->priority(), 0); | 190 DCHECK_GE(request->priority(), 0); |
| 189 CompletionCallback* const callback = request->callback(); | 191 CompletionCallback* const callback = request->callback(); |
| 190 CHECK(callback); | 192 CHECK(callback); |
| 191 ClientSocketHandle* const handle = request->handle(); | 193 ClientSocketHandle* const handle = request->handle(); |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 // |group| may no longer be valid after this point. Be careful not to | 649 // |group| may no longer be valid after this point. Be careful not to |
| 648 // access it again. | 650 // access it again. |
| 649 } else if (group->IsEmpty()) { | 651 } else if (group->IsEmpty()) { |
| 650 // Delete |group| if no longer needed. |group| will no longer be valid. | 652 // Delete |group| if no longer needed. |group| will no longer be valid. |
| 651 group_map_.erase(group_name); | 653 group_map_.erase(group_name); |
| 652 } | 654 } |
| 653 } | 655 } |
| 654 | 656 |
| 655 void ClientSocketPoolBaseHelper::ProcessPendingRequest( | 657 void ClientSocketPoolBaseHelper::ProcessPendingRequest( |
| 656 const std::string& group_name, Group* group) { | 658 const std::string& group_name, Group* group) { |
| 657 scoped_ptr<const Request> r(*group->pending_requests.begin()); | 659 int rv = RequestSocketInternal(group_name, *group->pending_requests.begin()); |
| 658 int rv = RequestSocketInternal(group_name, r.get()); | |
| 659 | 660 |
| 660 if (rv != ERR_IO_PENDING) { | 661 if (rv != ERR_IO_PENDING) { |
| 662 scoped_ptr<const Request> r(RemoveRequestFromQueue( |
| 663 group->pending_requests.begin(), &group->pending_requests)); |
| 661 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); | 664 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); |
| 662 RemoveRequestFromQueue(group->pending_requests.begin(), | |
| 663 &group->pending_requests); | |
| 664 r->callback()->Run(rv); | 665 r->callback()->Run(rv); |
| 665 if (rv != OK) { | 666 if (rv != OK) { |
| 666 // |group| may be invalid after the callback, we need to search | 667 // |group| may be invalid after the callback, we need to search |
| 667 // |group_map_| again. | 668 // |group_map_| again. |
| 668 MaybeOnAvailableSocketSlot(group_name); | 669 MaybeOnAvailableSocketSlot(group_name); |
| 669 } | 670 } |
| 670 } else { | |
| 671 r.release(); | |
| 672 } | 671 } |
| 673 } | 672 } |
| 674 | 673 |
| 675 void ClientSocketPoolBaseHelper::HandOutSocket( | 674 void ClientSocketPoolBaseHelper::HandOutSocket( |
| 676 ClientSocket* socket, | 675 ClientSocket* socket, |
| 677 bool reused, | 676 bool reused, |
| 678 ClientSocketHandle* handle, | 677 ClientSocketHandle* handle, |
| 679 base::TimeDelta idle_time, | 678 base::TimeDelta idle_time, |
| 680 Group* group, | 679 Group* group, |
| 681 const BoundNetLog& net_log) { | 680 const BoundNetLog& net_log) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 DCHECK_LE(total, max_sockets_); | 736 DCHECK_LE(total, max_sockets_); |
| 738 if (total < max_sockets_) | 737 if (total < max_sockets_) |
| 739 return false; | 738 return false; |
| 740 LOG(WARNING) << "ReachedMaxSocketsLimit: " << total << "/" << max_sockets_; | 739 LOG(WARNING) << "ReachedMaxSocketsLimit: " << total << "/" << max_sockets_; |
| 741 return true; | 740 return true; |
| 742 } | 741 } |
| 743 | 742 |
| 744 } // namespace internal | 743 } // namespace internal |
| 745 | 744 |
| 746 } // namespace net | 745 } // namespace net |
| OLD | NEW |