Chromium Code Reviews| 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 resumed_init_connection_(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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 RunLoop(result); | 549 RunLoop(result); |
| 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 |
| 559 session_->spdy_session_pool()->ResumeAllPendingRequests(spdy_session_key_); | |
| 558 if (job_type_ == PRECONNECT) { | 560 if (job_type_ == PRECONNECT) { |
| 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. |
| (...skipping 111 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_BEFORE_INIT_CONNECTION: | |
| 692 DCHECK_EQ(OK, rv); | |
| 693 rv = DoBeforeInitConnection(); | |
| 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_BEFORE_INIT_CONNECTION; | |
| 782 return OK; | |
| 783 } | |
| 784 | |
| 785 int HttpStreamFactoryImpl::Job::DoBeforeInitConnection() { | |
| 775 next_state_ = STATE_INIT_CONNECTION; | 786 next_state_ = STATE_INIT_CONNECTION; |
| 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( | |
|
Bence
2017/06/09 19:17:38
Please invert this condition and do an early retur
xunjieli
2017/06/13 15:23:10
Done.
| |
| 790 spdy_session_key_.host_port_pair())) { | |
| 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)) { | |
|
Bence
2017/06/09 19:17:38
Please invert this condition and do an early retur
xunjieli
2017/06/13 15:23:10
Done.
| |
| 796 base::Closure callback = | |
| 797 base::Bind(&HttpStreamFactoryImpl::Job::ResumeInitConnection, | |
| 798 ptr_factory_.GetWeakPtr()); | |
| 799 if (!session_->spdy_session_pool()->StartRequest(spdy_session_key_, | |
| 800 callback)) { | |
| 801 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 802 FROM_HERE, callback, base::TimeDelta::FromMilliseconds(300)); | |
|
Bence
2017/06/09 19:17:38
Please define a file-scope const int at the top of
xunjieli
2017/06/13 15:23:10
Done.
| |
| 803 return ERR_IO_PENDING; | |
| 804 } | |
| 805 } | |
| 806 } | |
| 776 return OK; | 807 return OK; |
| 777 } | 808 } |
| 778 | 809 |
| 810 void HttpStreamFactoryImpl::Job::ResumeInitConnection() { | |
| 811 if (resumed_init_connection_) | |
|
Bence
2017/06/09 19:17:38
Under what circumstances can this be called multip
xunjieli
2017/06/13 15:23:10
Assuming there are 2 Jobs (A and B) issued at the
Bence
2017/06/13 16:04:51
Thanks for the explanation.
| |
| 812 return; | |
| 813 CHECK_EQ(next_state_, STATE_INIT_CONNECTION); | |
| 814 resumed_init_connection_ = true; | |
| 815 OnIOComplete(OK); | |
| 816 } | |
| 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 } |
| 787 | 826 |
| 788 int HttpStreamFactoryImpl::Job::DoInitConnectionImpl() { | 827 int HttpStreamFactoryImpl::Job::DoInitConnectionImpl() { |
| (...skipping 697 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 |