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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 123 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 124 if (source.IsValid()) | 124 if (source.IsValid()) |
| 125 source.AddToEventParameters(dict.get()); | 125 source.AddToEventParameters(dict.get()); |
| 126 dict->SetString("original_url", original_url->GetOrigin().spec()); | 126 dict->SetString("original_url", original_url->GetOrigin().spec()); |
| 127 dict->SetString("url", url->GetOrigin().spec()); | 127 dict->SetString("url", url->GetOrigin().spec()); |
| 128 dict->SetString("alternative_service", alternative_service->ToString()); | 128 dict->SetString("alternative_service", alternative_service->ToString()); |
| 129 dict->SetString("priority", RequestPriorityToString(priority)); | 129 dict->SetString("priority", RequestPriorityToString(priority)); |
| 130 return std::move(dict); | 130 return std::move(dict); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Returns parameters associated with the delay of the HTTP stream job. | |
| 134 std::unique_ptr<base::Value> NetLogHttpStreamJobDelayCallback( | |
| 135 base::TimeDelta delay, | |
| 136 NetLogCaptureMode /* capture_mode */) { | |
| 137 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 138 dict->SetInteger("resume_after_ms", static_cast<int>(delay.InMilliseconds())); | |
| 139 return std::move(dict); | |
| 140 } | |
| 141 | |
| 142 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP | 133 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP |
| 143 // stream. | 134 // stream. |
| 144 std::unique_ptr<base::Value> NetLogHttpStreamProtoCallback( | 135 std::unique_ptr<base::Value> NetLogHttpStreamProtoCallback( |
| 145 const SSLClientSocket::NextProtoStatus status, | 136 const SSLClientSocket::NextProtoStatus status, |
| 146 const std::string* proto, | 137 const std::string* proto, |
| 147 NetLogCaptureMode /* capture_mode */) { | 138 NetLogCaptureMode /* capture_mode */) { |
| 148 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 139 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 149 | 140 |
| 150 dict->SetString("next_proto_status", | 141 dict->SetString("next_proto_status", |
| 151 SSLClientSocket::NextProtoStatusToString(status)); | 142 SSLClientSocket::NextProtoStatusToString(status)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), | 185 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), |
| 195 connection_(new ClientSocketHandle), | 186 connection_(new ClientSocketHandle), |
| 196 session_(session), | 187 session_(session), |
| 197 next_state_(STATE_NONE), | 188 next_state_(STATE_NONE), |
| 198 pac_request_(NULL), | 189 pac_request_(NULL), |
| 199 destination_(destination), | 190 destination_(destination), |
| 200 origin_url_(origin_url), | 191 origin_url_(origin_url), |
| 201 alternative_service_(alternative_service), | 192 alternative_service_(alternative_service), |
| 202 delegate_(delegate), | 193 delegate_(delegate), |
| 203 job_type_(job_type), | 194 job_type_(job_type), |
| 204 blocking_job_(NULL), | |
| 205 waiting_job_(NULL), | |
| 206 using_ssl_(false), | 195 using_ssl_(false), |
| 207 using_spdy_(false), | 196 using_spdy_(false), |
| 208 using_quic_(false), | 197 using_quic_(false), |
| 209 quic_request_(session_->quic_stream_factory()), | 198 quic_request_(session_->quic_stream_factory()), |
| 210 using_existing_quic_session_(false), | 199 using_existing_quic_session_(false), |
| 211 spdy_certificate_error_(OK), | 200 spdy_certificate_error_(OK), |
| 212 establishing_tunnel_(false), | 201 establishing_tunnel_(false), |
| 213 was_npn_negotiated_(false), | 202 was_npn_negotiated_(false), |
| 214 protocol_negotiated_(kProtoUnknown), | 203 protocol_negotiated_(kProtoUnknown), |
| 215 num_streams_(0), | 204 num_streams_(0), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 case STATE_RESOLVE_PROXY_COMPLETE: | 270 case STATE_RESOLVE_PROXY_COMPLETE: |
| 282 return session_->proxy_service()->GetLoadState(pac_request_); | 271 return session_->proxy_service()->GetLoadState(pac_request_); |
| 283 case STATE_INIT_CONNECTION_COMPLETE: | 272 case STATE_INIT_CONNECTION_COMPLETE: |
| 284 case STATE_CREATE_STREAM_COMPLETE: | 273 case STATE_CREATE_STREAM_COMPLETE: |
| 285 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); | 274 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); |
| 286 default: | 275 default: |
| 287 return LOAD_STATE_IDLE; | 276 return LOAD_STATE_IDLE; |
| 288 } | 277 } |
| 289 } | 278 } |
| 290 | 279 |
| 291 void HttpStreamFactoryImpl::Job::WaitFor(Job* job) { | 280 void HttpStreamFactoryImpl::Job::Resume() { |
| 292 DCHECK_EQ(STATE_NONE, next_state_); | 281 DCHECK_EQ(job_type_, MAIN); |
| 293 DCHECK_EQ(STATE_NONE, job->next_state_); | 282 DCHECK_EQ(next_state_, STATE_WAIT_COMPLETE); |
| 294 DCHECK(!blocking_job_); | 283 OnIOComplete(OK); |
| 295 DCHECK(!job->waiting_job_); | |
| 296 | |
| 297 // Never share connection with other jobs for FTP requests. | |
| 298 DCHECK(!request_info_.url.SchemeIs("ftp")); | |
| 299 | |
| 300 blocking_job_ = job; | |
| 301 job->waiting_job_ = this; | |
| 302 } | |
| 303 | |
| 304 void HttpStreamFactoryImpl::Job::ResumeAfterDelay() { | |
| 305 DCHECK(!blocking_job_); | |
| 306 DCHECK_EQ(STATE_WAIT_FOR_JOB_COMPLETE, next_state_); | |
| 307 | |
| 308 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_DELAYED, | |
| 309 base::Bind(&NetLogHttpStreamJobDelayCallback, wait_time_)); | |
| 310 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 311 FROM_HERE, base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete, | |
| 312 ptr_factory_.GetWeakPtr(), OK), | |
| 313 wait_time_); | |
| 314 } | |
| 315 | |
| 316 void HttpStreamFactoryImpl::Job::Resume(Job* job, | |
| 317 const base::TimeDelta& delay) { | |
| 318 DCHECK_EQ(blocking_job_, job); | |
| 319 blocking_job_ = NULL; | |
| 320 | |
| 321 // If |this| job is not past STATE_WAIT_FOR_JOB_COMPLETE state, then it will | |
| 322 // be delayed by the |wait_time_| when it resumes. | |
| 323 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE) | |
| 324 wait_time_ = delay; | |
| 325 | |
| 326 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. | |
| 327 // Unblock |this|. | |
| 328 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) | |
| 329 ResumeAfterDelay(); | |
| 330 } | 284 } |
| 331 | 285 |
| 332 void HttpStreamFactoryImpl::Job::Orphan() { | 286 void HttpStreamFactoryImpl::Job::Orphan() { |
| 333 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); | 287 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); |
| 334 if (blocking_job_) { | 288 |
| 335 // We've been orphaned, but there's a job we're blocked on. Don't bother | 289 if (delegate_->for_websockets()) { |
| 336 // racing, just cancel ourself. | |
| 337 DCHECK(blocking_job_->waiting_job_); | |
| 338 blocking_job_->waiting_job_ = NULL; | |
| 339 blocking_job_ = NULL; | |
| 340 if (delegate_->for_websockets() && connection_ && connection_->socket()) { | |
| 341 connection_->socket()->Disconnect(); | |
| 342 } | |
| 343 delegate_->OnOrphanedJobComplete(this); | |
| 344 } else if (delegate_->for_websockets()) { | |
| 345 // We cancel this job because a WebSocketHandshakeStream can't be created | 290 // We cancel this job because a WebSocketHandshakeStream can't be created |
| 346 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in | 291 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in |
| 347 // the Request class and isn't retrievable by this job. | 292 // the Request class and isn't retrievable by this job. |
| 348 if (connection_ && connection_->socket()) { | 293 if (connection_ && connection_->socket()) { |
| 349 connection_->socket()->Disconnect(); | 294 connection_->socket()->Disconnect(); |
| 350 } | 295 } |
| 351 delegate_->OnOrphanedJobComplete(this); | 296 delegate_->OnOrphanedJobComplete(this); |
| 352 } | 297 } |
| 353 // |this| may be deleted after this call. | 298 // |this| may be deleted after this call. |
| 354 } | 299 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 } | 496 } |
| 552 | 497 |
| 553 int HttpStreamFactoryImpl::Job::RunLoop(int result) { | 498 int HttpStreamFactoryImpl::Job::RunLoop(int result) { |
| 554 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), | 499 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), |
| 555 "HttpStreamFactoryImpl::Job::RunLoop"); | 500 "HttpStreamFactoryImpl::Job::RunLoop"); |
| 556 result = DoLoop(result); | 501 result = DoLoop(result); |
| 557 | 502 |
| 558 if (result == ERR_IO_PENDING) | 503 if (result == ERR_IO_PENDING) |
| 559 return result; | 504 return result; |
| 560 | 505 |
| 561 // If there was an error, we should have already resumed the |waiting_job_|, | |
| 562 // if there was one. | |
| 563 DCHECK(result == OK || waiting_job_ == NULL); | |
| 564 | |
| 565 if (job_type_ == PRECONNECT) { | 506 if (job_type_ == PRECONNECT) { |
| 566 base::ThreadTaskRunnerHandle::Get()->PostTask( | 507 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 567 FROM_HERE, | 508 FROM_HERE, |
| 568 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, | 509 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, |
| 569 ptr_factory_.GetWeakPtr())); | 510 ptr_factory_.GetWeakPtr())); |
| 570 return ERR_IO_PENDING; | 511 return ERR_IO_PENDING; |
| 571 } | 512 } |
| 572 | 513 |
| 573 if (IsCertificateError(result)) { | 514 if (IsCertificateError(result)) { |
| 574 // Retrieve SSL information from the socket. | 515 // Retrieve SSL information from the socket. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 DCHECK_EQ(OK, rv); | 629 DCHECK_EQ(OK, rv); |
| 689 rv = DoStart(); | 630 rv = DoStart(); |
| 690 break; | 631 break; |
| 691 case STATE_RESOLVE_PROXY: | 632 case STATE_RESOLVE_PROXY: |
| 692 DCHECK_EQ(OK, rv); | 633 DCHECK_EQ(OK, rv); |
| 693 rv = DoResolveProxy(); | 634 rv = DoResolveProxy(); |
| 694 break; | 635 break; |
| 695 case STATE_RESOLVE_PROXY_COMPLETE: | 636 case STATE_RESOLVE_PROXY_COMPLETE: |
| 696 rv = DoResolveProxyComplete(rv); | 637 rv = DoResolveProxyComplete(rv); |
| 697 break; | 638 break; |
| 698 case STATE_WAIT_FOR_JOB: | 639 case STATE_WAIT: |
| 699 DCHECK_EQ(OK, rv); | 640 DCHECK_EQ(OK, rv); |
| 700 rv = DoWaitForJob(); | 641 rv = DoWait(); |
| 701 break; | 642 break; |
| 702 case STATE_WAIT_FOR_JOB_COMPLETE: | 643 case STATE_WAIT_COMPLETE: |
| 703 rv = DoWaitForJobComplete(rv); | 644 rv = DoWaitComplete(rv); |
| 704 break; | 645 break; |
| 705 case STATE_INIT_CONNECTION: | 646 case STATE_INIT_CONNECTION: |
| 706 DCHECK_EQ(OK, rv); | 647 DCHECK_EQ(OK, rv); |
| 707 rv = DoInitConnection(); | 648 rv = DoInitConnection(); |
| 708 break; | 649 break; |
| 709 case STATE_INIT_CONNECTION_COMPLETE: | 650 case STATE_INIT_CONNECTION_COMPLETE: |
| 710 rv = DoInitConnectionComplete(rv); | 651 rv = DoInitConnectionComplete(rv); |
| 711 break; | 652 break; |
| 712 case STATE_WAITING_USER_ACTION: | 653 case STATE_WAITING_USER_ACTION: |
| 713 rv = DoWaitingUserAction(rv); | 654 rv = DoWaitingUserAction(rv); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(), | 695 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(), |
| 755 &request_info_.url, &origin_url_, &alternative_service_, | 696 &request_info_.url, &origin_url_, &alternative_service_, |
| 756 priority_)); | 697 priority_)); |
| 757 net_log->AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, | 698 net_log->AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, |
| 758 net_log_.source().ToEventParametersCallback()); | 699 net_log_.source().ToEventParametersCallback()); |
| 759 } | 700 } |
| 760 | 701 |
| 761 // Don't connect to restricted ports. | 702 // Don't connect to restricted ports. |
| 762 if (!IsPortAllowedForScheme(destination_.port(), | 703 if (!IsPortAllowedForScheme(destination_.port(), |
| 763 request_info_.url.scheme())) { | 704 request_info_.url.scheme())) { |
| 764 if (waiting_job_) { | |
| 765 waiting_job_->Resume(this, base::TimeDelta()); | |
| 766 waiting_job_ = NULL; | |
| 767 } | |
| 768 return ERR_UNSAFE_PORT; | 705 return ERR_UNSAFE_PORT; |
| 769 } | 706 } |
| 770 | 707 |
| 771 next_state_ = STATE_RESOLVE_PROXY; | 708 next_state_ = STATE_RESOLVE_PROXY; |
| 772 return OK; | 709 return OK; |
| 773 } | 710 } |
| 774 | 711 |
| 775 int HttpStreamFactoryImpl::Job::DoResolveProxy() { | 712 int HttpStreamFactoryImpl::Job::DoResolveProxy() { |
| 776 DCHECK(!pac_request_); | 713 DCHECK(!pac_request_); |
| 777 DCHECK(session_); | 714 DCHECK(session_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 830 result = ERR_NO_SUPPORTED_PROXIES; | 767 result = ERR_NO_SUPPORTED_PROXIES; |
| 831 } else if (using_quic_ && | 768 } else if (using_quic_ && |
| 832 (!proxy_info_.is_quic() && !proxy_info_.is_direct())) { | 769 (!proxy_info_.is_quic() && !proxy_info_.is_direct())) { |
| 833 // QUIC can not be spoken to non-QUIC proxies. This error should not be | 770 // QUIC can not be spoken to non-QUIC proxies. This error should not be |
| 834 // user visible, because the non-alternative Job should be resumed. | 771 // user visible, because the non-alternative Job should be resumed. |
| 835 result = ERR_NO_SUPPORTED_PROXIES; | 772 result = ERR_NO_SUPPORTED_PROXIES; |
| 836 } | 773 } |
| 837 } | 774 } |
| 838 | 775 |
| 839 if (result != OK) { | 776 if (result != OK) { |
| 840 if (waiting_job_) { | |
| 841 waiting_job_->Resume(this, base::TimeDelta()); | |
| 842 waiting_job_ = NULL; | |
| 843 } | |
| 844 return result; | 777 return result; |
| 845 } | 778 } |
| 846 | 779 |
| 847 next_state_ = STATE_WAIT_FOR_JOB; | 780 next_state_ = STATE_WAIT; |
| 848 return OK; | 781 return OK; |
| 849 } | 782 } |
| 850 | 783 |
| 851 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { | 784 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { |
| 852 return session_->params().enable_quic && | 785 return session_->params().enable_quic && |
| 853 ContainsKey(session_->params().origins_to_force_quic_on, | 786 ContainsKey(session_->params().origins_to_force_quic_on, |
| 854 destination_) && | 787 destination_) && |
| 855 proxy_info_.is_direct() && origin_url_.SchemeIs("https"); | 788 proxy_info_.is_direct() && origin_url_.SchemeIs("https"); |
| 856 } | 789 } |
| 857 | 790 |
| 858 int HttpStreamFactoryImpl::Job::DoWaitForJob() { | 791 int HttpStreamFactoryImpl::Job::DoWait() { |
| 859 if (!blocking_job_ && wait_time_.is_zero()) { | 792 next_state_ = STATE_WAIT_COMPLETE; |
| 860 // There is no |blocking_job_| and there is no |wait_time_|. | 793 if (delegate_->ShouldWait(this)) |
| 861 next_state_ = STATE_INIT_CONNECTION; | 794 return ERR_IO_PENDING; |
| 862 return OK; | |
| 863 } | |
| 864 | 795 |
| 865 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; | 796 next_state_ = STATE_INIT_CONNECTION; |
|
Ryan Hamilton
2016/07/12 00:21:45
nit: It's cleaner to just remove this. Then we'll
Zhongyi Shi
2016/07/12 23:03:12
Done.
| |
| 866 if (!wait_time_.is_zero()) { | 797 return OK; |
| 867 // If there is a waiting_time, then resume the job after the wait_time_. | |
| 868 DCHECK(!blocking_job_); | |
| 869 ResumeAfterDelay(); | |
| 870 } | |
| 871 | |
| 872 return ERR_IO_PENDING; | |
| 873 } | 798 } |
| 874 | 799 |
| 875 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { | 800 int HttpStreamFactoryImpl::Job::DoWaitComplete(int result) { |
| 876 DCHECK(!blocking_job_); | |
| 877 DCHECK_EQ(OK, result); | 801 DCHECK_EQ(OK, result); |
| 878 wait_time_ = base::TimeDelta(); | |
| 879 next_state_ = STATE_INIT_CONNECTION; | 802 next_state_ = STATE_INIT_CONNECTION; |
| 880 return OK; | 803 return OK; |
| 881 } | 804 } |
| 882 | 805 |
| 883 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 806 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
| 807 int result = DoInitConnectionImpl(); | |
| 808 delegate_->OnConnectionInitialized(this, result); | |
| 809 | |
| 810 return result; | |
| 811 } | |
| 812 | |
| 813 int HttpStreamFactoryImpl::Job::DoInitConnectionImpl() { | |
| 884 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. | 814 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. |
| 885 tracked_objects::ScopedTracker tracking_profile( | 815 tracked_objects::ScopedTracker tracking_profile( |
| 886 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 816 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 887 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); | 817 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); |
| 888 DCHECK(!blocking_job_); | |
| 889 DCHECK(!connection_->is_initialized()); | 818 DCHECK(!connection_->is_initialized()); |
| 890 DCHECK(proxy_info_.proxy_server().is_valid()); | 819 DCHECK(proxy_info_.proxy_server().is_valid()); |
| 891 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 820 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
| 892 | 821 |
| 893 using_ssl_ = origin_url_.SchemeIs("https") || origin_url_.SchemeIs("wss") || | 822 using_ssl_ = origin_url_.SchemeIs("https") || origin_url_.SchemeIs("wss") || |
| 894 IsSpdyAlternative(); | 823 IsSpdyAlternative(); |
| 895 using_spdy_ = false; | 824 using_spdy_ = false; |
| 896 | 825 |
| 897 if (ShouldForceQuic()) | 826 if (ShouldForceQuic()) |
| 898 using_quic_ = true; | 827 using_quic_ = true; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 destination = destination_; | 879 destination = destination_; |
| 951 ssl_config = &server_ssl_config_; | 880 ssl_config = &server_ssl_config_; |
| 952 } | 881 } |
| 953 int rv = | 882 int rv = |
| 954 quic_request_.Request(destination, request_info_.privacy_mode, | 883 quic_request_.Request(destination, request_info_.privacy_mode, |
| 955 ssl_config->GetCertVerifyFlags(), url, | 884 ssl_config->GetCertVerifyFlags(), url, |
| 956 request_info_.method, net_log_, io_callback_); | 885 request_info_.method, net_log_, io_callback_); |
| 957 if (rv == OK) { | 886 if (rv == OK) { |
| 958 using_existing_quic_session_ = true; | 887 using_existing_quic_session_ = true; |
| 959 } else { | 888 } else { |
| 960 // OK, there's no available QUIC session. Let |waiting_job_| resume | 889 base::TimeDelta delay; |
| 961 // if it's paused. | 890 // OK, there's no available QUIC session. Let JobController to resume |
| 962 if (waiting_job_) { | 891 // the waiting job if it's paused. |
|
Ryan Hamilton
2016/07/12 00:21:44
nit: Let's tweak this comment slightly since all t
Zhongyi Shi
2016/07/12 23:03:12
Done.
| |
| 963 if (rv == ERR_IO_PENDING) { | 892 if (rv == ERR_IO_PENDING) { |
| 964 // Start the |waiting_job_| after the delay returned by | 893 // Set the wait time for main job if it is delayed TCP. |
| 965 // GetTimeDelayForWaitingJob(). | 894 delegate_->SetWaitTimeForMainJob( |
| 966 // | 895 quic_request_.GetTimeDelayForWaitingJob()); |
| 967 // If QUIC request fails during handshake, then | |
| 968 // DoInitConnectionComplete() will start the |waiting_job_|. | |
| 969 waiting_job_->Resume(this, quic_request_.GetTimeDelayForWaitingJob()); | |
| 970 } else { | |
| 971 // QUIC request has failed, resume the |waiting_job_|. | |
| 972 waiting_job_->Resume(this, base::TimeDelta()); | |
| 973 } | |
| 974 waiting_job_ = NULL; | |
| 975 } | 896 } |
| 976 } | 897 } |
| 977 return rv; | 898 return rv; |
| 978 } | 899 } |
| 979 | 900 |
| 980 SpdySessionKey spdy_session_key = GetSpdySessionKey(); | 901 SpdySessionKey spdy_session_key = GetSpdySessionKey(); |
| 981 | 902 |
| 982 // Check first if we have a spdy session for this group. If so, then go | 903 // Check first if we have a spdy session for this group. If so, then go |
| 983 // straight to using that. | 904 // straight to using that. |
| 984 if (CanUseExistingSpdySession()) { | 905 if (CanUseExistingSpdySession()) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 997 existing_spdy_session_ = spdy_session; | 918 existing_spdy_session_ = spdy_session; |
| 998 return OK; | 919 return OK; |
| 999 } | 920 } |
| 1000 } | 921 } |
| 1001 if (using_ssl_) { | 922 if (using_ssl_) { |
| 1002 // Ask |delegate_delegate_| to update the spdy session key for the request | 923 // Ask |delegate_delegate_| to update the spdy session key for the request |
| 1003 // that launched this job. | 924 // that launched this job. |
| 1004 delegate_->SetSpdySessionKey(this, spdy_session_key); | 925 delegate_->SetSpdySessionKey(this, spdy_session_key); |
| 1005 } | 926 } |
| 1006 | 927 |
| 1007 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's | |
| 1008 // paused. | |
| 1009 if (waiting_job_) { | |
| 1010 waiting_job_->Resume(this, base::TimeDelta()); | |
| 1011 waiting_job_ = NULL; | |
| 1012 } | |
| 1013 | |
| 1014 if (proxy_info_.is_http() || proxy_info_.is_https()) | 928 if (proxy_info_.is_http() || proxy_info_.is_https()) |
| 1015 establishing_tunnel_ = using_ssl_; | 929 establishing_tunnel_ = using_ssl_; |
| 1016 | 930 |
| 1017 const bool expect_spdy = IsSpdyAlternative(); | 931 const bool expect_spdy = IsSpdyAlternative(); |
| 1018 | 932 |
| 1019 base::WeakPtr<HttpServerProperties> http_server_properties = | 933 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 1020 session_->http_server_properties(); | 934 session_->http_server_properties(); |
| 1021 if (http_server_properties) { | 935 if (http_server_properties) { |
| 1022 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); | 936 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); |
| 1023 if (proxy_info_.is_http() || proxy_info_.is_https()) { | 937 if (proxy_info_.is_http() || proxy_info_.is_https()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 } | 970 } |
| 1057 | 971 |
| 1058 return InitSocketHandleForHttpRequest( | 972 return InitSocketHandleForHttpRequest( |
| 1059 GetSocketGroup(), destination_, request_info_.extra_headers, | 973 GetSocketGroup(), destination_, request_info_.extra_headers, |
| 1060 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, | 974 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, |
| 1061 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, | 975 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, |
| 1062 net_log_, connection_.get(), resolution_callback, io_callback_); | 976 net_log_, connection_.get(), resolution_callback, io_callback_); |
| 1063 } | 977 } |
| 1064 | 978 |
| 1065 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 979 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
| 1066 if (using_quic_ && result < 0 && waiting_job_) { | |
| 1067 waiting_job_->Resume(this, base::TimeDelta()); | |
| 1068 waiting_job_ = NULL; | |
| 1069 } | |
| 1070 if (job_type_ == PRECONNECT) { | 980 if (job_type_ == PRECONNECT) { |
| 1071 if (using_quic_) | 981 if (using_quic_) |
| 1072 return result; | 982 return result; |
| 1073 DCHECK_EQ(OK, result); | 983 DCHECK_EQ(OK, result); |
| 1074 return OK; | 984 return OK; |
| 1075 } | 985 } |
| 1076 | 986 |
| 1077 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { | 987 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { |
| 1078 // We found a SPDY connection after resolving the host. This is | 988 // We found a SPDY connection after resolving the host. This is |
| 1079 // probably an IP pooled connection. | 989 // probably an IP pooled connection. |
| 1080 SpdySessionKey spdy_session_key = GetSpdySessionKey(); | 990 SpdySessionKey spdy_session_key = GetSpdySessionKey(); |
| 1081 existing_spdy_session_ = | 991 existing_spdy_session_ = |
| 1082 session_->spdy_session_pool()->FindAvailableSession( | 992 session_->spdy_session_pool()->FindAvailableSession( |
| 1083 spdy_session_key, origin_url_, net_log_); | 993 spdy_session_key, origin_url_, net_log_); |
| 1084 if (existing_spdy_session_) { | 994 if (existing_spdy_session_) { |
| 1085 using_spdy_ = true; | 995 using_spdy_ = true; |
| 1086 next_state_ = STATE_CREATE_STREAM; | 996 next_state_ = STATE_CREATE_STREAM; |
| 1087 } else { | 997 } else { |
| 1088 // It is possible that the spdy session no longer exists. | 998 // It is possible that the spdy session no longer exists. |
| 1089 ReturnToStateInitConnection(true /* close connection */); | 999 ReturnToStateInitConnection(true /* close connection */); |
| 1090 } | 1000 } |
| 1091 return OK; | 1001 return OK; |
| 1092 } | 1002 } |
| 1093 | 1003 |
| 1094 if (proxy_info_.is_quic() && using_quic_) { | 1004 if (proxy_info_.is_quic() && using_quic_) { |
| 1095 // Mark QUIC proxy as bad if QUIC got disabled on the destination port. | 1005 // Mark QUIC proxy as bad if QUIC got disabled on the destination port. |
| 1096 // Underlying QUIC layer would have closed the connection. | 1006 // Underlying QUIC layer would have closed the connection. |
| 1097 HostPortPair destination = proxy_info_.proxy_server().host_port_pair(); | 1007 HostPortPair destination = proxy_info_.proxy_server().host_port_pair(); |
| 1098 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) { | 1008 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) { |
| 1099 using_quic_ = false; | 1009 using_quic_ = false; |
| 1100 return ReconsiderProxyAfterError(ERR_QUIC_PROTOCOL_ERROR); | 1010 return ReconsiderProxyAfterError(ERR_QUIC_PROTOCOL_ERROR); |
| 1101 } | 1011 } |
| 1102 } | 1012 } |
| 1103 | 1013 |
| 1104 // TODO(willchan): Make this a bit more exact. Maybe there are recoverable | |
| 1105 // errors, such as ignoring certificate errors for Alternate-Protocol. | |
| 1106 if (result < 0 && waiting_job_) { | |
| 1107 waiting_job_->Resume(this, base::TimeDelta()); | |
| 1108 waiting_job_ = NULL; | |
| 1109 } | |
| 1110 | |
| 1111 // |result| may be the result of any of the stacked pools. The following | 1014 // |result| may be the result of any of the stacked pools. The following |
| 1112 // logic is used when determining how to interpret an error. | 1015 // logic is used when determining how to interpret an error. |
| 1113 // If |result| < 0: | 1016 // If |result| < 0: |
| 1114 // and connection_->socket() != NULL, then the SSL handshake ran and it | 1017 // and connection_->socket() != NULL, then the SSL handshake ran and it |
| 1115 // is a potentially recoverable error. | 1018 // is a potentially recoverable error. |
| 1116 // and connection_->socket == NULL and connection_->is_ssl_error() is true, | 1019 // and connection_->socket == NULL and connection_->is_ssl_error() is true, |
| 1117 // then the SSL handshake ran with an unrecoverable error. | 1020 // then the SSL handshake ran with an unrecoverable error. |
| 1118 // otherwise, the error came from one of the other pools. | 1021 // otherwise, the error came from one of the other pools. |
| 1119 bool ssl_started = using_ssl_ && (result == OK || connection_->socket() || | 1022 bool ssl_started = using_ssl_ && (result == OK || connection_->socket() || |
| 1120 connection_->is_ssl_error()); | 1023 connection_->is_ssl_error()); |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1731 | 1634 |
| 1732 ConnectionAttempts socket_attempts = connection_->connection_attempts(); | 1635 ConnectionAttempts socket_attempts = connection_->connection_attempts(); |
| 1733 if (connection_->socket()) { | 1636 if (connection_->socket()) { |
| 1734 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1637 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1735 } | 1638 } |
| 1736 | 1639 |
| 1737 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); | 1640 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); |
| 1738 } | 1641 } |
| 1739 | 1642 |
| 1740 } // namespace net | 1643 } // namespace net |
| OLD | NEW |