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 resolve_result_(OK), |
| 212 connect_result_(OK) { |
208 helper_.SetOnIOComplete(this); | 213 helper_.SetOnIOComplete(this); |
209 } | 214 } |
210 | 215 |
211 TransportConnectJob::~TransportConnectJob() { | 216 TransportConnectJob::~TransportConnectJob() { |
212 // We don't worry about cancelling the host resolution and TCP connect, since | 217 // We don't worry about cancelling the host resolution and TCP connect, since |
213 // ~SingleRequestHostResolver and ~StreamSocket will take care of it. | 218 // ~SingleRequestHostResolver and ~StreamSocket will take care of it. |
214 } | 219 } |
215 | 220 |
216 LoadState TransportConnectJob::GetLoadState() const { | 221 LoadState TransportConnectJob::GetLoadState() const { |
217 switch (helper_.next_state()) { | 222 switch (helper_.next_state()) { |
218 case TransportConnectJobHelper::STATE_RESOLVE_HOST: | 223 case TransportConnectJobHelper::STATE_RESOLVE_HOST: |
219 case TransportConnectJobHelper::STATE_RESOLVE_HOST_COMPLETE: | 224 case TransportConnectJobHelper::STATE_RESOLVE_HOST_COMPLETE: |
220 return LOAD_STATE_RESOLVING_HOST; | 225 return LOAD_STATE_RESOLVING_HOST; |
221 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT: | 226 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT: |
222 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE: | 227 case TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE: |
223 return LOAD_STATE_CONNECTING; | 228 return LOAD_STATE_CONNECTING; |
224 case TransportConnectJobHelper::STATE_NONE: | 229 case TransportConnectJobHelper::STATE_NONE: |
225 return LOAD_STATE_IDLE; | 230 return LOAD_STATE_IDLE; |
226 } | 231 } |
227 NOTREACHED(); | 232 NOTREACHED(); |
228 return LOAD_STATE_IDLE; | 233 return LOAD_STATE_IDLE; |
229 } | 234 } |
230 | 235 |
| 236 void TransportConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { |
| 237 // If hostname resolution failed, record an empty endpoint and the result. |
| 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 ConnectionAttempts attempts; |
| 242 if (resolve_result_ != OK) { |
| 243 DCHECK_EQ(0u, helper_.addresses().size()); |
| 244 attempts.push_back(ConnectionAttempt(IPEndPoint(), resolve_result_)); |
| 245 } else if (connect_result_ != OK) { |
| 246 DCHECK_LT(0u, helper_.addresses().size()); |
| 247 attempts.push_back( |
| 248 ConnectionAttempt(helper_.addresses().back(), connect_result_)); |
| 249 } |
| 250 handle->set_connection_attempts(attempts); |
| 251 } |
| 252 |
231 // static | 253 // static |
232 void TransportConnectJob::MakeAddressListStartWithIPv4(AddressList* list) { | 254 void TransportConnectJob::MakeAddressListStartWithIPv4(AddressList* list) { |
233 for (AddressList::iterator i = list->begin(); i != list->end(); ++i) { | 255 for (AddressList::iterator i = list->begin(); i != list->end(); ++i) { |
234 if (i->GetFamily() == ADDRESS_FAMILY_IPV4) { | 256 if (i->GetFamily() == ADDRESS_FAMILY_IPV4) { |
235 std::rotate(list->begin(), i, list->end()); | 257 std::rotate(list->begin(), i, list->end()); |
236 break; | 258 break; |
237 } | 259 } |
238 } | 260 } |
239 } | 261 } |
240 | 262 |
241 int TransportConnectJob::DoResolveHost() { | 263 int TransportConnectJob::DoResolveHost() { |
242 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. | 264 // TODO(ricea): Remove ScopedTracker below once crbug.com/436634 is fixed. |
243 tracked_objects::ScopedTracker tracking_profile( | 265 tracked_objects::ScopedTracker tracking_profile( |
244 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 266 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
245 "436634 TransportConnectJob::DoResolveHost")); | 267 "436634 TransportConnectJob::DoResolveHost")); |
246 | 268 |
247 return helper_.DoResolveHost(priority(), net_log()); | 269 return helper_.DoResolveHost(priority(), net_log()); |
248 } | 270 } |
249 | 271 |
250 int TransportConnectJob::DoResolveHostComplete(int result) { | 272 int TransportConnectJob::DoResolveHostComplete(int result) { |
| 273 resolve_result_ = result; |
251 return helper_.DoResolveHostComplete(result, net_log()); | 274 return helper_.DoResolveHostComplete(result, net_log()); |
252 } | 275 } |
253 | 276 |
254 int TransportConnectJob::DoTransportConnect() { | 277 int TransportConnectJob::DoTransportConnect() { |
255 base::TimeTicks now = base::TimeTicks::Now(); | 278 base::TimeTicks now = base::TimeTicks::Now(); |
256 base::TimeTicks last_connect_time; | 279 base::TimeTicks last_connect_time; |
257 { | 280 { |
258 base::AutoLock lock(g_last_connect_time_lock.Get()); | 281 base::AutoLock lock(g_last_connect_time_lock.Get()); |
259 last_connect_time = g_last_connect_time.Get(); | 282 last_connect_time = g_last_connect_time.Get(); |
260 *g_last_connect_time.Pointer() = now; | 283 *g_last_connect_time.Pointer() = now; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 376 } |
354 | 377 |
355 SetSocket(transport_socket_.Pass()); | 378 SetSocket(transport_socket_.Pass()); |
356 fallback_timer_.Stop(); | 379 fallback_timer_.Stop(); |
357 } else { | 380 } else { |
358 // Be a bit paranoid and kill off the fallback members to prevent reuse. | 381 // Be a bit paranoid and kill off the fallback members to prevent reuse. |
359 fallback_transport_socket_.reset(); | 382 fallback_transport_socket_.reset(); |
360 fallback_addresses_.reset(); | 383 fallback_addresses_.reset(); |
361 } | 384 } |
362 | 385 |
| 386 connect_result_ = result; |
| 387 |
363 return result; | 388 return result; |
364 } | 389 } |
365 | 390 |
366 void TransportConnectJob::DoIPv6FallbackTransportConnect() { | 391 void TransportConnectJob::DoIPv6FallbackTransportConnect() { |
367 // The timer should only fire while we're waiting for the main connect to | 392 // The timer should only fire while we're waiting for the main connect to |
368 // succeed. | 393 // succeed. |
369 if (helper_.next_state() != | 394 if (helper_.next_state() != |
370 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE) { | 395 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE) { |
371 NOTREACHED(); | 396 NOTREACHED(); |
372 return; | 397 return; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 HigherLayeredPool* higher_pool) { | 588 HigherLayeredPool* higher_pool) { |
564 base_.AddHigherLayeredPool(higher_pool); | 589 base_.AddHigherLayeredPool(higher_pool); |
565 } | 590 } |
566 | 591 |
567 void TransportClientSocketPool::RemoveHigherLayeredPool( | 592 void TransportClientSocketPool::RemoveHigherLayeredPool( |
568 HigherLayeredPool* higher_pool) { | 593 HigherLayeredPool* higher_pool) { |
569 base_.RemoveHigherLayeredPool(higher_pool); | 594 base_.RemoveHigherLayeredPool(higher_pool); |
570 } | 595 } |
571 | 596 |
572 } // namespace net | 597 } // namespace net |
OLD | NEW |