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 } |
| 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 // TODO(xunjieli): Change this to a DCHECK once crbug.com/718576 is stable. |
| 814 CHECK_EQ(next_state_, STATE_INIT_CONNECTION); |
| 815 init_connection_already_resumed_ = true; |
| 816 OnIOComplete(OK); |
767 } | 817 } |
768 | 818 |
769 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 819 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
770 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_INIT_CONNECTION); | 820 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_JOB_INIT_CONNECTION); |
771 int result = DoInitConnectionImpl(); | 821 int result = DoInitConnectionImpl(); |
772 if (result != ERR_SPDY_SESSION_ALREADY_EXISTS) | 822 if (result != ERR_SPDY_SESSION_ALREADY_EXISTS) |
773 delegate_->OnConnectionInitialized(this, result); | 823 delegate_->OnConnectionInitialized(this, result); |
774 | 824 |
775 return result; | 825 return result; |
776 } | 826 } |
(...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 | 916 // If we're preconnecting, but we already have a SpdySession, we don't |
867 // actually need to preconnect any sockets, so we're done. | 917 // actually need to preconnect any sockets, so we're done. |
868 if (job_type_ == PRECONNECT) | 918 if (job_type_ == PRECONNECT) |
869 return OK; | 919 return OK; |
870 using_spdy_ = true; | 920 using_spdy_ = true; |
871 next_state_ = STATE_CREATE_STREAM; | 921 next_state_ = STATE_CREATE_STREAM; |
872 existing_spdy_session_ = spdy_session; | 922 existing_spdy_session_ = spdy_session; |
873 return OK; | 923 return OK; |
874 } | 924 } |
875 } | 925 } |
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 | 926 |
882 if (proxy_info_.is_http() || proxy_info_.is_https()) | 927 if (proxy_info_.is_http() || proxy_info_.is_https()) |
883 establishing_tunnel_ = using_ssl_; | 928 establishing_tunnel_ = using_ssl_; |
884 | 929 |
885 HttpServerProperties* http_server_properties = | 930 HttpServerProperties* http_server_properties = |
886 session_->http_server_properties(); | 931 session_->http_server_properties(); |
887 if (http_server_properties) { | 932 if (http_server_properties) { |
888 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); | 933 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); |
889 if (proxy_info_.is_http() || proxy_info_.is_https()) { | 934 if (proxy_info_.is_http() || proxy_info_.is_https()) { |
890 http_server_properties->MaybeForceHTTP11( | 935 http_server_properties->MaybeForceHTTP11( |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 bool enable_ip_based_pooling, | 1496 bool enable_ip_based_pooling, |
1452 NetLog* net_log) { | 1497 NetLog* net_log) { |
1453 return base::MakeUnique<HttpStreamFactoryImpl::Job>( | 1498 return base::MakeUnique<HttpStreamFactoryImpl::Job>( |
1454 delegate, job_type, session, request_info, priority, proxy_info, | 1499 delegate, job_type, session, request_info, priority, proxy_info, |
1455 server_ssl_config, proxy_ssl_config, destination, origin_url, | 1500 server_ssl_config, proxy_ssl_config, destination, origin_url, |
1456 kProtoUnknown, alternative_proxy_server, enable_ip_based_pooling, | 1501 kProtoUnknown, alternative_proxy_server, enable_ip_based_pooling, |
1457 net_log); | 1502 net_log); |
1458 } | 1503 } |
1459 | 1504 |
1460 } // namespace net | 1505 } // namespace net |
OLD | NEW |