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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 if (result == ERR_IO_PENDING) | 445 if (result == ERR_IO_PENDING) |
446 return result; | 446 return result; |
447 | 447 |
448 // If there was an error, we should have already resumed the |waiting_job_|, | 448 // If there was an error, we should have already resumed the |waiting_job_|, |
449 // if there was one. | 449 // if there was one. |
450 DCHECK(result == OK || waiting_job_ == NULL); | 450 DCHECK(result == OK || waiting_job_ == NULL); |
451 | 451 |
452 if (IsPreconnecting()) { | 452 if (IsPreconnecting()) { |
453 base::MessageLoop::current()->PostTask( | 453 base::MessageLoop::current()->PostTask( |
454 FROM_HERE, | 454 FROM_HERE, |
455 base::Bind( | 455 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, |
456 &HttpStreamFactoryImpl::Job::OnPreconnectsComplete, | 456 ptr_factory_.GetWeakPtr())); |
457 ptr_factory_.GetWeakPtr())); | |
458 return ERR_IO_PENDING; | 457 return ERR_IO_PENDING; |
459 } | 458 } |
460 | 459 |
461 if (IsCertificateError(result)) { | 460 if (IsCertificateError(result)) { |
462 // Retrieve SSL information from the socket. | 461 // Retrieve SSL information from the socket. |
463 GetSSLInfo(); | 462 GetSSLInfo(); |
464 | 463 |
465 next_state_ = STATE_WAITING_USER_ACTION; | 464 next_state_ = STATE_WAITING_USER_ACTION; |
466 base::MessageLoop::current()->PostTask( | 465 base::MessageLoop::current()->PostTask( |
467 FROM_HERE, | 466 FROM_HERE, |
468 base::Bind( | 467 base::Bind(&HttpStreamFactoryImpl::Job::OnCertificateErrorCallback, |
469 &HttpStreamFactoryImpl::Job::OnCertificateErrorCallback, | 468 ptr_factory_.GetWeakPtr(), result, ssl_info_)); |
470 ptr_factory_.GetWeakPtr(), | |
471 result, ssl_info_)); | |
472 return ERR_IO_PENDING; | 469 return ERR_IO_PENDING; |
473 } | 470 } |
474 | 471 |
475 switch (result) { | 472 switch (result) { |
476 case ERR_PROXY_AUTH_REQUESTED: | 473 case ERR_PROXY_AUTH_REQUESTED: { |
477 { | 474 DCHECK(connection_.get()); |
478 DCHECK(connection_.get()); | 475 DCHECK(connection_->socket()); |
479 DCHECK(connection_->socket()); | 476 DCHECK(establishing_tunnel_); |
480 DCHECK(establishing_tunnel_); | |
481 | 477 |
482 ProxyClientSocket* proxy_socket = | 478 next_state_ = STATE_WAITING_USER_ACTION; |
483 static_cast<ProxyClientSocket*>(connection_->socket()); | 479 ProxyClientSocket* proxy_socket = |
484 const HttpResponseInfo* tunnel_auth_response = | 480 static_cast<ProxyClientSocket*>(connection_->socket()); |
485 proxy_socket->GetConnectResponseInfo(); | 481 base::MessageLoop::current()->PostTask( |
486 | 482 FROM_HERE, |
487 next_state_ = STATE_WAITING_USER_ACTION; | 483 base::Bind(&Job::OnNeedsProxyAuthCallback, ptr_factory_.GetWeakPtr(), |
488 base::MessageLoop::current()->PostTask( | 484 *proxy_socket->GetConnectResponseInfo(), |
489 FROM_HERE, | 485 proxy_socket->GetAuthController())); |
490 base::Bind( | |
491 &Job::OnNeedsProxyAuthCallback, | |
492 ptr_factory_.GetWeakPtr(), | |
493 *tunnel_auth_response, | |
494 proxy_socket->GetAuthController())); | |
495 } | |
496 return ERR_IO_PENDING; | 486 return ERR_IO_PENDING; |
| 487 } |
497 | 488 |
498 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: | 489 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: |
499 base::MessageLoop::current()->PostTask( | 490 base::MessageLoop::current()->PostTask( |
500 FROM_HERE, | 491 FROM_HERE, |
501 base::Bind( | 492 base::Bind(&Job::OnNeedsClientAuthCallback, ptr_factory_.GetWeakPtr(), |
502 &Job::OnNeedsClientAuthCallback, | 493 connection_->ssl_error_response_info().cert_request_info)); |
503 ptr_factory_.GetWeakPtr(), | |
504 connection_->ssl_error_response_info().cert_request_info)); | |
505 return ERR_IO_PENDING; | 494 return ERR_IO_PENDING; |
506 | 495 |
507 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE: | 496 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE: { |
508 { | 497 DCHECK(connection_.get()); |
509 DCHECK(connection_.get()); | 498 DCHECK(connection_->socket()); |
510 DCHECK(connection_->socket()); | 499 DCHECK(establishing_tunnel_); |
511 DCHECK(establishing_tunnel_); | |
512 | 500 |
513 ProxyClientSocket* proxy_socket = | 501 ProxyClientSocket* proxy_socket = |
514 static_cast<ProxyClientSocket*>(connection_->socket()); | 502 static_cast<ProxyClientSocket*>(connection_->socket()); |
515 base::MessageLoop::current()->PostTask( | 503 base::MessageLoop::current()->PostTask( |
516 FROM_HERE, | 504 FROM_HERE, |
517 base::Bind( | 505 base::Bind(&Job::OnHttpsProxyTunnelResponseCallback, |
518 &Job::OnHttpsProxyTunnelResponseCallback, | 506 ptr_factory_.GetWeakPtr(), |
519 ptr_factory_.GetWeakPtr(), | 507 *proxy_socket->GetConnectResponseInfo(), |
520 *proxy_socket->GetConnectResponseInfo(), | 508 proxy_socket->CreateConnectResponseStream())); |
521 proxy_socket->CreateConnectResponseStream())); | 509 return ERR_IO_PENDING; |
522 return ERR_IO_PENDING; | 510 } |
523 } | |
524 | 511 |
525 case OK: | 512 case OK: |
526 next_state_ = STATE_DONE; | 513 next_state_ = STATE_DONE; |
527 if (new_spdy_session_.get()) { | 514 if (new_spdy_session_.get()) { |
528 base::MessageLoop::current()->PostTask( | 515 base::MessageLoop::current()->PostTask( |
529 FROM_HERE, | 516 FROM_HERE, |
530 base::Bind(&Job::OnNewSpdySessionReadyCallback, | 517 base::Bind(&Job::OnNewSpdySessionReadyCallback, |
531 ptr_factory_.GetWeakPtr())); | 518 ptr_factory_.GetWeakPtr())); |
532 } else if (stream_factory_->for_websockets_) { | 519 } else if (stream_factory_->for_websockets_) { |
533 DCHECK(websocket_stream_); | 520 DCHECK(websocket_stream_); |
534 base::MessageLoop::current()->PostTask( | 521 base::MessageLoop::current()->PostTask( |
535 FROM_HERE, | 522 FROM_HERE, |
536 base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, | 523 base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, |
537 ptr_factory_.GetWeakPtr())); | 524 ptr_factory_.GetWeakPtr())); |
538 } else { | 525 } else { |
539 DCHECK(stream_.get()); | 526 DCHECK(stream_.get()); |
540 base::MessageLoop::current()->PostTask( | 527 base::MessageLoop::current()->PostTask( |
541 FROM_HERE, | 528 FROM_HERE, |
542 base::Bind( | 529 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr())); |
543 &Job::OnStreamReadyCallback, | |
544 ptr_factory_.GetWeakPtr())); | |
545 } | 530 } |
546 return ERR_IO_PENDING; | 531 return ERR_IO_PENDING; |
547 | 532 |
548 default: | 533 default: |
549 base::MessageLoop::current()->PostTask( | 534 base::MessageLoop::current()->PostTask( |
550 FROM_HERE, | 535 FROM_HERE, |
551 base::Bind( | 536 base::Bind(&Job::OnStreamFailedCallback, ptr_factory_.GetWeakPtr(), |
552 &Job::OnStreamFailedCallback, | 537 result)); |
553 ptr_factory_.GetWeakPtr(), | |
554 result)); | |
555 return ERR_IO_PENDING; | 538 return ERR_IO_PENDING; |
556 } | 539 } |
557 return result; | |
558 } | 540 } |
559 | 541 |
560 int HttpStreamFactoryImpl::Job::DoLoop(int result) { | 542 int HttpStreamFactoryImpl::Job::DoLoop(int result) { |
561 DCHECK_NE(next_state_, STATE_NONE); | 543 DCHECK_NE(next_state_, STATE_NONE); |
562 int rv = result; | 544 int rv = result; |
563 do { | 545 do { |
564 State state = next_state_; | 546 State state = next_state_; |
565 next_state_ = STATE_NONE; | 547 next_state_ = STATE_NONE; |
566 switch (state) { | 548 switch (state) { |
567 case STATE_START: | 549 case STATE_START: |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | | 1456 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | |
1475 net::LOAD_IS_DOWNLOAD)) { | 1457 net::LOAD_IS_DOWNLOAD)) { |
1476 // Avoid pipelining resources that may be streamed for a long time. | 1458 // Avoid pipelining resources that may be streamed for a long time. |
1477 return false; | 1459 return false; |
1478 } | 1460 } |
1479 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( | 1461 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( |
1480 *http_pipelining_key_.get()); | 1462 *http_pipelining_key_.get()); |
1481 } | 1463 } |
1482 | 1464 |
1483 } // namespace net | 1465 } // namespace net |
OLD | NEW |