| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 DCHECK_LE(0, max_sockets_per_group); | 182 DCHECK_LE(0, max_sockets_per_group); |
| 183 DCHECK_LE(max_sockets_per_group, max_sockets); | 183 DCHECK_LE(max_sockets_per_group, max_sockets); |
| 184 | 184 |
| 185 NetworkChangeNotifier::AddIPAddressObserver(this); | 185 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 186 } | 186 } |
| 187 | 187 |
| 188 ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { | 188 ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { |
| 189 // Clean up any idle sockets and pending connect jobs. Assert that we have no | 189 // Clean up any idle sockets and pending connect jobs. Assert that we have no |
| 190 // remaining active sockets or pending requests. They should have all been | 190 // remaining active sockets or pending requests. They should have all been |
| 191 // cleaned up prior to |this| being destroyed. | 191 // cleaned up prior to |this| being destroyed. |
| 192 Flush(); | 192 Flush(ERR_ABORTED); |
| 193 DCHECK(group_map_.empty()); | 193 DCHECK(group_map_.empty()); |
| 194 DCHECK(pending_callback_map_.empty()); | 194 DCHECK(pending_callback_map_.empty()); |
| 195 DCHECK_EQ(0, connecting_socket_count_); | 195 DCHECK_EQ(0, connecting_socket_count_); |
| 196 CHECK(higher_layer_pools_.empty()); | 196 CHECK(higher_layer_pools_.empty()); |
| 197 | 197 |
| 198 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 198 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 199 } | 199 } |
| 200 | 200 |
| 201 ClientSocketPoolBaseHelper::CallbackResultPair::CallbackResultPair() | 201 ClientSocketPoolBaseHelper::CallbackResultPair::CallbackResultPair() |
| 202 : result(OK) { | 202 : result(OK) { |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 RemoveConnectJob(job, group); | 896 RemoveConnectJob(job, group); |
| 897 } | 897 } |
| 898 if (!handed_out_socket) { | 898 if (!handed_out_socket) { |
| 899 OnAvailableSocketSlot(group_name, group); | 899 OnAvailableSocketSlot(group_name, group); |
| 900 CheckForStalledSocketGroups(); | 900 CheckForStalledSocketGroups(); |
| 901 } | 901 } |
| 902 } | 902 } |
| 903 } | 903 } |
| 904 | 904 |
| 905 void ClientSocketPoolBaseHelper::OnIPAddressChanged() { | 905 void ClientSocketPoolBaseHelper::OnIPAddressChanged() { |
| 906 Flush(); | 906 Flush(ERR_NETWORK_CHANGED); |
| 907 } | 907 } |
| 908 | 908 |
| 909 void ClientSocketPoolBaseHelper::Flush() { | 909 void ClientSocketPoolBaseHelper::Flush(int error) { |
| 910 pool_generation_number_++; | 910 pool_generation_number_++; |
| 911 CancelAllConnectJobs(); | 911 CancelAllConnectJobs(); |
| 912 CloseIdleSockets(); | 912 CloseIdleSockets(); |
| 913 AbortAllRequests(); | 913 AbortAllRequests(error); |
| 914 } | 914 } |
| 915 | 915 |
| 916 bool ClientSocketPoolBaseHelper::IsStalled() const { | 916 bool ClientSocketPoolBaseHelper::IsStalled() const { |
| 917 // If we are not using |max_sockets_|, then clearly we are not stalled | 917 // If we are not using |max_sockets_|, then clearly we are not stalled |
| 918 if ((handed_out_socket_count_ + connecting_socket_count_) < max_sockets_) | 918 if ((handed_out_socket_count_ + connecting_socket_count_) < max_sockets_) |
| 919 return false; | 919 return false; |
| 920 // So in order to be stalled we need to be using |max_sockets_| AND | 920 // So in order to be stalled we need to be using |max_sockets_| AND |
| 921 // we need to have a request that is actually stalled on the global | 921 // we need to have a request that is actually stalled on the global |
| 922 // socket limit. To find such a request, we look for a group that | 922 // socket limit. To find such a request, we look for a group that |
| 923 // a has more requests that jobs AND where the number of jobs is less | 923 // a has more requests that jobs AND where the number of jobs is less |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 // but i will already have been incremented to a valid iterator before | 1024 // but i will already have been incremented to a valid iterator before |
| 1025 // RemoveGroup() is called. | 1025 // RemoveGroup() is called. |
| 1026 RemoveGroup(i++); | 1026 RemoveGroup(i++); |
| 1027 } else { | 1027 } else { |
| 1028 ++i; | 1028 ++i; |
| 1029 } | 1029 } |
| 1030 } | 1030 } |
| 1031 DCHECK_EQ(0, connecting_socket_count_); | 1031 DCHECK_EQ(0, connecting_socket_count_); |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 void ClientSocketPoolBaseHelper::AbortAllRequests() { | 1034 void ClientSocketPoolBaseHelper::AbortAllRequests(int error) { |
| 1035 for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { | 1035 for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { |
| 1036 Group* group = i->second; | 1036 Group* group = i->second; |
| 1037 | 1037 |
| 1038 RequestQueue pending_requests; | 1038 RequestQueue pending_requests; |
| 1039 pending_requests.swap(*group->mutable_pending_requests()); | 1039 pending_requests.swap(*group->mutable_pending_requests()); |
| 1040 for (RequestQueue::iterator it2 = pending_requests.begin(); | 1040 for (RequestQueue::iterator it2 = pending_requests.begin(); |
| 1041 it2 != pending_requests.end(); ++it2) { | 1041 it2 != pending_requests.end(); ++it2) { |
| 1042 scoped_ptr<const Request> request(*it2); | 1042 scoped_ptr<const Request> request(*it2); |
| 1043 InvokeUserCallbackLater( | 1043 InvokeUserCallbackLater( |
| 1044 request->handle(), request->callback(), ERR_ABORTED); | 1044 request->handle(), request->callback(), error); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 // Delete group if no longer needed. | 1047 // Delete group if no longer needed. |
| 1048 if (group->IsEmpty()) { | 1048 if (group->IsEmpty()) { |
| 1049 // RemoveGroup() will call .erase() which will invalidate the iterator, | 1049 // RemoveGroup() will call .erase() which will invalidate the iterator, |
| 1050 // but i will already have been incremented to a valid iterator before | 1050 // but i will already have been incremented to a valid iterator before |
| 1051 // RemoveGroup() is called. | 1051 // RemoveGroup() is called. |
| 1052 RemoveGroup(i++); | 1052 RemoveGroup(i++); |
| 1053 } else { | 1053 } else { |
| 1054 ++i; | 1054 ++i; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 STLDeleteElements(&jobs_); | 1229 STLDeleteElements(&jobs_); |
| 1230 unassigned_job_count_ = 0; | 1230 unassigned_job_count_ = 0; |
| 1231 | 1231 |
| 1232 // Cancel pending backup job. | 1232 // Cancel pending backup job. |
| 1233 weak_factory_.InvalidateWeakPtrs(); | 1233 weak_factory_.InvalidateWeakPtrs(); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 } // namespace internal | 1236 } // namespace internal |
| 1237 | 1237 |
| 1238 } // namespace net | 1238 } // namespace net |
| OLD | NEW |