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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 NetLogCaptureMode /* capture_mode */) { | 149 NetLogCaptureMode /* capture_mode */) { |
| 150 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 150 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 151 | 151 |
| 152 dict->SetString("next_proto_status", | 152 dict->SetString("next_proto_status", |
| 153 SSLClientSocket::NextProtoStatusToString(status)); | 153 SSLClientSocket::NextProtoStatusToString(status)); |
| 154 dict->SetString("proto", *proto); | 154 dict->SetString("proto", *proto); |
| 155 return std::move(dict); | 155 return std::move(dict); |
| 156 } | 156 } |
| 157 | 157 |
| 158 HttpStreamFactoryImpl::Job::Job(JobController* job_controller, | 158 HttpStreamFactoryImpl::Job::Job(JobController* job_controller, |
| 159 JobType job_type, | |
| 159 HttpNetworkSession* session, | 160 HttpNetworkSession* session, |
| 160 const HttpRequestInfo& request_info, | 161 const HttpRequestInfo& request_info, |
| 161 RequestPriority priority, | 162 RequestPriority priority, |
| 162 const SSLConfig& server_ssl_config, | 163 const SSLConfig& server_ssl_config, |
| 163 const SSLConfig& proxy_ssl_config, | 164 const SSLConfig& proxy_ssl_config, |
| 164 HostPortPair destination, | 165 HostPortPair destination, |
| 165 GURL origin_url, | 166 GURL origin_url, |
| 166 NetLog* net_log) | 167 NetLog* net_log) |
| 167 : Job(job_controller, | 168 : Job(job_controller, |
| 169 job_type, | |
| 168 session, | 170 session, |
| 169 request_info, | 171 request_info, |
| 170 priority, | 172 priority, |
| 171 server_ssl_config, | 173 server_ssl_config, |
| 172 proxy_ssl_config, | 174 proxy_ssl_config, |
| 173 destination, | 175 destination, |
| 174 origin_url, | 176 origin_url, |
| 175 AlternativeService(), | 177 AlternativeService(), |
| 176 net_log) {} | 178 net_log) {} |
| 177 | 179 |
| 178 HttpStreamFactoryImpl::Job::Job(JobController* job_controller, | 180 HttpStreamFactoryImpl::Job::Job(JobController* job_controller, |
| 181 JobType job_type, | |
| 179 HttpNetworkSession* session, | 182 HttpNetworkSession* session, |
| 180 const HttpRequestInfo& request_info, | 183 const HttpRequestInfo& request_info, |
| 181 RequestPriority priority, | 184 RequestPriority priority, |
| 182 const SSLConfig& server_ssl_config, | 185 const SSLConfig& server_ssl_config, |
| 183 const SSLConfig& proxy_ssl_config, | 186 const SSLConfig& proxy_ssl_config, |
| 184 HostPortPair destination, | 187 HostPortPair destination, |
| 185 GURL origin_url, | 188 GURL origin_url, |
| 186 AlternativeService alternative_service, | 189 AlternativeService alternative_service, |
| 187 NetLog* net_log) | 190 NetLog* net_log) |
| 188 : request_info_(request_info), | 191 : request_info_(request_info), |
| 189 priority_(priority), | 192 priority_(priority), |
| 190 server_ssl_config_(server_ssl_config), | 193 server_ssl_config_(server_ssl_config), |
| 191 proxy_ssl_config_(proxy_ssl_config), | 194 proxy_ssl_config_(proxy_ssl_config), |
| 192 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), | 195 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), |
| 193 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), | 196 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), |
| 194 connection_(new ClientSocketHandle), | 197 connection_(new ClientSocketHandle), |
| 195 session_(session), | 198 session_(session), |
| 196 next_state_(STATE_NONE), | 199 next_state_(STATE_NONE), |
| 197 pac_request_(NULL), | 200 pac_request_(NULL), |
| 198 destination_(destination), | 201 destination_(destination), |
| 199 origin_url_(origin_url), | 202 origin_url_(origin_url), |
| 200 alternative_service_(alternative_service), | 203 alternative_service_(alternative_service), |
| 201 job_controller_(job_controller), | 204 job_controller_(job_controller), |
| 202 blocking_job_(NULL), | 205 job_type_(job_type), |
| 203 waiting_job_(NULL), | |
| 204 orphaned_(false), | 206 orphaned_(false), |
| 205 using_ssl_(false), | 207 using_ssl_(false), |
| 206 using_spdy_(false), | 208 using_spdy_(false), |
| 207 using_quic_(false), | 209 using_quic_(false), |
| 208 quic_request_(session_->quic_stream_factory()), | 210 quic_request_(session_->quic_stream_factory()), |
| 209 using_existing_quic_session_(false), | 211 using_existing_quic_session_(false), |
| 210 spdy_certificate_error_(OK), | 212 spdy_certificate_error_(OK), |
| 211 establishing_tunnel_(false), | 213 establishing_tunnel_(false), |
| 212 was_npn_negotiated_(false), | 214 was_npn_negotiated_(false), |
| 213 protocol_negotiated_(kProtoUnknown), | 215 protocol_negotiated_(kProtoUnknown), |
| 214 num_streams_(0), | 216 num_streams_(0), |
| 215 spdy_session_direct_(false), | 217 spdy_session_direct_(false), |
| 216 job_status_(STATUS_RUNNING), | 218 job_status_(STATUS_RUNNING), |
| 217 other_job_status_(STATUS_RUNNING), | 219 other_job_status_(STATUS_RUNNING), |
| 218 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), | 220 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), |
| 219 ptr_factory_(this) { | 221 ptr_factory_(this) { |
| 220 DCHECK(session); | 222 DCHECK(session); |
| 221 if (IsQuicAlternative()) { | 223 if (IsQuicAlternative()) { |
| 222 DCHECK(session_->params().enable_quic); | 224 DCHECK(session_->params().enable_quic); |
| 223 using_quic_ = true; | 225 using_quic_ = true; |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 | 228 |
| 227 HttpStreamFactoryImpl::Job::~Job() { | 229 HttpStreamFactoryImpl::Job::~Job() { |
| 228 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB); | 230 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB); |
| 231 job_controller_->OnJobDeletion(this); | |
|
Ryan Hamilton
2016/05/06 21:33:14
The controller owns the job, right? That means the
Zhongyi Shi
2016/05/13 00:31:25
The intention was to remove references to the dele
| |
| 229 | 232 |
| 230 // When we're in a partially constructed state, waiting for the user to | 233 // When we're in a partially constructed state, waiting for the user to |
| 231 // provide certificate handling information or authentication, we can't reuse | 234 // provide certificate handling information or authentication, we can't reuse |
| 232 // this stream at all. | 235 // this stream at all. |
| 233 if (next_state_ == STATE_WAITING_USER_ACTION) { | 236 if (next_state_ == STATE_WAITING_USER_ACTION) { |
| 234 connection_->socket()->Disconnect(); | 237 connection_->socket()->Disconnect(); |
| 235 connection_.reset(); | 238 connection_.reset(); |
| 236 } | 239 } |
| 237 | 240 |
| 238 if (pac_request_) | 241 if (pac_request_) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 case STATE_RESOLVE_PROXY_COMPLETE: | 279 case STATE_RESOLVE_PROXY_COMPLETE: |
| 277 return session_->proxy_service()->GetLoadState(pac_request_); | 280 return session_->proxy_service()->GetLoadState(pac_request_); |
| 278 case STATE_INIT_CONNECTION_COMPLETE: | 281 case STATE_INIT_CONNECTION_COMPLETE: |
| 279 case STATE_CREATE_STREAM_COMPLETE: | 282 case STATE_CREATE_STREAM_COMPLETE: |
| 280 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); | 283 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); |
| 281 default: | 284 default: |
| 282 return LOAD_STATE_IDLE; | 285 return LOAD_STATE_IDLE; |
| 283 } | 286 } |
| 284 } | 287 } |
| 285 | 288 |
| 286 void HttpStreamFactoryImpl::Job::WaitFor(Job* job) { | |
| 287 DCHECK_EQ(STATE_NONE, next_state_); | |
| 288 DCHECK_EQ(STATE_NONE, job->next_state_); | |
| 289 DCHECK(!blocking_job_); | |
| 290 DCHECK(!job->waiting_job_); | |
| 291 | |
| 292 // Never share connection with other jobs for FTP requests. | |
| 293 DCHECK(!request_info_.url.SchemeIs("ftp")); | |
| 294 | |
| 295 blocking_job_ = job; | |
| 296 job->waiting_job_ = this; | |
| 297 } | |
| 298 | |
| 299 void HttpStreamFactoryImpl::Job::ResumeAfterDelay() { | 289 void HttpStreamFactoryImpl::Job::ResumeAfterDelay() { |
| 300 DCHECK(!blocking_job_); | 290 DCHECK((job_type_ == ALTERNATIVE || !job_controller_->racing())); |
| 301 DCHECK_EQ(STATE_WAIT_FOR_JOB_COMPLETE, next_state_); | 291 DCHECK_EQ(STATE_WAIT_FOR_JOB_COMPLETE, next_state_); |
| 302 | 292 |
| 303 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_DELAYED, | 293 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_DELAYED, |
| 304 base::Bind(&NetLogHttpStreamJobDelayCallback, wait_time_)); | 294 base::Bind(&NetLogHttpStreamJobDelayCallback, wait_time_)); |
| 305 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 295 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 306 FROM_HERE, base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete, | 296 FROM_HERE, base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete, |
| 307 ptr_factory_.GetWeakPtr(), OK), | 297 ptr_factory_.GetWeakPtr(), OK), |
| 308 wait_time_); | 298 wait_time_); |
| 309 } | 299 } |
| 310 | 300 |
| 311 void HttpStreamFactoryImpl::Job::Resume(Job* job, | 301 void HttpStreamFactoryImpl::Job::Resume(const base::TimeDelta& delay) { |
| 312 const base::TimeDelta& delay) { | |
| 313 DCHECK_EQ(blocking_job_, job); | |
| 314 blocking_job_ = NULL; | |
| 315 | |
| 316 // If |this| job is not past STATE_WAIT_FOR_JOB_COMPLETE state, then it will | 302 // If |this| job is not past STATE_WAIT_FOR_JOB_COMPLETE state, then it will |
| 317 // be delayed by the |wait_time_| when it resumes. | 303 // be delayed by the |wait_time_| when it resumes. |
| 318 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE) | 304 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE) |
| 319 wait_time_ = delay; | 305 wait_time_ = delay; |
| 320 | 306 |
| 321 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. | 307 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. |
| 322 // Unblock |this|. | 308 // Unblock |this|. |
| 323 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) | 309 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) |
| 324 ResumeAfterDelay(); | 310 ResumeAfterDelay(); |
| 325 } | 311 } |
| 326 | 312 |
| 327 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { | 313 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { |
| 328 DCHECK(!orphaned_); | 314 DCHECK(!orphaned_); |
| 329 if (!IsPreconnecting()) | 315 if (!IsPreconnecting()) |
| 330 orphaned_ = true; | 316 orphaned_ = true; |
| 331 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); | 317 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); |
| 332 if (blocking_job_) { | 318 |
| 333 // We've been orphaned, but there's a job we're blocked on. Don't bother | 319 job_controller_->MaybeResumeOtherJob(this, base::TimeDelta()); |
| 334 // racing, just cancel ourself. | 320 if (job_controller_->for_websockets()) { |
| 335 DCHECK(blocking_job_->waiting_job_); | |
| 336 blocking_job_->waiting_job_ = NULL; | |
| 337 blocking_job_ = NULL; | |
| 338 if (job_controller_->for_websockets() && connection_ && | |
| 339 connection_->socket()) { | |
| 340 connection_->socket()->Disconnect(); | |
| 341 } | |
| 342 job_controller_->OnOrphanedJobComplete(this); | |
| 343 } else if (job_controller_->for_websockets()) { | |
| 344 // We cancel this job because a WebSocketHandshakeStream can't be created | 321 // We cancel this job because a WebSocketHandshakeStream can't be created |
| 345 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in | 322 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in |
| 346 // the Request class and isn't accessible from this job. | 323 // the Request class and isn't accessible from this job. |
| 347 if (connection_ && connection_->socket()) { | 324 if (connection_ && connection_->socket()) { |
| 348 connection_->socket()->Disconnect(); | 325 connection_->socket()->Disconnect(); |
| 349 } | 326 } |
| 350 job_controller_->OnOrphanedJobComplete(this); | 327 job_controller_->OnOrphanedJobComplete(this); |
| 351 } | 328 } |
| 352 } | 329 } |
| 353 | 330 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 } | 580 } |
| 604 | 581 |
| 605 int HttpStreamFactoryImpl::Job::RunLoop(int result) { | 582 int HttpStreamFactoryImpl::Job::RunLoop(int result) { |
| 606 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), | 583 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), |
| 607 "HttpStreamFactoryImpl::Job::RunLoop"); | 584 "HttpStreamFactoryImpl::Job::RunLoop"); |
| 608 result = DoLoop(result); | 585 result = DoLoop(result); |
| 609 | 586 |
| 610 if (result == ERR_IO_PENDING) | 587 if (result == ERR_IO_PENDING) |
| 611 return result; | 588 return result; |
| 612 | 589 |
| 613 // If there was an error, we should have already resumed the |waiting_job_|, | 590 // If there was an error, we should have already resumed the other waiting |
| 614 // if there was one. | 591 // job, if there was one. |
| 615 DCHECK(result == OK || waiting_job_ == NULL); | 592 DCHECK(result == OK || job_type_ == NON_ALTERNATIVE || |
| 593 !job_controller_->racing()); | |
| 616 | 594 |
| 617 if (IsPreconnecting()) { | 595 if (IsPreconnecting()) { |
| 618 base::ThreadTaskRunnerHandle::Get()->PostTask( | 596 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 619 FROM_HERE, | 597 FROM_HERE, |
| 620 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, | 598 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, |
| 621 ptr_factory_.GetWeakPtr())); | 599 ptr_factory_.GetWeakPtr())); |
| 622 return ERR_IO_PENDING; | 600 return ERR_IO_PENDING; |
| 623 } | 601 } |
| 624 | 602 |
| 625 if (IsCertificateError(result)) { | 603 if (IsCertificateError(result)) { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 priority_)); | 787 priority_)); |
| 810 if (!IsPreconnecting() && !orphaned_) { | 788 if (!IsPreconnecting() && !orphaned_) { |
| 811 job_controller_->GetNetLogFromRequest().AddEvent( | 789 job_controller_->GetNetLogFromRequest().AddEvent( |
| 812 NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, | 790 NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, |
| 813 net_log_.source().ToEventParametersCallback()); | 791 net_log_.source().ToEventParametersCallback()); |
| 814 } | 792 } |
| 815 | 793 |
| 816 // Don't connect to restricted ports. | 794 // Don't connect to restricted ports. |
| 817 if (!IsPortAllowedForScheme(destination_.port(), | 795 if (!IsPortAllowedForScheme(destination_.port(), |
| 818 request_info_.url.scheme())) { | 796 request_info_.url.scheme())) { |
| 819 if (waiting_job_) { | 797 job_controller_->MaybeResumeOtherJob(this, base::TimeDelta()); |
| 820 waiting_job_->Resume(this, base::TimeDelta()); | |
| 821 waiting_job_ = NULL; | |
| 822 } | |
| 823 return ERR_UNSAFE_PORT; | 798 return ERR_UNSAFE_PORT; |
| 824 } | 799 } |
| 825 | 800 |
| 826 next_state_ = STATE_RESOLVE_PROXY; | 801 next_state_ = STATE_RESOLVE_PROXY; |
| 827 return OK; | 802 return OK; |
| 828 } | 803 } |
| 829 | 804 |
| 830 int HttpStreamFactoryImpl::Job::DoResolveProxy() { | 805 int HttpStreamFactoryImpl::Job::DoResolveProxy() { |
| 831 DCHECK(!pac_request_); | 806 DCHECK(!pac_request_); |
| 832 DCHECK(session_); | 807 DCHECK(session_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 885 result = ERR_NO_SUPPORTED_PROXIES; | 860 result = ERR_NO_SUPPORTED_PROXIES; |
| 886 } else if (using_quic_ && | 861 } else if (using_quic_ && |
| 887 (!proxy_info_.is_quic() && !proxy_info_.is_direct())) { | 862 (!proxy_info_.is_quic() && !proxy_info_.is_direct())) { |
| 888 // QUIC can not be spoken to non-QUIC proxies. This error should not be | 863 // QUIC can not be spoken to non-QUIC proxies. This error should not be |
| 889 // user visible, because the non-alternative Job should be resumed. | 864 // user visible, because the non-alternative Job should be resumed. |
| 890 result = ERR_NO_SUPPORTED_PROXIES; | 865 result = ERR_NO_SUPPORTED_PROXIES; |
| 891 } | 866 } |
| 892 } | 867 } |
| 893 | 868 |
| 894 if (result != OK) { | 869 if (result != OK) { |
| 895 if (waiting_job_) { | 870 job_controller_->MaybeResumeOtherJob(this, base::TimeDelta()); |
| 896 waiting_job_->Resume(this, base::TimeDelta()); | |
| 897 waiting_job_ = NULL; | |
| 898 } | |
| 899 return result; | 871 return result; |
| 900 } | 872 } |
| 901 | 873 |
| 902 next_state_ = STATE_WAIT_FOR_JOB; | 874 next_state_ = STATE_WAIT_FOR_JOB; |
| 903 return OK; | 875 return OK; |
| 904 } | 876 } |
| 905 | 877 |
| 906 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { | 878 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { |
| 907 return session_->params().enable_quic && | 879 return session_->params().enable_quic && |
| 908 ContainsKey(session_->params().origins_to_force_quic_on, | 880 ContainsKey(session_->params().origins_to_force_quic_on, |
| 909 destination_) && | 881 destination_) && |
| 910 proxy_info_.is_direct() && origin_url_.SchemeIs("https"); | 882 proxy_info_.is_direct() && origin_url_.SchemeIs("https"); |
| 911 } | 883 } |
| 912 | 884 |
| 913 int HttpStreamFactoryImpl::Job::DoWaitForJob() { | 885 int HttpStreamFactoryImpl::Job::DoWaitForJob() { |
| 914 if (!blocking_job_ && wait_time_.is_zero()) { | 886 if ((job_type_ == ALTERNATIVE || !job_controller_->racing()) && |
| 915 // There is no |blocking_job_| and there is no |wait_time_|. | 887 wait_time_.is_zero()) { |
| 888 // There is no blocking job and there is no |wait_time_|. | |
| 916 next_state_ = STATE_INIT_CONNECTION; | 889 next_state_ = STATE_INIT_CONNECTION; |
| 917 return OK; | 890 return OK; |
| 918 } | 891 } |
| 919 | 892 |
| 920 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; | 893 next_state_ = STATE_WAIT_FOR_JOB_COMPLETE; |
| 921 if (!wait_time_.is_zero()) { | 894 if (!wait_time_.is_zero()) { |
| 922 // If there is a waiting_time, then resume the job after the wait_time_. | 895 // If there is a waiting_time, then resume the job after the wait_time_. |
| 923 DCHECK(!blocking_job_); | 896 DCHECK((job_type_ == ALTERNATIVE || !job_controller_->racing())); |
|
Ryan Hamilton
2016/05/06 21:33:14
it's not clear to me why the job needs to perform
Zhongyi Shi
2016/05/13 00:31:24
Moved to JobController!
| |
| 924 ResumeAfterDelay(); | 897 ResumeAfterDelay(); |
| 925 } | 898 } |
| 926 | 899 |
| 927 return ERR_IO_PENDING; | 900 return ERR_IO_PENDING; |
| 928 } | 901 } |
| 929 | 902 |
| 930 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { | 903 int HttpStreamFactoryImpl::Job::DoWaitForJobComplete(int result) { |
| 931 DCHECK(!blocking_job_); | 904 DCHECK((job_type_ == ALTERNATIVE || !job_controller_->racing())); |
| 932 DCHECK_EQ(OK, result); | 905 DCHECK_EQ(OK, result); |
| 933 wait_time_ = base::TimeDelta(); | 906 wait_time_ = base::TimeDelta(); |
| 934 next_state_ = STATE_INIT_CONNECTION; | 907 next_state_ = STATE_INIT_CONNECTION; |
| 935 return OK; | 908 return OK; |
| 936 } | 909 } |
| 937 | 910 |
| 938 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 911 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
| 939 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. | 912 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. |
| 940 tracked_objects::ScopedTracker tracking_profile( | 913 tracked_objects::ScopedTracker tracking_profile( |
| 941 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 914 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 942 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); | 915 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); |
| 943 DCHECK(!blocking_job_); | 916 DCHECK((job_type_ == ALTERNATIVE || !job_controller_->racing())); |
| 944 DCHECK(!connection_->is_initialized()); | 917 DCHECK(!connection_->is_initialized()); |
| 945 DCHECK(proxy_info_.proxy_server().is_valid()); | 918 DCHECK(proxy_info_.proxy_server().is_valid()); |
| 946 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 919 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
| 947 | 920 |
| 948 using_ssl_ = origin_url_.SchemeIs("https") || origin_url_.SchemeIs("wss") || | 921 using_ssl_ = origin_url_.SchemeIs("https") || origin_url_.SchemeIs("wss") || |
| 949 IsSpdyAlternative(); | 922 IsSpdyAlternative(); |
| 950 using_spdy_ = false; | 923 using_spdy_ = false; |
| 951 | 924 |
| 952 if (ShouldForceQuic()) | 925 if (ShouldForceQuic()) |
| 953 using_quic_ = true; | 926 using_quic_ = true; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 destination = destination_; | 978 destination = destination_; |
| 1006 ssl_config = &server_ssl_config_; | 979 ssl_config = &server_ssl_config_; |
| 1007 } | 980 } |
| 1008 int rv = | 981 int rv = |
| 1009 quic_request_.Request(destination, request_info_.privacy_mode, | 982 quic_request_.Request(destination, request_info_.privacy_mode, |
| 1010 ssl_config->GetCertVerifyFlags(), url, | 983 ssl_config->GetCertVerifyFlags(), url, |
| 1011 request_info_.method, net_log_, io_callback_); | 984 request_info_.method, net_log_, io_callback_); |
| 1012 if (rv == OK) { | 985 if (rv == OK) { |
| 1013 using_existing_quic_session_ = true; | 986 using_existing_quic_session_ = true; |
| 1014 } else { | 987 } else { |
| 1015 // OK, there's no available QUIC session. Let |waiting_job_| resume | 988 base::TimeDelta delay = base::TimeDelta(); |
|
Ryan Hamilton
2016/05/06 21:33:14
nit: I think you can remove the = ...;
Zhongyi Shi
2016/05/13 00:31:24
Done.
| |
| 1016 // if it's paused. | 989 // OK, there's no available QUIC session. Let JobController to resume |
| 1017 if (waiting_job_) { | 990 // the waiting job if it's paused. |
| 1018 if (rv == ERR_IO_PENDING) { | 991 if (rv == ERR_IO_PENDING) { |
| 1019 // Start the |waiting_job_| after the delay returned by | 992 // Start the waiting job after the delay returned by |
| 1020 // GetTimeDelayForWaitingJob(). | 993 // GetTimeDelayForWaitingJob(). |
| 1021 // | 994 // |
| 1022 // If QUIC request fails during handshake, then | 995 // If QUIC request fails during handshake, then |
| 1023 // DoInitConnectionComplete() will start the |waiting_job_|. | 996 // DoInitConnectionComplete() will start the waiting job. |
| 1024 waiting_job_->Resume(this, quic_request_.GetTimeDelayForWaitingJob()); | 997 delay = quic_request_.GetTimeDelayForWaitingJob(); |
| 1025 } else { | |
| 1026 // QUIC request has failed, resume the |waiting_job_|. | |
| 1027 waiting_job_->Resume(this, base::TimeDelta()); | |
| 1028 } | |
| 1029 waiting_job_ = NULL; | |
| 1030 } | 998 } |
| 999 job_controller_->MaybeResumeOtherJob(this, delay); | |
| 1031 } | 1000 } |
| 1032 return rv; | 1001 return rv; |
| 1033 } | 1002 } |
| 1034 | 1003 |
| 1035 SpdySessionKey spdy_session_key = GetSpdySessionKey(); | 1004 SpdySessionKey spdy_session_key = GetSpdySessionKey(); |
| 1036 | 1005 |
| 1037 // Check first if we have a spdy session for this group. If so, then go | 1006 // Check first if we have a spdy session for this group. If so, then go |
| 1038 // straight to using that. | 1007 // straight to using that. |
| 1039 if (CanUseExistingSpdySession()) { | 1008 if (CanUseExistingSpdySession()) { |
| 1040 base::WeakPtr<SpdySession> spdy_session; | 1009 base::WeakPtr<SpdySession> spdy_session; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1052 existing_spdy_session_ = spdy_session; | 1021 existing_spdy_session_ = spdy_session; |
| 1053 return OK; | 1022 return OK; |
| 1054 } | 1023 } |
| 1055 } | 1024 } |
| 1056 if (!IsPreconnecting() && !orphaned_ && using_ssl_) { | 1025 if (!IsPreconnecting() && !orphaned_ && using_ssl_) { |
| 1057 // Ask |job_controller_| to update the spdy session key for the request | 1026 // Ask |job_controller_| to update the spdy session key for the request |
| 1058 // that launched this job. | 1027 // that launched this job. |
| 1059 job_controller_->SetSpdySessionKey(spdy_session_key); | 1028 job_controller_->SetSpdySessionKey(spdy_session_key); |
| 1060 } | 1029 } |
| 1061 | 1030 |
| 1062 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's | 1031 // OK, there's no available SPDY session. Let JobController to resume the |
| 1063 // paused. | 1032 // non-alternative job if it's paused. |
| 1064 if (waiting_job_) { | 1033 job_controller_->MaybeResumeOtherJob(this, base::TimeDelta()); |
| 1065 waiting_job_->Resume(this, base::TimeDelta()); | |
| 1066 waiting_job_ = NULL; | |
| 1067 } | |
| 1068 | 1034 |
| 1069 if (proxy_info_.is_http() || proxy_info_.is_https()) | 1035 if (proxy_info_.is_http() || proxy_info_.is_https()) |
| 1070 establishing_tunnel_ = using_ssl_; | 1036 establishing_tunnel_ = using_ssl_; |
| 1071 | 1037 |
| 1072 const bool expect_spdy = IsSpdyAlternative(); | 1038 const bool expect_spdy = IsSpdyAlternative(); |
| 1073 | 1039 |
| 1074 base::WeakPtr<HttpServerProperties> http_server_properties = | 1040 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 1075 session_->http_server_properties(); | 1041 session_->http_server_properties(); |
| 1076 if (http_server_properties) { | 1042 if (http_server_properties) { |
| 1077 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); | 1043 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 } | 1077 } |
| 1112 | 1078 |
| 1113 return InitSocketHandleForHttpRequest( | 1079 return InitSocketHandleForHttpRequest( |
| 1114 GetSocketGroup(), destination_, request_info_.extra_headers, | 1080 GetSocketGroup(), destination_, request_info_.extra_headers, |
| 1115 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, | 1081 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, |
| 1116 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, | 1082 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, |
| 1117 net_log_, connection_.get(), resolution_callback, io_callback_); | 1083 net_log_, connection_.get(), resolution_callback, io_callback_); |
| 1118 } | 1084 } |
| 1119 | 1085 |
| 1120 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 1086 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
| 1121 if (using_quic_ && result < 0 && waiting_job_) { | 1087 if (using_quic_ && result < 0) { |
| 1122 waiting_job_->Resume(this, base::TimeDelta()); | 1088 job_controller_->MaybeResumeOtherJob(this, base::TimeDelta()); |
| 1123 waiting_job_ = NULL; | |
| 1124 } | 1089 } |
| 1125 if (IsPreconnecting()) { | 1090 if (IsPreconnecting()) { |
| 1126 if (using_quic_) | 1091 if (using_quic_) |
| 1127 return result; | 1092 return result; |
| 1128 DCHECK_EQ(OK, result); | 1093 DCHECK_EQ(OK, result); |
| 1129 return OK; | 1094 return OK; |
| 1130 } | 1095 } |
| 1131 | 1096 |
| 1132 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { | 1097 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { |
| 1133 // We found a SPDY connection after resolving the host. This is | 1098 // We found a SPDY connection after resolving the host. This is |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1151 // Underlying QUIC layer would have closed the connection. | 1116 // Underlying QUIC layer would have closed the connection. |
| 1152 HostPortPair destination = proxy_info_.proxy_server().host_port_pair(); | 1117 HostPortPair destination = proxy_info_.proxy_server().host_port_pair(); |
| 1153 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) { | 1118 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) { |
| 1154 using_quic_ = false; | 1119 using_quic_ = false; |
| 1155 return ReconsiderProxyAfterError(ERR_QUIC_PROTOCOL_ERROR); | 1120 return ReconsiderProxyAfterError(ERR_QUIC_PROTOCOL_ERROR); |
| 1156 } | 1121 } |
| 1157 } | 1122 } |
| 1158 | 1123 |
| 1159 // TODO(willchan): Make this a bit more exact. Maybe there are recoverable | 1124 // TODO(willchan): Make this a bit more exact. Maybe there are recoverable |
| 1160 // errors, such as ignoring certificate errors for Alternate-Protocol. | 1125 // errors, such as ignoring certificate errors for Alternate-Protocol. |
| 1161 if (result < 0 && waiting_job_) { | 1126 if (result < 0) { |
| 1162 waiting_job_->Resume(this, base::TimeDelta()); | 1127 job_controller_->MaybeResumeOtherJob(this, base::TimeDelta()); |
| 1163 waiting_job_ = NULL; | |
| 1164 } | 1128 } |
| 1165 | 1129 |
| 1166 // |result| may be the result of any of the stacked pools. The following | 1130 // |result| may be the result of any of the stacked pools. The following |
| 1167 // logic is used when determining how to interpret an error. | 1131 // logic is used when determining how to interpret an error. |
| 1168 // If |result| < 0: | 1132 // If |result| < 0: |
| 1169 // and connection_->socket() != NULL, then the SSL handshake ran and it | 1133 // and connection_->socket() != NULL, then the SSL handshake ran and it |
| 1170 // is a potentially recoverable error. | 1134 // is a potentially recoverable error. |
| 1171 // and connection_->socket == NULL and connection_->is_ssl_error() is true, | 1135 // and connection_->socket == NULL and connection_->is_ssl_error() is true, |
| 1172 // then the SSL handshake ran with an unrecoverable error. | 1136 // then the SSL handshake ran with an unrecoverable error. |
| 1173 // otherwise, the error came from one of the other pools. | 1137 // otherwise, the error came from one of the other pools. |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1805 ConnectionAttempts socket_attempts; | 1769 ConnectionAttempts socket_attempts; |
| 1806 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1770 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1807 job_controller_->AddConnectionAttemptsToRequest(socket_attempts); | 1771 job_controller_->AddConnectionAttemptsToRequest(socket_attempts); |
| 1808 } else { | 1772 } else { |
| 1809 job_controller_->AddConnectionAttemptsToRequest( | 1773 job_controller_->AddConnectionAttemptsToRequest( |
| 1810 connection_->connection_attempts()); | 1774 connection_->connection_attempts()); |
| 1811 } | 1775 } |
| 1812 } | 1776 } |
| 1813 | 1777 |
| 1814 } // namespace net | 1778 } // namespace net |
| OLD | NEW |