| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 TransportConnectJob::TransportConnectJob( | 194 TransportConnectJob::TransportConnectJob( |
| 195 const std::string& group_name, | 195 const std::string& group_name, |
| 196 RequestPriority priority, | 196 RequestPriority priority, |
| 197 const scoped_refptr<TransportSocketParams>& params, | 197 const scoped_refptr<TransportSocketParams>& params, |
| 198 base::TimeDelta timeout_duration, | 198 base::TimeDelta timeout_duration, |
| 199 ClientSocketFactory* client_socket_factory, | 199 ClientSocketFactory* client_socket_factory, |
| 200 HostResolver* host_resolver, | 200 HostResolver* host_resolver, |
| 201 Delegate* delegate, | 201 Delegate* delegate, |
| 202 NetLog* net_log) | 202 NetLog* net_log) |
| 203 : ConnectJob(group_name, timeout_duration, priority, delegate, | 203 : ConnectJob(group_name, |
| 204 timeout_duration, |
| 205 priority, |
| 206 delegate, |
| 204 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 207 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 205 helper_(params, client_socket_factory, host_resolver, &connect_timing_), | 208 helper_(params, client_socket_factory, host_resolver, &connect_timing_), |
| 206 interval_between_connects_(CONNECT_INTERVAL_GT_20MS) { | 209 interval_between_connects_(CONNECT_INTERVAL_GT_20MS), |
| 210 connect_result_(OK) { |
| 207 helper_.SetOnIOComplete(this); | 211 helper_.SetOnIOComplete(this); |
| 208 } | 212 } |
| 209 | 213 |
| 210 TransportConnectJob::~TransportConnectJob() { | 214 TransportConnectJob::~TransportConnectJob() { |
| 211 // We don't worry about cancelling the host resolution and TCP connect, since | 215 // We don't worry about cancelling the host resolution and TCP connect, since |
| 212 // ~SingleRequestHostResolver and ~StreamSocket will take care of it. | 216 // ~SingleRequestHostResolver and ~StreamSocket will take care of it. |
| 213 } | 217 } |
| 214 | 218 |
| 215 LoadState TransportConnectJob::GetLoadState() const { | 219 LoadState TransportConnectJob::GetLoadState() const { |
| 216 switch (helper_.next_state()) { | 220 switch (helper_.next_state()) { |
| 217 case TransportConnectJobHelper::STATE_RESOLVE_HOST: | 221 case TransportConnectJobHelper::STATE_RESOLVE_HOST: |
| 218 case TransportConnectJobHelper::STATE_RESOLVE_HOST_COMPLETE: | 222 case TransportConnectJobHelper::STATE_RESOLVE_HOST_COMPLETE: |
| 219 return LOAD_STATE_RESOLVING_HOST; | 223 return LOAD_STATE_RESOLVING_HOST; |
| 220 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT: | 224 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT: |
| 221 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE: | 225 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE: |
| 222 return LOAD_STATE_CONNECTING; | 226 return LOAD_STATE_CONNECTING; |
| 223 case TransportConnectJobHelper::STATE_NONE: | 227 case TransportConnectJobHelper::STATE_NONE: |
| 224 return LOAD_STATE_IDLE; | 228 return LOAD_STATE_IDLE; |
| 225 } | 229 } |
| 226 NOTREACHED(); | 230 NOTREACHED(); |
| 227 return LOAD_STATE_IDLE; | 231 return LOAD_STATE_IDLE; |
| 228 } | 232 } |
| 229 | 233 |
| 234 void TransportConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { |
| 235 if (connect_result_ == OK) |
| 236 return; |
| 237 |
| 238 // If the actual socket Connect call failed, record the result and the last |
| 239 // address attempted. |
| 240 // TODO(ttuttle): Plumb into the socket layer and record *all* attempts. |
| 241 DCHECK_LT(0u, helper_.addresses().size()); |
| 242 ClientSocketHandle::ConnectionAttempts attempts; |
| 243 attempts.push_back(ClientSocketHandle::ConnectionAttempt( |
| 244 helper_.addresses().back(), connect_result_)); |
| 245 handle->set_connection_attempts(attempts); |
| 246 } |
| 247 |
| 230 // static | 248 // static |
| 231 void TransportConnectJob::MakeAddressListStartWithIPv4(AddressList* list) { | 249 void TransportConnectJob::MakeAddressListStartWithIPv4(AddressList* list) { |
| 232 for (AddressList::iterator i = list->begin(); i != list->end(); ++i) { | 250 for (AddressList::iterator i = list->begin(); i != list->end(); ++i) { |
| 233 if (i->GetFamily() == ADDRESS_FAMILY_IPV4) { | 251 if (i->GetFamily() == ADDRESS_FAMILY_IPV4) { |
| 234 std::rotate(list->begin(), i, list->end()); | 252 std::rotate(list->begin(), i, list->end()); |
| 235 break; | 253 break; |
| 236 } | 254 } |
| 237 } | 255 } |
| 238 } | 256 } |
| 239 | 257 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 401 } |
| 384 | 402 |
| 385 SetSocket(transport_socket_.Pass()); | 403 SetSocket(transport_socket_.Pass()); |
| 386 fallback_timer_.Stop(); | 404 fallback_timer_.Stop(); |
| 387 } else { | 405 } else { |
| 388 // Be a bit paranoid and kill off the fallback members to prevent reuse. | 406 // Be a bit paranoid and kill off the fallback members to prevent reuse. |
| 389 fallback_transport_socket_.reset(); | 407 fallback_transport_socket_.reset(); |
| 390 fallback_addresses_.reset(); | 408 fallback_addresses_.reset(); |
| 391 } | 409 } |
| 392 | 410 |
| 411 connect_result_ = result; |
| 412 |
| 393 return result; | 413 return result; |
| 394 } | 414 } |
| 395 | 415 |
| 396 void TransportConnectJob::DoIPv6FallbackTransportConnect() { | 416 void TransportConnectJob::DoIPv6FallbackTransportConnect() { |
| 397 // The timer should only fire while we're waiting for the main connect to | 417 // The timer should only fire while we're waiting for the main connect to |
| 398 // succeed. | 418 // succeed. |
| 399 if (helper_.next_state() != | 419 if (helper_.next_state() != |
| 400 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE) { | 420 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE) { |
| 401 NOTREACHED(); | 421 NOTREACHED(); |
| 402 return; | 422 return; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 HigherLayeredPool* higher_pool) { | 615 HigherLayeredPool* higher_pool) { |
| 596 base_.AddHigherLayeredPool(higher_pool); | 616 base_.AddHigherLayeredPool(higher_pool); |
| 597 } | 617 } |
| 598 | 618 |
| 599 void TransportClientSocketPool::RemoveHigherLayeredPool( | 619 void TransportClientSocketPool::RemoveHigherLayeredPool( |
| 600 HigherLayeredPool* higher_pool) { | 620 HigherLayeredPool* higher_pool) { |
| 601 base_.RemoveHigherLayeredPool(higher_pool); | 621 base_.RemoveHigherLayeredPool(higher_pool); |
| 602 } | 622 } |
| 603 | 623 |
| 604 } // namespace net | 624 } // namespace net |
| OLD | NEW |