Chromium Code Reviews| 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/transport_client_socket_pool.h" | 5 #include "net/socket/transport_client_socket_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 | 194 |
| 195 TransportConnectJob::TransportConnectJob( | 195 TransportConnectJob::TransportConnectJob( |
| 196 const std::string& group_name, | 196 const std::string& group_name, |
| 197 RequestPriority priority, | 197 RequestPriority priority, |
| 198 const scoped_refptr<TransportSocketParams>& params, | 198 const scoped_refptr<TransportSocketParams>& params, |
| 199 base::TimeDelta timeout_duration, | 199 base::TimeDelta timeout_duration, |
| 200 ClientSocketFactory* client_socket_factory, | 200 ClientSocketFactory* client_socket_factory, |
| 201 HostResolver* host_resolver, | 201 HostResolver* host_resolver, |
| 202 Delegate* delegate, | 202 Delegate* delegate, |
| 203 NetLog* net_log) | 203 NetLog* net_log) |
| 204 : ConnectJob(group_name, timeout_duration, priority, delegate, | 204 : ConnectJob(group_name, |
| 205 timeout_duration, | |
| 206 priority, | |
| 207 delegate, | |
| 205 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 208 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 206 helper_(params, client_socket_factory, host_resolver, &connect_timing_), | 209 helper_(params, client_socket_factory, host_resolver, &connect_timing_), |
| 207 interval_between_connects_(CONNECT_INTERVAL_GT_20MS) { | 210 interval_between_connects_(CONNECT_INTERVAL_GT_20MS), |
| 211 connect_result_(OK) { | |
|
Randy Smith (Not in Mondays)
2015/04/23 19:04:09
Should there be an initialization for resolve_resu
Deprecated (see juliatuttle)
2015/04/23 21:04:16
Done.
| |
| 208 helper_.SetOnIOComplete(this); | 212 helper_.SetOnIOComplete(this); |
| 209 } | 213 } |
| 210 | 214 |
| 211 TransportConnectJob::~TransportConnectJob() { | 215 TransportConnectJob::~TransportConnectJob() { |
| 212 // We don't worry about cancelling the host resolution and TCP connect, since | 216 // We don't worry about cancelling the host resolution and TCP connect, since |
| 213 // ~SingleRequestHostResolver and ~StreamSocket will take care of it. | 217 // ~SingleRequestHostResolver and ~StreamSocket will take care of it. |
| 214 } | 218 } |
| 215 | 219 |
| 216 LoadState TransportConnectJob::GetLoadState() const { | 220 LoadState TransportConnectJob::GetLoadState() const { |
| 217 switch (helper_.next_state()) { | 221 switch (helper_.next_state()) { |
| 218 case TransportConnectJobHelper::STATE_RESOLVE_HOST: | 222 case TransportConnectJobHelper::STATE_RESOLVE_HOST: |
| 219 case TransportConnectJobHelper::STATE_RESOLVE_HOST_COMPLETE: | 223 case TransportConnectJobHelper::STATE_RESOLVE_HOST_COMPLETE: |
| 220 return LOAD_STATE_RESOLVING_HOST; | 224 return LOAD_STATE_RESOLVING_HOST; |
| 221 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT: | 225 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT: |
| 222 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE: | 226 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE: |
| 223 return LOAD_STATE_CONNECTING; | 227 return LOAD_STATE_CONNECTING; |
| 224 case TransportConnectJobHelper::STATE_NONE: | 228 case TransportConnectJobHelper::STATE_NONE: |
| 225 return LOAD_STATE_IDLE; | 229 return LOAD_STATE_IDLE; |
| 226 } | 230 } |
| 227 NOTREACHED(); | 231 NOTREACHED(); |
| 228 return LOAD_STATE_IDLE; | 232 return LOAD_STATE_IDLE; |
| 229 } | 233 } |
| 230 | 234 |
| 235 void TransportConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { | |
| 236 // If hostname resolution failed, record an empty endpoint and the result. | |
| 237 // If the actual socket Connect call failed, record the result and the last | |
| 238 // address attempted. | |
| 239 // TODO(ttuttle): Plumb into the socket layer and record *all* attempts. | |
| 240 ConnectionAttempts attempts; | |
| 241 if (resolve_result_ != OK) { | |
| 242 DCHECK_EQ(0u, helper_.addresses().size()); | |
| 243 attempts.push_back(ConnectionAttempt(IPEndPoint(), resolve_result_)); | |
| 244 } else if (connect_result_ != OK) { | |
| 245 DCHECK_LT(0u, helper_.addresses().size()); | |
| 246 attempts.push_back( | |
| 247 ConnectionAttempt(helper_.addresses().back(), connect_result_)); | |
| 248 } | |
| 249 handle->set_connection_attempts(attempts); | |
| 250 } | |
| 251 | |
| 231 // static | 252 // static |
| 232 void TransportConnectJob::MakeAddressListStartWithIPv4(AddressList* list) { | 253 void TransportConnectJob::MakeAddressListStartWithIPv4(AddressList* list) { |
| 233 for (AddressList::iterator i = list->begin(); i != list->end(); ++i) { | 254 for (AddressList::iterator i = list->begin(); i != list->end(); ++i) { |
| 234 if (i->GetFamily() == ADDRESS_FAMILY_IPV4) { | 255 if (i->GetFamily() == ADDRESS_FAMILY_IPV4) { |
| 235 std::rotate(list->begin(), i, list->end()); | 256 std::rotate(list->begin(), i, list->end()); |
| 236 break; | 257 break; |
| 237 } | 258 } |
| 238 } | 259 } |
| 239 } | 260 } |
| 240 | 261 |
| 241 int TransportConnectJob::DoResolveHost() { | 262 int TransportConnectJob::DoResolveHost() { |
| 242 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. | 263 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. |
| 243 tracked_objects::ScopedTracker tracking_profile( | 264 tracked_objects::ScopedTracker tracking_profile( |
| 244 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 265 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 245 "436634 TransportConnectJob::DoResolveHost")); | 266 "436634 TransportConnectJob::DoResolveHost")); |
| 246 | 267 |
| 247 return helper_.DoResolveHost(priority(), net_log()); | 268 return helper_.DoResolveHost(priority(), net_log()); |
| 248 } | 269 } |
| 249 | 270 |
| 250 int TransportConnectJob::DoResolveHostComplete(int result) { | 271 int TransportConnectJob::DoResolveHostComplete(int result) { |
| 272 resolve_result_ = result; | |
| 251 return helper_.DoResolveHostComplete(result, net_log()); | 273 return helper_.DoResolveHostComplete(result, net_log()); |
| 252 } | 274 } |
| 253 | 275 |
| 254 int TransportConnectJob::DoTransportConnect() { | 276 int TransportConnectJob::DoTransportConnect() { |
| 255 base::TimeTicks now = base::TimeTicks::Now(); | 277 base::TimeTicks now = base::TimeTicks::Now(); |
| 256 base::TimeTicks last_connect_time; | 278 base::TimeTicks last_connect_time; |
| 257 { | 279 { |
| 258 base::AutoLock lock(g_last_connect_time_lock.Get()); | 280 base::AutoLock lock(g_last_connect_time_lock.Get()); |
| 259 last_connect_time = g_last_connect_time.Get(); | 281 last_connect_time = g_last_connect_time.Get(); |
| 260 *g_last_connect_time.Pointer() = now; | 282 *g_last_connect_time.Pointer() = now; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 } | 375 } |
| 354 | 376 |
| 355 SetSocket(transport_socket_.Pass()); | 377 SetSocket(transport_socket_.Pass()); |
| 356 fallback_timer_.Stop(); | 378 fallback_timer_.Stop(); |
| 357 } else { | 379 } else { |
| 358 // Be a bit paranoid and kill off the fallback members to prevent reuse. | 380 // Be a bit paranoid and kill off the fallback members to prevent reuse. |
| 359 fallback_transport_socket_.reset(); | 381 fallback_transport_socket_.reset(); |
| 360 fallback_addresses_.reset(); | 382 fallback_addresses_.reset(); |
| 361 } | 383 } |
| 362 | 384 |
| 385 connect_result_ = result; | |
| 386 | |
| 363 return result; | 387 return result; |
| 364 } | 388 } |
| 365 | 389 |
| 366 void TransportConnectJob::DoIPv6FallbackTransportConnect() { | 390 void TransportConnectJob::DoIPv6FallbackTransportConnect() { |
| 367 // The timer should only fire while we're waiting for the main connect to | 391 // The timer should only fire while we're waiting for the main connect to |
| 368 // succeed. | 392 // succeed. |
| 369 if (helper_.next_state() != | 393 if (helper_.next_state() != |
| 370 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE) { | 394 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE) { |
| 371 NOTREACHED(); | 395 NOTREACHED(); |
| 372 return; | 396 return; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 HigherLayeredPool* higher_pool) { | 587 HigherLayeredPool* higher_pool) { |
| 564 base_.AddHigherLayeredPool(higher_pool); | 588 base_.AddHigherLayeredPool(higher_pool); |
| 565 } | 589 } |
| 566 | 590 |
| 567 void TransportClientSocketPool::RemoveHigherLayeredPool( | 591 void TransportClientSocketPool::RemoveHigherLayeredPool( |
| 568 HigherLayeredPool* higher_pool) { | 592 HigherLayeredPool* higher_pool) { |
| 569 base_.RemoveHigherLayeredPool(higher_pool); | 593 base_.RemoveHigherLayeredPool(higher_pool); |
| 570 } | 594 } |
| 571 | 595 |
| 572 } // namespace net | 596 } // namespace net |
| OLD | NEW |