| 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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 DCHECK(job); | 168 DCHECK(job); |
| 169 | 169 |
| 170 if (job_bound_ && bound_job_ != job) { | 170 if (job_bound_ && bound_job_ != job) { |
| 171 // We have bound a job to the associated Request, |job| has been orphaned. | 171 // We have bound a job to the associated Request, |job| has been orphaned. |
| 172 OnOrphanedJobComplete(job); | 172 OnOrphanedJobComplete(job); |
| 173 return; | 173 return; |
| 174 } | 174 } |
| 175 std::unique_ptr<HttpStream> stream = job->ReleaseStream(); | 175 std::unique_ptr<HttpStream> stream = job->ReleaseStream(); |
| 176 DCHECK(stream); | 176 DCHECK(stream); |
| 177 | 177 |
| 178 MarkRequestComplete(job->was_npn_negotiated(), job->negotiated_protocol(), | 178 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), |
| 179 job->using_spdy()); | 179 job->using_spdy()); |
| 180 | 180 |
| 181 if (!request_) | 181 if (!request_) |
| 182 return; | 182 return; |
| 183 DCHECK(!factory_->for_websockets_); | 183 DCHECK(!factory_->for_websockets_); |
| 184 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type()); | 184 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type()); |
| 185 OnJobSucceeded(job); | 185 OnJobSucceeded(job); |
| 186 request_->OnStreamReady(used_ssl_config, used_proxy_info, stream.release()); | 186 request_->OnStreamReady(used_ssl_config, used_proxy_info, stream.release()); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void HttpStreamFactoryImpl::JobController::OnBidirectionalStreamImplReady( | 189 void HttpStreamFactoryImpl::JobController::OnBidirectionalStreamImplReady( |
| 190 Job* job, | 190 Job* job, |
| 191 const SSLConfig& used_ssl_config, | 191 const SSLConfig& used_ssl_config, |
| 192 const ProxyInfo& used_proxy_info) { | 192 const ProxyInfo& used_proxy_info) { |
| 193 DCHECK(job); | 193 DCHECK(job); |
| 194 | 194 |
| 195 if (job_bound_ && bound_job_ != job) { | 195 if (job_bound_ && bound_job_ != job) { |
| 196 // We have bound a job to the associated Request, |job| has been orphaned. | 196 // We have bound a job to the associated Request, |job| has been orphaned. |
| 197 OnOrphanedJobComplete(job); | 197 OnOrphanedJobComplete(job); |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 | 200 |
| 201 MarkRequestComplete(job->was_npn_negotiated(), job->negotiated_protocol(), | 201 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), |
| 202 job->using_spdy()); | 202 job->using_spdy()); |
| 203 | 203 |
| 204 if (!request_) | 204 if (!request_) |
| 205 return; | 205 return; |
| 206 std::unique_ptr<BidirectionalStreamImpl> stream = | 206 std::unique_ptr<BidirectionalStreamImpl> stream = |
| 207 job->ReleaseBidirectionalStream(); | 207 job->ReleaseBidirectionalStream(); |
| 208 DCHECK(stream); | 208 DCHECK(stream); |
| 209 DCHECK(!factory_->for_websockets_); | 209 DCHECK(!factory_->for_websockets_); |
| 210 DCHECK_EQ(HttpStreamRequest::BIDIRECTIONAL_STREAM, request_->stream_type()); | 210 DCHECK_EQ(HttpStreamRequest::BIDIRECTIONAL_STREAM, request_->stream_type()); |
| 211 | 211 |
| 212 OnJobSucceeded(job); | 212 OnJobSucceeded(job); |
| 213 request_->OnBidirectionalStreamImplReady(used_ssl_config, used_proxy_info, | 213 request_->OnBidirectionalStreamImplReady(used_ssl_config, used_proxy_info, |
| 214 stream.release()); | 214 stream.release()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void HttpStreamFactoryImpl::JobController::OnWebSocketHandshakeStreamReady( | 217 void HttpStreamFactoryImpl::JobController::OnWebSocketHandshakeStreamReady( |
| 218 Job* job, | 218 Job* job, |
| 219 const SSLConfig& used_ssl_config, | 219 const SSLConfig& used_ssl_config, |
| 220 const ProxyInfo& used_proxy_info, | 220 const ProxyInfo& used_proxy_info, |
| 221 WebSocketHandshakeStreamBase* stream) { | 221 WebSocketHandshakeStreamBase* stream) { |
| 222 DCHECK(job); | 222 DCHECK(job); |
| 223 MarkRequestComplete(job->was_npn_negotiated(), job->negotiated_protocol(), | 223 MarkRequestComplete(job->was_alpn_negotiated(), job->negotiated_protocol(), |
| 224 job->using_spdy()); | 224 job->using_spdy()); |
| 225 | 225 |
| 226 if (!request_) | 226 if (!request_) |
| 227 return; | 227 return; |
| 228 DCHECK(factory_->for_websockets_); | 228 DCHECK(factory_->for_websockets_); |
| 229 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type()); | 229 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type()); |
| 230 DCHECK(stream); | 230 DCHECK(stream); |
| 231 | 231 |
| 232 OnJobSucceeded(job); | 232 OnJobSucceeded(job); |
| 233 request_->OnWebSocketHandshakeStreamReady(used_ssl_config, used_proxy_info, | 233 request_->OnWebSocketHandshakeStreamReady(used_ssl_config, used_proxy_info, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 const base::WeakPtr<SpdySession>& spdy_session, | 403 const base::WeakPtr<SpdySession>& spdy_session, |
| 404 bool direct) { | 404 bool direct) { |
| 405 DCHECK(job); | 405 DCHECK(job); |
| 406 DCHECK(job->using_spdy()); | 406 DCHECK(job->using_spdy()); |
| 407 | 407 |
| 408 bool is_job_orphaned = job_bound_ && bound_job_ != job; | 408 bool is_job_orphaned = job_bound_ && bound_job_ != job; |
| 409 | 409 |
| 410 // Cache these values in case the job gets deleted. | 410 // Cache these values in case the job gets deleted. |
| 411 const SSLConfig used_ssl_config = job->server_ssl_config(); | 411 const SSLConfig used_ssl_config = job->server_ssl_config(); |
| 412 const ProxyInfo used_proxy_info = job->proxy_info(); | 412 const ProxyInfo used_proxy_info = job->proxy_info(); |
| 413 const bool was_npn_negotiated = job->was_npn_negotiated(); | 413 const bool was_alpn_negotiated = job->was_alpn_negotiated(); |
| 414 const NextProto negotiated_protocol = job->negotiated_protocol(); | 414 const NextProto negotiated_protocol = job->negotiated_protocol(); |
| 415 const bool using_spdy = job->using_spdy(); | 415 const bool using_spdy = job->using_spdy(); |
| 416 const BoundNetLog net_log = job->net_log(); | 416 const BoundNetLog net_log = job->net_log(); |
| 417 | 417 |
| 418 // Cache this so we can still use it if the JobController is deleted. | 418 // Cache this so we can still use it if the JobController is deleted. |
| 419 HttpStreamFactoryImpl* factory = factory_; | 419 HttpStreamFactoryImpl* factory = factory_; |
| 420 | 420 |
| 421 // Notify |request_|. | 421 // Notify |request_|. |
| 422 if (!is_preconnect_ && !is_job_orphaned) { | 422 if (!is_preconnect_ && !is_job_orphaned) { |
| 423 if (job->job_type() == MAIN && alternative_job_failed_) | 423 if (job->job_type() == MAIN && alternative_job_failed_) |
| 424 ReportBrokenAlternativeService(); | 424 ReportBrokenAlternativeService(); |
| 425 | 425 |
| 426 DCHECK(request_); | 426 DCHECK(request_); |
| 427 | 427 |
| 428 // The first case is the usual case. | 428 // The first case is the usual case. |
| 429 if (!job_bound_) { | 429 if (!job_bound_) { |
| 430 BindJob(job); | 430 BindJob(job); |
| 431 } | 431 } |
| 432 | 432 |
| 433 MarkRequestComplete(was_npn_negotiated, negotiated_protocol, using_spdy); | 433 MarkRequestComplete(was_alpn_negotiated, negotiated_protocol, using_spdy); |
| 434 | 434 |
| 435 std::unique_ptr<HttpStream> stream; | 435 std::unique_ptr<HttpStream> stream; |
| 436 std::unique_ptr<BidirectionalStreamImpl> bidirectional_stream_impl; | 436 std::unique_ptr<BidirectionalStreamImpl> bidirectional_stream_impl; |
| 437 | 437 |
| 438 if (for_websockets()) { | 438 if (for_websockets()) { |
| 439 // TODO(ricea): Re-instate this code when WebSockets over SPDY is | 439 // TODO(ricea): Re-instate this code when WebSockets over SPDY is |
| 440 // implemented. | 440 // implemented. |
| 441 NOTREACHED(); | 441 NOTREACHED(); |
| 442 } else if (job->stream_type() == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 442 } else if (job->stream_type() == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 443 bidirectional_stream_impl = job->ReleaseBidirectionalStream(); | 443 bidirectional_stream_impl = job->ReleaseBidirectionalStream(); |
| 444 DCHECK(bidirectional_stream_impl); | 444 DCHECK(bidirectional_stream_impl); |
| 445 delegate_->OnBidirectionalStreamImplReady( | 445 delegate_->OnBidirectionalStreamImplReady( |
| 446 used_ssl_config, used_proxy_info, | 446 used_ssl_config, used_proxy_info, |
| 447 bidirectional_stream_impl.release()); | 447 bidirectional_stream_impl.release()); |
| 448 } else { | 448 } else { |
| 449 stream = job->ReleaseStream(); | 449 stream = job->ReleaseStream(); |
| 450 DCHECK(stream); | 450 DCHECK(stream); |
| 451 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, | 451 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, |
| 452 stream.release()); | 452 stream.release()); |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 | 455 |
| 456 // Notify |factory_|. |request_| and |bounded_job_| might be deleted already. | 456 // Notify |factory_|. |request_| and |bounded_job_| might be deleted already. |
| 457 if (spdy_session && spdy_session->IsAvailable()) { | 457 if (spdy_session && spdy_session->IsAvailable()) { |
| 458 factory->OnNewSpdySessionReady(spdy_session, direct, used_ssl_config, | 458 factory->OnNewSpdySessionReady(spdy_session, direct, used_ssl_config, |
| 459 used_proxy_info, was_npn_negotiated, | 459 used_proxy_info, was_alpn_negotiated, |
| 460 negotiated_protocol, using_spdy, net_log); | 460 negotiated_protocol, using_spdy, net_log); |
| 461 } | 461 } |
| 462 if (is_job_orphaned) { | 462 if (is_job_orphaned) { |
| 463 OnOrphanedJobComplete(job); | 463 OnOrphanedJobComplete(job); |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 | 466 |
| 467 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) { | 467 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) { |
| 468 DCHECK_EQ(main_job_.get(), job); | 468 DCHECK_EQ(main_job_.get(), job); |
| 469 main_job_.reset(); | 469 main_job_.reset(); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 if (!bound_job_) { | 742 if (!bound_job_) { |
| 743 if (main_job_ && alternative_job_) | 743 if (main_job_ && alternative_job_) |
| 744 job->ReportJobSucceededForRequest(); | 744 job->ReportJobSucceededForRequest(); |
| 745 BindJob(job); | 745 BindJob(job); |
| 746 return; | 746 return; |
| 747 } | 747 } |
| 748 DCHECK(bound_job_); | 748 DCHECK(bound_job_); |
| 749 } | 749 } |
| 750 | 750 |
| 751 void HttpStreamFactoryImpl::JobController::MarkRequestComplete( | 751 void HttpStreamFactoryImpl::JobController::MarkRequestComplete( |
| 752 bool was_npn_negotiated, | 752 bool was_alpn_negotiated, |
| 753 NextProto negotiated_protocol, | 753 NextProto negotiated_protocol, |
| 754 bool using_spdy) { | 754 bool using_spdy) { |
| 755 if (request_) | 755 if (request_) |
| 756 request_->Complete(was_npn_negotiated, negotiated_protocol, using_spdy); | 756 request_->Complete(was_alpn_negotiated, negotiated_protocol, using_spdy); |
| 757 } | 757 } |
| 758 | 758 |
| 759 void HttpStreamFactoryImpl::JobController::OnAlternativeJobFailed(Job* job) { | 759 void HttpStreamFactoryImpl::JobController::OnAlternativeJobFailed(Job* job) { |
| 760 DCHECK_EQ(job->job_type(), ALTERNATIVE); | 760 DCHECK_EQ(job->job_type(), ALTERNATIVE); |
| 761 | 761 |
| 762 alternative_job_failed_ = true; | 762 alternative_job_failed_ = true; |
| 763 | 763 |
| 764 if (job->alternative_proxy_server().is_valid()) { | 764 if (job->alternative_proxy_server().is_valid()) { |
| 765 failed_alternative_proxy_server_ = job->alternative_proxy_server(); | 765 failed_alternative_proxy_server_ = job->alternative_proxy_server(); |
| 766 } else { | 766 } else { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 // Check that QUIC is enabled globally, and it is not disabled. | 1040 // Check that QUIC is enabled globally, and it is not disabled. |
| 1041 if (!session_->params().enable_quic || | 1041 if (!session_->params().enable_quic || |
| 1042 session_->quic_stream_factory()->IsQuicDisabled()) { | 1042 session_->quic_stream_factory()->IsQuicDisabled()) { |
| 1043 return false; | 1043 return false; |
| 1044 } | 1044 } |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 return true; | 1047 return true; |
| 1048 } | 1048 } |
| 1049 } | 1049 } |
| OLD | NEW |