Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 : alternative_job_->GetLoadState(); | 138 : alternative_job_->GetLoadState(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void HttpStreamFactoryImpl::JobController::OnRequestComplete() { | 141 void HttpStreamFactoryImpl::JobController::OnRequestComplete() { |
| 142 CancelJobs(); | 142 CancelJobs(); |
| 143 DCHECK(request_); | 143 DCHECK(request_); |
| 144 request_ = nullptr; | 144 request_ = nullptr; |
| 145 if (bound_job_) { | 145 if (bound_job_) { |
| 146 if (bound_job_->job_type() == MAIN) { | 146 if (bound_job_->job_type() == MAIN) { |
| 147 main_job_.reset(); | 147 main_job_.reset(); |
| 148 // |alternative_job_| can be non-null if |main_job_| is resumed after | |
| 149 // |main_job_wait_time_| has elapsed. | |
| 150 // Do not reset |alternative_job_| here and let it run for completion. | |
| 151 // OnOrphanedJobComplete() will clean up |this| when the job completes. | |
| 148 } else { | 152 } else { |
| 149 DCHECK(bound_job_->job_type() == ALTERNATIVE); | 153 DCHECK(bound_job_->job_type() == ALTERNATIVE); |
| 150 alternative_job_.reset(); | 154 alternative_job_.reset(); |
| 155 // If |main_job_| hasn't started connecting, reset it. Otherwise, | |
| 156 // OnOrphanedJobComplete() will clean up |this| when the job completes. | |
| 157 // Use |main_job_is_blocked_| instead of |main_job_|->is_waiting() because | |
| 158 // |main_job_| can be in proxy resolution step. | |
| 159 if (main_job_ && main_job_is_blocked_) | |
|
mmenke
2017/01/09 18:37:20
Should this be:
if (main_job_ && (main_job_is_blo
xunjieli
2017/01/09 18:52:31
In HttpStreamFactoryImpl::Job::DoInitConnectionImp
mmenke
2017/01/09 18:56:19
It's not the same thing. We set main_job_is_block
xunjieli
2017/01/09 19:18:21
Done. Got it, Thanks!
Zhongyi Shi
2017/01/09 20:09:45
Umm, main_job_wait_time is only used to figure out
mmenke
2017/01/09 20:12:27
That strikes me as unexpected - why are we delayin
Zhongyi Shi
2017/01/09 23:18:49
We are delaying the tcp job because we want to giv
mmenke
2017/01/09 23:25:12
So what is fundamentally different between cases w
Zhongyi Shi
2017/01/09 23:39:46
My understanding is: if we've started the timer, t
Zhongyi Shi
2017/01/10 01:11:32
Looks like both jobs and request will be reset her
| |
| 160 main_job_.reset(); | |
| 151 } | 161 } |
| 152 bound_job_ = nullptr; | 162 bound_job_ = nullptr; |
| 153 } | 163 } |
| 154 MaybeNotifyFactoryOfCompletion(); | 164 MaybeNotifyFactoryOfCompletion(); |
| 155 } | 165 } |
| 156 | 166 |
| 157 int HttpStreamFactoryImpl::JobController::RestartTunnelWithProxyAuth( | 167 int HttpStreamFactoryImpl::JobController::RestartTunnelWithProxyAuth( |
| 158 const AuthCredentials& credentials) { | 168 const AuthCredentials& credentials) { |
| 159 DCHECK(bound_job_); | 169 DCHECK(bound_job_); |
| 160 return bound_job_->RestartTunnelWithProxyAuth(credentials); | 170 return bound_job_->RestartTunnelWithProxyAuth(credentials); |
| 161 } | 171 } |
| 162 | 172 |
| 163 void HttpStreamFactoryImpl::JobController::SetPriority( | 173 void HttpStreamFactoryImpl::JobController::SetPriority( |
| 164 RequestPriority priority) { | 174 RequestPriority priority) { |
| 165 if (main_job_) { | 175 if (main_job_) { |
| 166 main_job_->SetPriority(priority); | 176 main_job_->SetPriority(priority); |
| 167 } | 177 } |
| 168 if (alternative_job_) { | 178 if (alternative_job_) { |
| 169 alternative_job_->SetPriority(priority); | 179 alternative_job_->SetPriority(priority); |
| 170 } | 180 } |
| 171 } | 181 } |
| 172 | 182 |
| 173 void HttpStreamFactoryImpl::JobController::OnStreamReady( | 183 void HttpStreamFactoryImpl::JobController::OnStreamReady( |
| 174 Job* job, | 184 Job* job, |
| 175 const SSLConfig& used_ssl_config) { | 185 const SSLConfig& used_ssl_config) { |
| 176 DCHECK(job); | 186 DCHECK(job); |
| 177 | 187 |
| 178 factory_->OnStreamReady(job->proxy_info()); | 188 factory_->OnStreamReady(job->proxy_info()); |
| 179 | 189 |
| 180 if (job_bound_ && bound_job_ != job) { | 190 if (!request_ || (job_bound_ && bound_job_ != job)) { |
| 181 // We have bound a job to the associated Request, |job| has been orphaned. | 191 // We have bound a job to the associated Request, |job| has been orphaned. |
| 182 OnOrphanedJobComplete(job); | 192 OnOrphanedJobComplete(job); |
| 183 return; | 193 return; |
| 184 } | 194 } |
| 185 std::unique_ptr<HttpStream> stream = job->ReleaseStream(); | 195 std::unique_ptr<HttpStream> stream = job->ReleaseStream(); |
| 186 DCHECK(stream); | 196 DCHECK(stream); |
| 187 | 197 |
| 188 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), | 198 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), |
| 189 job->using_spdy()); | 199 job->using_spdy()); |
| 190 | 200 |
| 191 if (!request_) | 201 if (!request_) |
| 192 return; | 202 return; |
| 193 DCHECK(!factory_->for_websockets_); | 203 DCHECK(!factory_->for_websockets_); |
| 194 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type()); | 204 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type()); |
| 195 OnJobSucceeded(job); | 205 OnJobSucceeded(job); |
| 196 request_->OnStreamReady(used_ssl_config, job->proxy_info(), stream.release()); | 206 request_->OnStreamReady(used_ssl_config, job->proxy_info(), stream.release()); |
| 197 } | 207 } |
| 198 | 208 |
| 199 void HttpStreamFactoryImpl::JobController::OnBidirectionalStreamImplReady( | 209 void HttpStreamFactoryImpl::JobController::OnBidirectionalStreamImplReady( |
| 200 Job* job, | 210 Job* job, |
| 201 const SSLConfig& used_ssl_config, | 211 const SSLConfig& used_ssl_config, |
| 202 const ProxyInfo& used_proxy_info) { | 212 const ProxyInfo& used_proxy_info) { |
| 203 DCHECK(job); | 213 DCHECK(job); |
| 204 | 214 |
| 205 if (job_bound_ && bound_job_ != job) { | 215 if (!request_ || (job_bound_ && bound_job_ != job)) { |
| 206 // We have bound a job to the associated Request, |job| has been orphaned. | 216 // We have bound a job to the associated Request, |job| has been orphaned. |
| 207 OnOrphanedJobComplete(job); | 217 OnOrphanedJobComplete(job); |
| 208 return; | 218 return; |
| 209 } | 219 } |
| 210 | 220 |
| 211 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), | 221 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), |
| 212 job->using_spdy()); | 222 job->using_spdy()); |
| 213 | 223 |
| 214 if (!request_) | 224 if (!request_) |
| 215 return; | 225 return; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 246 | 256 |
| 247 void HttpStreamFactoryImpl::JobController::OnStreamFailed( | 257 void HttpStreamFactoryImpl::JobController::OnStreamFailed( |
| 248 Job* job, | 258 Job* job, |
| 249 int status, | 259 int status, |
| 250 const SSLConfig& used_ssl_config) { | 260 const SSLConfig& used_ssl_config) { |
| 251 if (job->job_type() == ALTERNATIVE) | 261 if (job->job_type() == ALTERNATIVE) |
| 252 OnAlternativeJobFailed(job); | 262 OnAlternativeJobFailed(job); |
| 253 | 263 |
| 254 MaybeResumeMainJob(job, base::TimeDelta()); | 264 MaybeResumeMainJob(job, base::TimeDelta()); |
| 255 | 265 |
| 256 if (job_bound_ && bound_job_ != job) { | 266 if (!request_ || (job_bound_ && bound_job_ != job)) { |
| 257 // We have bound a job to the associated Request, |job| has been orphaned. | 267 // We have bound a job to the associated Request, |job| has been orphaned. |
| 258 OnOrphanedJobComplete(job); | 268 OnOrphanedJobComplete(job); |
| 259 return; | 269 return; |
| 260 } | 270 } |
| 261 | 271 |
| 262 if (!request_) | 272 if (!request_) |
| 263 return; | 273 return; |
| 264 DCHECK_NE(OK, status); | 274 DCHECK_NE(OK, status); |
| 265 DCHECK(job); | 275 DCHECK(job); |
| 266 | 276 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 284 request_->OnStreamFailed(status, used_ssl_config); | 294 request_->OnStreamFailed(status, used_ssl_config); |
| 285 } | 295 } |
| 286 | 296 |
| 287 void HttpStreamFactoryImpl::JobController::OnCertificateError( | 297 void HttpStreamFactoryImpl::JobController::OnCertificateError( |
| 288 Job* job, | 298 Job* job, |
| 289 int status, | 299 int status, |
| 290 const SSLConfig& used_ssl_config, | 300 const SSLConfig& used_ssl_config, |
| 291 const SSLInfo& ssl_info) { | 301 const SSLInfo& ssl_info) { |
| 292 MaybeResumeMainJob(job, base::TimeDelta()); | 302 MaybeResumeMainJob(job, base::TimeDelta()); |
| 293 | 303 |
| 294 if (job_bound_ && bound_job_ != job) { | 304 if (!request_ || (job_bound_ && bound_job_ != job)) { |
| 295 // We have bound a job to the associated Request, |job| has been orphaned. | 305 // We have bound a job to the associated Request, |job| has been orphaned. |
| 296 OnOrphanedJobComplete(job); | 306 OnOrphanedJobComplete(job); |
| 297 return; | 307 return; |
| 298 } | 308 } |
| 299 | 309 |
| 300 if (!request_) | 310 if (!request_) |
| 301 return; | 311 return; |
| 302 DCHECK_NE(OK, status); | 312 DCHECK_NE(OK, status); |
| 303 if (!bound_job_) | 313 if (!bound_job_) |
| 304 BindJob(job); | 314 BindJob(job); |
| 305 | 315 |
| 306 request_->OnCertificateError(status, used_ssl_config, ssl_info); | 316 request_->OnCertificateError(status, used_ssl_config, ssl_info); |
| 307 } | 317 } |
| 308 | 318 |
| 309 void HttpStreamFactoryImpl::JobController::OnHttpsProxyTunnelResponse( | 319 void HttpStreamFactoryImpl::JobController::OnHttpsProxyTunnelResponse( |
| 310 Job* job, | 320 Job* job, |
| 311 const HttpResponseInfo& response_info, | 321 const HttpResponseInfo& response_info, |
| 312 const SSLConfig& used_ssl_config, | 322 const SSLConfig& used_ssl_config, |
| 313 const ProxyInfo& used_proxy_info, | 323 const ProxyInfo& used_proxy_info, |
| 314 HttpStream* stream) { | 324 HttpStream* stream) { |
| 315 MaybeResumeMainJob(job, base::TimeDelta()); | 325 MaybeResumeMainJob(job, base::TimeDelta()); |
| 316 | 326 |
| 317 if (job_bound_ && bound_job_ != job) { | 327 if (!request_ || (job_bound_ && bound_job_ != job)) { |
| 318 // We have bound a job to the associated Request, |job| has been orphaned. | 328 // We have bound a job to the associated Request, |job| has been orphaned. |
| 319 OnOrphanedJobComplete(job); | 329 OnOrphanedJobComplete(job); |
| 320 return; | 330 return; |
| 321 } | 331 } |
| 322 | 332 |
| 323 if (!bound_job_) | 333 if (!bound_job_) |
| 324 BindJob(job); | 334 BindJob(job); |
| 325 if (!request_) | 335 if (!request_) |
| 326 return; | 336 return; |
| 327 request_->OnHttpsProxyTunnelResponse(response_info, used_ssl_config, | 337 request_->OnHttpsProxyTunnelResponse(response_info, used_ssl_config, |
| 328 used_proxy_info, stream); | 338 used_proxy_info, stream); |
| 329 } | 339 } |
| 330 | 340 |
| 331 void HttpStreamFactoryImpl::JobController::OnNeedsClientAuth( | 341 void HttpStreamFactoryImpl::JobController::OnNeedsClientAuth( |
| 332 Job* job, | 342 Job* job, |
| 333 const SSLConfig& used_ssl_config, | 343 const SSLConfig& used_ssl_config, |
| 334 SSLCertRequestInfo* cert_info) { | 344 SSLCertRequestInfo* cert_info) { |
| 335 MaybeResumeMainJob(job, base::TimeDelta()); | 345 MaybeResumeMainJob(job, base::TimeDelta()); |
| 336 | 346 |
| 337 if (job_bound_ && bound_job_ != job) { | 347 if (!request_ || (job_bound_ && bound_job_ != job)) { |
| 338 // We have bound a job to the associated Request, |job| has been orphaned. | 348 // We have bound a job to the associated Request, |job| has been orphaned. |
| 339 OnOrphanedJobComplete(job); | 349 OnOrphanedJobComplete(job); |
| 340 return; | 350 return; |
| 341 } | 351 } |
| 342 if (!request_) | 352 if (!request_) |
| 343 return; | 353 return; |
| 344 if (!bound_job_) | 354 if (!bound_job_) |
| 345 BindJob(job); | 355 BindJob(job); |
| 346 | 356 |
| 347 request_->OnNeedsClientAuth(used_ssl_config, cert_info); | 357 request_->OnNeedsClientAuth(used_ssl_config, cert_info); |
| 348 } | 358 } |
| 349 | 359 |
| 350 void HttpStreamFactoryImpl::JobController::OnNeedsProxyAuth( | 360 void HttpStreamFactoryImpl::JobController::OnNeedsProxyAuth( |
| 351 Job* job, | 361 Job* job, |
| 352 const HttpResponseInfo& proxy_response, | 362 const HttpResponseInfo& proxy_response, |
| 353 const SSLConfig& used_ssl_config, | 363 const SSLConfig& used_ssl_config, |
| 354 const ProxyInfo& used_proxy_info, | 364 const ProxyInfo& used_proxy_info, |
| 355 HttpAuthController* auth_controller) { | 365 HttpAuthController* auth_controller) { |
| 356 MaybeResumeMainJob(job, base::TimeDelta()); | 366 MaybeResumeMainJob(job, base::TimeDelta()); |
| 357 | 367 |
| 358 if (job_bound_ && bound_job_ != job) { | 368 if (!request_ || (job_bound_ && bound_job_ != job)) { |
|
mmenke
2017/01/09 18:37:20
Suggest a helper method here, IsJobOrphaned(job) c
xunjieli
2017/01/09 19:18:21
Done.
| |
| 359 // We have bound a job to the associated Request, |job| has been orphaned. | 369 // We have bound a job to the associated Request, |job| has been orphaned. |
| 360 OnOrphanedJobComplete(job); | 370 OnOrphanedJobComplete(job); |
| 361 return; | 371 return; |
| 362 } | 372 } |
| 363 | 373 |
| 364 if (!request_) | 374 if (!request_) |
| 365 return; | 375 return; |
| 366 if (!bound_job_) | 376 if (!bound_job_) |
| 367 BindJob(job); | 377 BindJob(job); |
| 368 request_->OnNeedsProxyAuth(proxy_response, used_ssl_config, used_proxy_info, | 378 request_->OnNeedsProxyAuth(proxy_response, used_ssl_config, used_proxy_info, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 } | 425 } |
| 416 | 426 |
| 417 void HttpStreamFactoryImpl::JobController::OnNewSpdySessionReady( | 427 void HttpStreamFactoryImpl::JobController::OnNewSpdySessionReady( |
| 418 Job* job, | 428 Job* job, |
| 419 const base::WeakPtr<SpdySession>& spdy_session, | 429 const base::WeakPtr<SpdySession>& spdy_session, |
| 420 bool direct) { | 430 bool direct) { |
| 421 DCHECK(job); | 431 DCHECK(job); |
| 422 DCHECK(job->using_spdy()); | 432 DCHECK(job->using_spdy()); |
| 423 DCHECK(!is_preconnect_); | 433 DCHECK(!is_preconnect_); |
| 424 | 434 |
| 425 bool is_job_orphaned = job_bound_ && bound_job_ != job; | 435 bool is_job_orphaned = !request_ || (job_bound_ && bound_job_ != job); |
| 426 | 436 |
| 427 // Cache these values in case the job gets deleted. | 437 // Cache these values in case the job gets deleted. |
| 428 const SSLConfig used_ssl_config = job->server_ssl_config(); | 438 const SSLConfig used_ssl_config = job->server_ssl_config(); |
| 429 const ProxyInfo used_proxy_info = job->proxy_info(); | 439 const ProxyInfo used_proxy_info = job->proxy_info(); |
| 430 const bool was_alpn_negotiated = job->was_alpn_negotiated(); | 440 const bool was_alpn_negotiated = job->was_alpn_negotiated(); |
| 431 const NextProto negotiated_protocol = job->negotiated_protocol(); | 441 const NextProto negotiated_protocol = job->negotiated_protocol(); |
| 432 const bool using_spdy = job->using_spdy(); | 442 const bool using_spdy = job->using_spdy(); |
| 433 const NetLogWithSource net_log = job->net_log(); | 443 const NetLogWithSource net_log = job->net_log(); |
| 434 | 444 |
| 435 // Cache this so we can still use it if the JobController is deleted. | 445 // Cache this so we can still use it if the JobController is deleted. |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1079 } | 1089 } |
| 1080 | 1090 |
| 1081 void HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob() { | 1091 void HttpStreamFactoryImpl::JobController::StartAlternativeProxyServerJob() { |
| 1082 if (!alternative_job_ || !request_) | 1092 if (!alternative_job_ || !request_) |
| 1083 return; | 1093 return; |
| 1084 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); | 1094 DCHECK(alternative_job_->alternative_proxy_server().is_valid()); |
| 1085 alternative_job_->Start(request_->stream_type()); | 1095 alternative_job_->Start(request_->stream_type()); |
| 1086 } | 1096 } |
| 1087 | 1097 |
| 1088 } // namespace net | 1098 } // namespace net |
| OLD | NEW |