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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 was_alpn_negotiated_(false), | 197 was_alpn_negotiated_(false), |
198 negotiated_protocol_(kProtoUnknown), | 198 negotiated_protocol_(kProtoUnknown), |
199 num_streams_(0), | 199 num_streams_(0), |
200 spdy_session_direct_( | 200 spdy_session_direct_( |
201 !(proxy_info.is_https() && origin_url_.SchemeIs(url::kHttpScheme))), | 201 !(proxy_info.is_https() && origin_url_.SchemeIs(url::kHttpScheme))), |
202 spdy_session_key_(GetSpdySessionKey(spdy_session_direct_, | 202 spdy_session_key_(GetSpdySessionKey(spdy_session_direct_, |
203 proxy_info_.proxy_server(), | 203 proxy_info_.proxy_server(), |
204 origin_url_, | 204 origin_url_, |
205 request_info_.privacy_mode)), | 205 request_info_.privacy_mode)), |
206 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), | 206 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), |
207 init_connection_already_resumed_(false), | |
207 ptr_factory_(this) { | 208 ptr_factory_(this) { |
208 DCHECK(session); | 209 DCHECK(session); |
209 if (alternative_protocol != kProtoUnknown) { | 210 if (alternative_protocol != kProtoUnknown) { |
210 // The job cannot have protocol requirements dictated by alternative service | 211 // The job cannot have protocol requirements dictated by alternative service |
211 // and have an alternative proxy server set at the same time, since | 212 // and have an alternative proxy server set at the same time, since |
212 // alternative services are used for requests that are fetched directly, | 213 // alternative services are used for requests that are fetched directly, |
213 // while the alternative proxy server is used for requests that should be | 214 // while the alternative proxy server is used for requests that should be |
214 // fetched using proxy. | 215 // fetched using proxy. |
215 DCHECK(!alternative_proxy_server_.is_valid()); | 216 DCHECK(!alternative_proxy_server_.is_valid()); |
216 // If the alternative service protocol is specified, then the job type must | 217 // If the alternative service protocol is specified, then the job type must |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 RunLoop(result); | 548 RunLoop(result); |
548 } | 549 } |
549 | 550 |
550 void HttpStreamFactoryImpl::Job::RunLoop(int result) { | 551 void HttpStreamFactoryImpl::Job::RunLoop(int result) { |
551 TRACE_EVENT0(kNetTracingCategory, "HttpStreamFactoryImpl::Job::RunLoop"); | 552 TRACE_EVENT0(kNetTracingCategory, "HttpStreamFactoryImpl::Job::RunLoop"); |
552 result = DoLoop(result); | 553 result = DoLoop(result); |
553 | 554 |
554 if (result == ERR_IO_PENDING) | 555 if (result == ERR_IO_PENDING) |
555 return; | 556 return; |
556 | 557 |
558 // Resume all throttled Jobs with the same SpdySessionKey if there are any, | |
559 // now that this job is done. | |
560 session_->spdy_session_pool()->ResumePendingRequests(spdy_session_key_); | |
561 | |
557 if (job_type_ == PRECONNECT) { | 562 if (job_type_ == PRECONNECT) { |
558 base::ThreadTaskRunnerHandle::Get()->PostTask( | 563 base::ThreadTaskRunnerHandle::Get()->PostTask( |
559 FROM_HERE, | 564 FROM_HERE, |
560 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, | 565 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, |
561 ptr_factory_.GetWeakPtr())); | 566 ptr_factory_.GetWeakPtr())); |
562 return; | 567 return; |
563 } | 568 } |
564 | 569 |
565 if (IsCertificateError(result)) { | 570 if (IsCertificateError(result)) { |
566 // Retrieve SSL information from the socket. | 571 // Retrieve SSL information from the socket. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 DCHECK_EQ(OK, rv); | 683 DCHECK_EQ(OK, rv); |
679 rv = DoStart(); | 684 rv = DoStart(); |
680 break; | 685 break; |
681 case STATE_WAIT: | 686 case STATE_WAIT: |
682 DCHECK_EQ(OK, rv); | 687 DCHECK_EQ(OK, rv); |
683 rv = DoWait(); | 688 rv = DoWait(); |
684 break; | 689 break; |
685 case STATE_WAIT_COMPLETE: | 690 case STATE_WAIT_COMPLETE: |
686 rv = DoWaitComplete(rv); | 691 rv = DoWaitComplete(rv); |
687 break; | 692 break; |
693 case STATE_EVALUATE_THROTTLE: | |
694 DCHECK_EQ(OK, rv); | |
695 rv = DoEvaluateThrottle(); | |
696 break; | |
688 case STATE_INIT_CONNECTION: | 697 case STATE_INIT_CONNECTION: |
689 DCHECK_EQ(OK, rv); | 698 DCHECK_EQ(OK, rv); |
690 rv = DoInitConnection(); | 699 rv = DoInitConnection(); |
691 break; | 700 break; |
692 case STATE_INIT_CONNECTION_COMPLETE: | 701 case STATE_INIT_CONNECTION_COMPLETE: |
693 rv = DoInitConnectionComplete(rv); | 702 rv = DoInitConnectionComplete(rv); |
694 break; | 703 break; |
695 case STATE_WAITING_USER_ACTION: | 704 case STATE_WAITING_USER_ACTION: |
696 rv = DoWaitingUserAction(rv); | 705 rv = DoWaitingUserAction(rv); |
697 break; | 706 break; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 NetLog::BoolCallback("should_wait", should_wait)); | 764 NetLog::BoolCallback("should_wait", should_wait)); |
756 if (should_wait) | 765 if (should_wait) |
757 return ERR_IO_PENDING; | 766 return ERR_IO_PENDING; |
758 | 767 |
759 return OK; | 768 return OK; |
760 } | 769 } |
761 | 770 |
762 int HttpStreamFactoryImpl::Job::DoWaitComplete(int result) { | 771 int HttpStreamFactoryImpl::Job::DoWaitComplete(int result) { |
763 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_WAITING); | 772 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB_WAITING); |
764 DCHECK_EQ(OK, result); | 773 DCHECK_EQ(OK, result); |
774 next_state_ = STATE_EVALUATE_THROTTLE; | |
775 return OK; | |
776 } | |
777 | |
778 int HttpStreamFactoryImpl::Job::DoEvaluateThrottle() { | |
765 next_state_ = STATE_INIT_CONNECTION; | 779 next_state_ = STATE_INIT_CONNECTION; |
766 return OK; | 780 if (!using_ssl_) |
781 return OK; | |
782 // Ask |delegate_delegate_| to update the spdy session key for the request | |
783 // that launched this job. | |
784 delegate_->SetSpdySessionKey(this, spdy_session_key_); | |
785 | |
786 // Throttle connect to an HTTP/2 supported server, if there are pending | |
787 // requests with the same SpdySessionKey. | |
788 if (session_->http_server_properties()->RequiresHTTP11( | |
789 spdy_session_key_.host_port_pair())) | |
790 return OK; | |
791 url::SchemeHostPort scheme_host_port( | |
792 using_ssl_ ? url::kHttpsScheme : url::kHttpScheme, | |
793 spdy_session_key_.host_port_pair().host(), | |
794 spdy_session_key_.host_port_pair().port()); | |
795 if (!session_->http_server_properties()->GetSupportsSpdy(scheme_host_port)) | |
796 return OK; | |
797 base::Closure callback = | |
798 base::Bind(&HttpStreamFactoryImpl::Job::ResumeInitConnection, | |
799 ptr_factory_.GetWeakPtr()); | |
800 if (session_->spdy_session_pool()->StartRequest(spdy_session_key_, | |
801 callback)) { | |
802 return OK; | |
803 } | |
804 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
805 FROM_HERE, callback, base::TimeDelta::FromMilliseconds(kHTTP2ThrottleMs)); | |
806 return ERR_IO_PENDING; | |
807 } | |
808 | |
809 void HttpStreamFactoryImpl::Job::ResumeInitConnection() { | |
810 if (init_connection_already_resumed_) | |
811 return; | |
812 CHECK_EQ(next_state_, STATE_INIT_CONNECTION); | |
Bence
2017/06/15 13:37:46
Very optional: a DCHECK should be enough here.
xunjieli
2017/06/15 13:53:25
Thanks. I add a TODO to change it back to DCHECK.
| |
813 init_connection_already_resumed_ = true; | |
814 OnIOComplete(OK); | |
767 } | 815 } |
768 | 816 |
769 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 817 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
770 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_INIT_CONNECTION); | 818 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_INIT_CONNECTION); |
771 int result = DoInitConnectionImpl(); | 819 int result = DoInitConnectionImpl(); |
772 if (result != ERR_SPDY_SESSION_ALREADY_EXISTS) | 820 if (result != ERR_SPDY_SESSION_ALREADY_EXISTS) |
773 delegate_->OnConnectionInitialized(this, result); | 821 delegate_->OnConnectionInitialized(this, result); |
774 | 822 |
775 return result; | 823 return result; |
776 } | 824 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 // If we're preconnecting, but we already have a SpdySession, we don't | 914 // If we're preconnecting, but we already have a SpdySession, we don't |
867 // actually need to preconnect any sockets, so we're done. | 915 // actually need to preconnect any sockets, so we're done. |
868 if (job_type_ == PRECONNECT) | 916 if (job_type_ == PRECONNECT) |
869 return OK; | 917 return OK; |
870 using_spdy_ = true; | 918 using_spdy_ = true; |
871 next_state_ = STATE_CREATE_STREAM; | 919 next_state_ = STATE_CREATE_STREAM; |
872 existing_spdy_session_ = spdy_session; | 920 existing_spdy_session_ = spdy_session; |
873 return OK; | 921 return OK; |
874 } | 922 } |
875 } | 923 } |
876 if (using_ssl_) { | |
877 // Ask |delegate_delegate_| to update the spdy session key for the request | |
878 // that launched this job. | |
879 delegate_->SetSpdySessionKey(this, spdy_session_key_); | |
880 } | |
881 | 924 |
882 if (proxy_info_.is_http() || proxy_info_.is_https()) | 925 if (proxy_info_.is_http() || proxy_info_.is_https()) |
883 establishing_tunnel_ = using_ssl_; | 926 establishing_tunnel_ = using_ssl_; |
884 | 927 |
885 HttpServerProperties* http_server_properties = | 928 HttpServerProperties* http_server_properties = |
886 session_->http_server_properties(); | 929 session_->http_server_properties(); |
887 if (http_server_properties) { | 930 if (http_server_properties) { |
888 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); | 931 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); |
889 if (proxy_info_.is_http() || proxy_info_.is_https()) { | 932 if (proxy_info_.is_http() || proxy_info_.is_https()) { |
890 http_server_properties->MaybeForceHTTP11( | 933 http_server_properties->MaybeForceHTTP11( |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1451 bool enable_ip_based_pooling, | 1494 bool enable_ip_based_pooling, |
1452 NetLog* net_log) { | 1495 NetLog* net_log) { |
1453 return base::MakeUnique<HttpStreamFactoryImpl::Job>( | 1496 return base::MakeUnique<HttpStreamFactoryImpl::Job>( |
1454 delegate, job_type, session, request_info, priority, proxy_info, | 1497 delegate, job_type, session, request_info, priority, proxy_info, |
1455 server_ssl_config, proxy_ssl_config, destination, origin_url, | 1498 server_ssl_config, proxy_ssl_config, destination, origin_url, |
1456 kProtoUnknown, alternative_proxy_server, enable_ip_based_pooling, | 1499 kProtoUnknown, alternative_proxy_server, enable_ip_based_pooling, |
1457 net_log); | 1500 net_log); |
1458 } | 1501 } |
1459 | 1502 |
1460 } // namespace net | 1503 } // namespace net |
OLD | NEW |