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) { |
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 (connect_result_ == OK) |
| 237 return; |
| 238 |
| 239 // If the actual socket Connect call failed, record the result and the last |
| 240 // address attempted. |
| 241 // TODO(ttuttle): Plumb into the socket layer and record *all* attempts. |
| 242 DCHECK_LT(0u, helper_.addresses().size()); |
| 243 ConnectionAttempts attempts; |
| 244 attempts.push_back( |
| 245 ConnectionAttempt(helper_.addresses().back(), connect_result_)); |
| 246 handle->set_connection_attempts(attempts); |
| 247 } |
| 248 |
231 // static | 249 // static |
232 void TransportConnectJob::MakeAddressListStartWithIPv4(AddressList* list) { | 250 void TransportConnectJob::MakeAddressListStartWithIPv4(AddressList* list) { |
233 for (AddressList::iterator i = list->begin(); i != list->end(); ++i) { | 251 for (AddressList::iterator i = list->begin(); i != list->end(); ++i) { |
234 if (i->GetFamily() == ADDRESS_FAMILY_IPV4) { | 252 if (i->GetFamily() == ADDRESS_FAMILY_IPV4) { |
235 std::rotate(list->begin(), i, list->end()); | 253 std::rotate(list->begin(), i, list->end()); |
236 break; | 254 break; |
237 } | 255 } |
238 } | 256 } |
239 } | 257 } |
240 | 258 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 371 } |
354 | 372 |
355 SetSocket(transport_socket_.Pass()); | 373 SetSocket(transport_socket_.Pass()); |
356 fallback_timer_.Stop(); | 374 fallback_timer_.Stop(); |
357 } else { | 375 } else { |
358 // Be a bit paranoid and kill off the fallback members to prevent reuse. | 376 // Be a bit paranoid and kill off the fallback members to prevent reuse. |
359 fallback_transport_socket_.reset(); | 377 fallback_transport_socket_.reset(); |
360 fallback_addresses_.reset(); | 378 fallback_addresses_.reset(); |
361 } | 379 } |
362 | 380 |
| 381 connect_result_ = result; |
| 382 |
363 return result; | 383 return result; |
364 } | 384 } |
365 | 385 |
366 void TransportConnectJob::DoIPv6FallbackTransportConnect() { | 386 void TransportConnectJob::DoIPv6FallbackTransportConnect() { |
367 // The timer should only fire while we're waiting for the main connect to | 387 // The timer should only fire while we're waiting for the main connect to |
368 // succeed. | 388 // succeed. |
369 if (helper_.next_state() != | 389 if (helper_.next_state() != |
370 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE) { | 390 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE) { |
371 NOTREACHED(); | 391 NOTREACHED(); |
372 return; | 392 return; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 HigherLayeredPool* higher_pool) { | 583 HigherLayeredPool* higher_pool) { |
564 base_.AddHigherLayeredPool(higher_pool); | 584 base_.AddHigherLayeredPool(higher_pool); |
565 } | 585 } |
566 | 586 |
567 void TransportClientSocketPool::RemoveHigherLayeredPool( | 587 void TransportClientSocketPool::RemoveHigherLayeredPool( |
568 HigherLayeredPool* higher_pool) { | 588 HigherLayeredPool* higher_pool) { |
569 base_.RemoveHigherLayeredPool(higher_pool); | 589 base_.RemoveHigherLayeredPool(higher_pool); |
570 } | 590 } |
571 | 591 |
572 } // namespace net | 592 } // namespace net |
OLD | NEW |