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/http/http_stream_factory_impl_job.h" | 5 #include "net/http/http_stream_factory_impl_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 // working. | 289 // working. |
290 return origin_url_.SchemeIs("https") || | 290 return origin_url_.SchemeIs("https") || |
291 proxy_info_.proxy_server().is_https() || IsSpdyAlternate(); | 291 proxy_info_.proxy_server().is_https() || IsSpdyAlternate(); |
292 } | 292 } |
293 | 293 |
294 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { | 294 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { |
295 DCHECK(stream_.get()); | 295 DCHECK(stream_.get()); |
296 DCHECK(!IsPreconnecting()); | 296 DCHECK(!IsPreconnecting()); |
297 DCHECK(!stream_factory_->for_websockets_); | 297 DCHECK(!stream_factory_->for_websockets_); |
298 | 298 |
299 MaybeCopyConnectionAttemptsFromClientSocketHandleToRequest(); | 299 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
300 | 300 |
301 if (IsOrphaned()) { | 301 if (IsOrphaned()) { |
302 stream_factory_->OnOrphanedJobComplete(this); | 302 stream_factory_->OnOrphanedJobComplete(this); |
303 } else { | 303 } else { |
304 request_->Complete(was_npn_negotiated(), | 304 request_->Complete(was_npn_negotiated(), |
305 protocol_negotiated(), | 305 protocol_negotiated(), |
306 using_spdy(), | 306 using_spdy(), |
307 net_log_); | 307 net_log_); |
308 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, | 308 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, |
309 stream_.release()); | 309 stream_.release()); |
310 } | 310 } |
311 // |this| may be deleted after this call. | 311 // |this| may be deleted after this call. |
312 } | 312 } |
313 | 313 |
314 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() { | 314 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() { |
315 DCHECK(websocket_stream_); | 315 DCHECK(websocket_stream_); |
316 DCHECK(!IsPreconnecting()); | 316 DCHECK(!IsPreconnecting()); |
317 DCHECK(stream_factory_->for_websockets_); | 317 DCHECK(stream_factory_->for_websockets_); |
318 // An orphaned WebSocket job will be closed immediately and | 318 // An orphaned WebSocket job will be closed immediately and |
319 // never be ready. | 319 // never be ready. |
320 DCHECK(!IsOrphaned()); | 320 DCHECK(!IsOrphaned()); |
321 | 321 |
322 MaybeCopyConnectionAttemptsFromClientSocketHandleToRequest(); | 322 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
323 | 323 |
324 request_->Complete(was_npn_negotiated(), | 324 request_->Complete(was_npn_negotiated(), |
325 protocol_negotiated(), | 325 protocol_negotiated(), |
326 using_spdy(), | 326 using_spdy(), |
327 net_log_); | 327 net_log_); |
328 request_->OnWebSocketHandshakeStreamReady(this, | 328 request_->OnWebSocketHandshakeStreamReady(this, |
329 server_ssl_config_, | 329 server_ssl_config_, |
330 proxy_info_, | 330 proxy_info_, |
331 websocket_stream_.release()); | 331 websocket_stream_.release()); |
332 // |this| may be deleted after this call. | 332 // |this| may be deleted after this call. |
333 } | 333 } |
334 | 334 |
335 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { | 335 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { |
336 DCHECK(stream_.get()); | 336 DCHECK(stream_.get()); |
337 DCHECK(!IsPreconnecting()); | 337 DCHECK(!IsPreconnecting()); |
338 DCHECK(using_spdy()); | 338 DCHECK(using_spdy()); |
339 // Note: an event loop iteration has passed, so |new_spdy_session_| may be | 339 // Note: an event loop iteration has passed, so |new_spdy_session_| may be |
340 // NULL at this point if the SpdySession closed immediately after creation. | 340 // NULL at this point if the SpdySession closed immediately after creation. |
341 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; | 341 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; |
342 new_spdy_session_.reset(); | 342 new_spdy_session_.reset(); |
343 | 343 |
344 MaybeCopyConnectionAttemptsFromClientSocketHandleToRequest(); | 344 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
345 | 345 |
346 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, | 346 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, |
347 // rather than notifying |request_| directly. | 347 // rather than notifying |request_| directly. |
348 if (IsOrphaned()) { | 348 if (IsOrphaned()) { |
349 if (spdy_session) { | 349 if (spdy_session) { |
350 stream_factory_->OnNewSpdySessionReady( | 350 stream_factory_->OnNewSpdySessionReady( |
351 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, | 351 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, |
352 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); | 352 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); |
353 } | 353 } |
354 stream_factory_->OnOrphanedJobComplete(this); | 354 stream_factory_->OnOrphanedJobComplete(this); |
355 } else { | 355 } else { |
356 request_->OnNewSpdySessionReady( | 356 request_->OnNewSpdySessionReady( |
357 this, stream_.Pass(), spdy_session, spdy_session_direct_); | 357 this, stream_.Pass(), spdy_session, spdy_session_direct_); |
358 } | 358 } |
359 // |this| may be deleted after this call. | 359 // |this| may be deleted after this call. |
360 } | 360 } |
361 | 361 |
362 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { | 362 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { |
363 DCHECK(!IsPreconnecting()); | 363 DCHECK(!IsPreconnecting()); |
364 | 364 |
365 MaybeCopyConnectionAttemptsFromClientSocketHandleToRequest(); | 365 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
366 | 366 |
367 if (IsOrphaned()) | 367 if (IsOrphaned()) |
368 stream_factory_->OnOrphanedJobComplete(this); | 368 stream_factory_->OnOrphanedJobComplete(this); |
369 else | 369 else |
370 request_->OnStreamFailed(this, result, server_ssl_config_); | 370 request_->OnStreamFailed(this, result, server_ssl_config_); |
371 // |this| may be deleted after this call. | 371 // |this| may be deleted after this call. |
372 } | 372 } |
373 | 373 |
374 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback( | 374 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback( |
375 int result, const SSLInfo& ssl_info) { | 375 int result, const SSLInfo& ssl_info) { |
376 DCHECK(!IsPreconnecting()); | 376 DCHECK(!IsPreconnecting()); |
377 | 377 |
378 MaybeCopyConnectionAttemptsFromClientSocketHandleToRequest(); | 378 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
379 | 379 |
380 if (IsOrphaned()) | 380 if (IsOrphaned()) |
381 stream_factory_->OnOrphanedJobComplete(this); | 381 stream_factory_->OnOrphanedJobComplete(this); |
382 else | 382 else |
383 request_->OnCertificateError(this, result, server_ssl_config_, ssl_info); | 383 request_->OnCertificateError(this, result, server_ssl_config_, ssl_info); |
384 // |this| may be deleted after this call. | 384 // |this| may be deleted after this call. |
385 } | 385 } |
386 | 386 |
387 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback( | 387 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback( |
388 const HttpResponseInfo& response, | 388 const HttpResponseInfo& response, |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1519 std::string scheme = origin_url_.scheme(); | 1519 std::string scheme = origin_url_.scheme(); |
1520 if (scheme == "https" || scheme == "wss" || IsSpdyAlternate()) | 1520 if (scheme == "https" || scheme == "wss" || IsSpdyAlternate()) |
1521 return ClientSocketPoolManager::SSL_GROUP; | 1521 return ClientSocketPoolManager::SSL_GROUP; |
1522 | 1522 |
1523 if (scheme == "ftp") | 1523 if (scheme == "ftp") |
1524 return ClientSocketPoolManager::FTP_GROUP; | 1524 return ClientSocketPoolManager::FTP_GROUP; |
1525 | 1525 |
1526 return ClientSocketPoolManager::NORMAL_GROUP; | 1526 return ClientSocketPoolManager::NORMAL_GROUP; |
1527 } | 1527 } |
1528 | 1528 |
1529 // If the connection succeeds, failed connection attempts leading up to the | |
1530 // success will be returned via the successfully connected socket. If the | |
1531 // connection fails, failed connection attempts will be returned via the | |
1532 // ClientSocketHandle. Check whether a socket was returned and copy the | |
1533 // connection attempts from the proper place. | |
1529 void HttpStreamFactoryImpl::Job:: | 1534 void HttpStreamFactoryImpl::Job:: |
1530 MaybeCopyConnectionAttemptsFromClientSocketHandleToRequest() { | 1535 MaybeCopyConnectionAttemptsFromSocketOrHandle() { |
1531 if (IsOrphaned() || !connection_) | 1536 if (IsOrphaned() || !connection_) |
1532 return; | 1537 return; |
1533 | 1538 |
1534 request_->AddConnectionAttempts(connection_->connection_attempts()); | 1539 if (connection_->socket()) { |
Randy Smith (Not in Mondays)
2015/05/14 19:42:05
Is there a way to write a unit test to test this c
Deprecated (see juliatuttle)
2015/05/14 20:02:35
I think it is implicitly tested by the tests at th
| |
1540 ConnectionAttempts socket_attempts; | |
1541 connection_->socket()->GetConnectionAttempts(&socket_attempts); | |
1542 request_->AddConnectionAttempts(socket_attempts); | |
1543 } else { | |
1544 request_->AddConnectionAttempts(connection_->connection_attempts()); | |
1545 } | |
1535 } | 1546 } |
1536 | 1547 |
1537 } // namespace net | 1548 } // namespace net |
OLD | NEW |