| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 quic_request_(session_->quic_stream_factory()), | 217 quic_request_(session_->quic_stream_factory()), |
| 218 using_existing_quic_session_(false), | 218 using_existing_quic_session_(false), |
| 219 establishing_tunnel_(false), | 219 establishing_tunnel_(false), |
| 220 was_alpn_negotiated_(false), | 220 was_alpn_negotiated_(false), |
| 221 negotiated_protocol_(kProtoUnknown), | 221 negotiated_protocol_(kProtoUnknown), |
| 222 num_streams_(0), | 222 num_streams_(0), |
| 223 spdy_session_direct_( | 223 spdy_session_direct_( |
| 224 !(proxy_info.is_https() && origin_url_.SchemeIs(url::kHttpScheme))), | 224 !(proxy_info.is_https() && origin_url_.SchemeIs(url::kHttpScheme))), |
| 225 spdy_session_key_(GetSpdySessionKey()), | 225 spdy_session_key_(GetSpdySessionKey()), |
| 226 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), | 226 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), |
| 227 init_connection_already_resumed_(false), |
| 227 ptr_factory_(this) { | 228 ptr_factory_(this) { |
| 228 DCHECK(session); | 229 DCHECK(session); |
| 229 // The job can't have alternative service and alternative proxy server set at | 230 // The job can't have alternative service and alternative proxy server set at |
| 230 // the same time since alternative services are used for requests that are | 231 // the same time since alternative services are used for requests that are |
| 231 // fetched directly, while the alternative proxy server is used for requests | 232 // fetched directly, while the alternative proxy server is used for requests |
| 232 // that should be fetched using proxy. | 233 // that should be fetched using proxy. |
| 233 DCHECK(alternative_service_.protocol == kProtoUnknown || | 234 DCHECK(alternative_service_.protocol == kProtoUnknown || |
| 234 !alternative_proxy_server_.is_valid()); | 235 !alternative_proxy_server_.is_valid()); |
| 235 DCHECK(!alternative_proxy_server_.is_valid() || | 236 DCHECK(!alternative_proxy_server_.is_valid() || |
| 236 !(IsSpdyAlternative() || IsQuicAlternative())); | 237 !(IsSpdyAlternative() || IsQuicAlternative())); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } | 550 } |
| 550 | 551 |
| 551 void HttpStreamFactoryImpl::Job::RunLoop(int result) { | 552 void HttpStreamFactoryImpl::Job::RunLoop(int result) { |
| 552 TRACE_EVENT0(kNetTracingCategory, "HttpStreamFactoryImpl::Job::RunLoop"); | 553 TRACE_EVENT0(kNetTracingCategory, "HttpStreamFactoryImpl::Job::RunLoop"); |
| 553 result = DoLoop(result); | 554 result = DoLoop(result); |
| 554 | 555 |
| 555 if (result == ERR_IO_PENDING) | 556 if (result == ERR_IO_PENDING) |
| 556 return; | 557 return; |
| 557 | 558 |
| 558 if (job_type_ == PRECONNECT) { | 559 if (job_type_ == PRECONNECT) { |
| 560 session_->spdy_session_pool()->ResumeAllPendingRequests(spdy_session_key_); |
| 559 base::ThreadTaskRunnerHandle::Get()->PostTask( | 561 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 560 FROM_HERE, | 562 FROM_HERE, |
| 561 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, | 563 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, |
| 562 ptr_factory_.GetWeakPtr())); | 564 ptr_factory_.GetWeakPtr())); |
| 563 return; | 565 return; |
| 564 } | 566 } |
| 565 | 567 |
| 566 if (IsCertificateError(result)) { | 568 if (IsCertificateError(result)) { |
| 567 // Retrieve SSL information from the socket. | 569 // Retrieve SSL information from the socket. |
| 568 SSLInfo ssl_info; | 570 SSLInfo ssl_info; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 DCHECK_EQ(OK, rv); | 681 DCHECK_EQ(OK, rv); |
| 680 rv = DoStart(); | 682 rv = DoStart(); |
| 681 break; | 683 break; |
| 682 case STATE_WAIT: | 684 case STATE_WAIT: |
| 683 DCHECK_EQ(OK, rv); | 685 DCHECK_EQ(OK, rv); |
| 684 rv = DoWait(); | 686 rv = DoWait(); |
| 685 break; | 687 break; |
| 686 case STATE_WAIT_COMPLETE: | 688 case STATE_WAIT_COMPLETE: |
| 687 rv = DoWaitComplete(rv); | 689 rv = DoWaitComplete(rv); |
| 688 break; | 690 break; |
| 691 case STATE_EVALUATE_THROTTLE: |
| 692 DCHECK_EQ(OK, rv); |
| 693 rv = DoEvaluateThrottle(); |
| 694 break; |
| 689 case STATE_INIT_CONNECTION: | 695 case STATE_INIT_CONNECTION: |
| 690 DCHECK_EQ(OK, rv); | 696 DCHECK_EQ(OK, rv); |
| 691 rv = DoInitConnection(); | 697 rv = DoInitConnection(); |
| 692 break; | 698 break; |
| 693 case STATE_INIT_CONNECTION_COMPLETE: | 699 case STATE_INIT_CONNECTION_COMPLETE: |
| 694 rv = DoInitConnectionComplete(rv); | 700 rv = DoInitConnectionComplete(rv); |
| 695 break; | 701 break; |
| 696 case STATE_WAITING_USER_ACTION: | 702 case STATE_WAITING_USER_ACTION: |
| 697 rv = DoWaitingUserAction(rv); | 703 rv = DoWaitingUserAction(rv); |
| 698 break; | 704 break; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 NetLog::BoolCallback("should_wait", should_wait)); | 771 NetLog::BoolCallback("should_wait", should_wait)); |
| 766 if (should_wait) | 772 if (should_wait) |
| 767 return ERR_IO_PENDING; | 773 return ERR_IO_PENDING; |
| 768 | 774 |
| 769 return OK; | 775 return OK; |
| 770 } | 776 } |
| 771 | 777 |
| 772 int HttpStreamFactoryImpl::Job::DoWaitComplete(int result) { | 778 int HttpStreamFactoryImpl::Job::DoWaitComplete(int result) { |
| 773 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_WAITING); | 779 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_WAITING); |
| 774 DCHECK_EQ(OK, result); | 780 DCHECK_EQ(OK, result); |
| 781 next_state_ = STATE_EVALUATE_THROTTLE; |
| 782 return OK; |
| 783 } |
| 784 |
| 785 int HttpStreamFactoryImpl::Job::DoEvaluateThrottle() { |
| 775 next_state_ = STATE_INIT_CONNECTION; | 786 next_state_ = STATE_INIT_CONNECTION; |
| 776 return OK; | 787 // Throttle connect to an HTTP/2 supported server, if there are pending |
| 788 // requests with the same SpdySessionKey. |
| 789 if (session_->http_server_properties()->RequiresHTTP11( |
| 790 spdy_session_key_.host_port_pair())) |
| 791 return OK; |
| 792 url::SchemeHostPort scheme_host_port( |
| 793 using_ssl_ ? url::kHttpsScheme : url::kHttpScheme, |
| 794 spdy_session_key_.host_port_pair().host(), |
| 795 spdy_session_key_.host_port_pair().port()); |
| 796 if (!session_->http_server_properties()->GetSupportsSpdy(scheme_host_port)) |
| 797 return OK; |
| 798 base::Closure callback = |
| 799 base::Bind(&HttpStreamFactoryImpl::Job::ResumeInitConnection, |
| 800 ptr_factory_.GetWeakPtr()); |
| 801 if (session_->spdy_session_pool()->StartRequest(spdy_session_key_, |
| 802 callback)) { |
| 803 return OK; |
| 804 } |
| 805 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 806 FROM_HERE, callback, base::TimeDelta::FromMilliseconds(kHTTP2ThrottleMs)); |
| 807 return ERR_IO_PENDING; |
| 808 } |
| 809 |
| 810 void HttpStreamFactoryImpl::Job::ResumeInitConnection() { |
| 811 if (init_connection_already_resumed_) |
| 812 return; |
| 813 CHECK_EQ(next_state_, STATE_INIT_CONNECTION); |
| 814 init_connection_already_resumed_ = true; |
| 815 OnIOComplete(OK); |
| 777 } | 816 } |
| 778 | 817 |
| 779 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 818 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
| 780 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_INIT_CONNECTION); | 819 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_INIT_CONNECTION); |
| 781 int result = DoInitConnectionImpl(); | 820 int result = DoInitConnectionImpl(); |
| 782 if (result != ERR_SPDY_SESSION_ALREADY_EXISTS) | 821 if (result != ERR_SPDY_SESSION_ALREADY_EXISTS) |
| 783 delegate_->OnConnectionInitialized(this, result); | 822 delegate_->OnConnectionInitialized(this, result); |
| 784 | 823 |
| 785 return result; | 824 return result; |
| 786 } | 825 } |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1486 bool enable_ip_based_pooling, | 1525 bool enable_ip_based_pooling, |
| 1487 NetLog* net_log) { | 1526 NetLog* net_log) { |
| 1488 return base::MakeUnique<HttpStreamFactoryImpl::Job>( | 1527 return base::MakeUnique<HttpStreamFactoryImpl::Job>( |
| 1489 delegate, job_type, session, request_info, priority, proxy_info, | 1528 delegate, job_type, session, request_info, priority, proxy_info, |
| 1490 server_ssl_config, proxy_ssl_config, destination, origin_url, | 1529 server_ssl_config, proxy_ssl_config, destination, origin_url, |
| 1491 AlternativeService(), alternative_proxy_server, enable_ip_based_pooling, | 1530 AlternativeService(), alternative_proxy_server, enable_ip_based_pooling, |
| 1492 net_log); | 1531 net_log); |
| 1493 } | 1532 } |
| 1494 | 1533 |
| 1495 } // namespace net | 1534 } // namespace net |
| OLD | NEW |