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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 quic_request_(session_->quic_stream_factory()), | 209 quic_request_(session_->quic_stream_factory()), |
| 210 using_existing_quic_session_(false), | 210 using_existing_quic_session_(false), |
| 211 spdy_certificate_error_(OK), | 211 spdy_certificate_error_(OK), |
| 212 establishing_tunnel_(false), | 212 establishing_tunnel_(false), |
| 213 was_npn_negotiated_(false), | 213 was_npn_negotiated_(false), |
| 214 protocol_negotiated_(kProtoUnknown), | 214 protocol_negotiated_(kProtoUnknown), |
| 215 num_streams_(0), | 215 num_streams_(0), |
| 216 spdy_session_direct_(false), | 216 spdy_session_direct_(false), |
| 217 job_status_(STATUS_RUNNING), | 217 job_status_(STATUS_RUNNING), |
| 218 other_job_status_(STATUS_RUNNING), | 218 other_job_status_(STATUS_RUNNING), |
| 219 for_bidirectional_(false), | 219 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), |
| 220 ptr_factory_(this) { | 220 ptr_factory_(this) { |
| 221 DCHECK(stream_factory); | 221 DCHECK(stream_factory); |
| 222 DCHECK(session); | 222 DCHECK(session); |
| 223 if (IsQuicAlternative()) { | 223 if (IsQuicAlternative()) { |
| 224 DCHECK(session_->params().enable_quic); | 224 DCHECK(session_->params().enable_quic); |
| 225 using_quic_ = true; | 225 using_quic_ = true; |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 HttpStreamFactoryImpl::Job::~Job() { | 229 HttpStreamFactoryImpl::Job::~Job() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 241 session_->proxy_service()->CancelPacRequest(pac_request_); | 241 session_->proxy_service()->CancelPacRequest(pac_request_); |
| 242 | 242 |
| 243 // The stream could be in a partial state. It is not reusable. | 243 // The stream could be in a partial state. It is not reusable. |
| 244 if (stream_.get() && next_state_ != STATE_DONE) | 244 if (stream_.get() && next_state_ != STATE_DONE) |
| 245 stream_->Close(true /* not reusable */); | 245 stream_->Close(true /* not reusable */); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void HttpStreamFactoryImpl::Job::Start(Request* request) { | 248 void HttpStreamFactoryImpl::Job::Start(Request* request) { |
| 249 DCHECK(request); | 249 DCHECK(request); |
| 250 request_ = request; | 250 request_ = request; |
| 251 // Saves |for_bidirectional_|, since request is nulled when job is orphaned. | 251 // Saves |stream_type_|, since request is nulled when job is orphaned. |
| 252 for_bidirectional_ = request_->for_bidirectional(); | 252 stream_type_ = request_->stream_type(); |
| 253 StartInternal(); | 253 StartInternal(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) { | 256 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) { |
| 257 DCHECK_GT(num_streams, 0); | 257 DCHECK_GT(num_streams, 0); |
| 258 base::WeakPtr<HttpServerProperties> http_server_properties = | 258 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 259 session_->http_server_properties(); | 259 session_->http_server_properties(); |
| 260 if (http_server_properties && | 260 if (http_server_properties && |
| 261 http_server_properties->SupportsRequestPriority( | 261 http_server_properties->SupportsRequestPriority( |
| 262 HostPortPair::FromURL(request_info_.url))) { | 262 HostPortPair::FromURL(request_info_.url))) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, | 495 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, |
| 496 // rather than notifying |request_| directly. | 496 // rather than notifying |request_| directly. |
| 497 if (IsOrphaned()) { | 497 if (IsOrphaned()) { |
| 498 if (spdy_session) { | 498 if (spdy_session) { |
| 499 stream_factory_->OnNewSpdySessionReady( | 499 stream_factory_->OnNewSpdySessionReady( |
| 500 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, | 500 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, |
| 501 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); | 501 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); |
| 502 } | 502 } |
| 503 stream_factory_->OnOrphanedJobComplete(this); | 503 stream_factory_->OnOrphanedJobComplete(this); |
| 504 } else { | 504 } else { |
| 505 if (for_bidirectional_) { | 505 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 506 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | 506 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
| 507 DCHECK(bidirectional_stream_job_); | 507 DCHECK(bidirectional_stream_job_); |
| 508 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr, | 508 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr, |
| 509 std::move(bidirectional_stream_job_), | 509 std::move(bidirectional_stream_job_), |
| 510 spdy_session, spdy_session_direct_); | 510 spdy_session, spdy_session_direct_); |
| 511 #else | 511 #else |
| 512 DCHECK(false); | 512 DCHECK(false); |
| 513 #endif | 513 #endif |
| 514 | |
| 515 } else { | 514 } else { |
| 516 DCHECK(stream_); | 515 DCHECK(stream_); |
| 517 request_->OnNewSpdySessionReady(this, std::move(stream_), | 516 request_->OnNewSpdySessionReady(this, std::move(stream_), |
| 518 /** bidirectional_stream_job=*/nullptr, | 517 /** bidirectional_stream_job=*/nullptr, |
| 519 spdy_session, spdy_session_direct_); | 518 spdy_session, spdy_session_direct_); |
| 520 } | 519 } |
| 521 } | 520 } |
| 522 // |this| may be deleted after this call. | 521 // |this| may be deleted after this call. |
| 523 } | 522 } |
| 524 | 523 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 next_state_ = STATE_DONE; | 696 next_state_ = STATE_DONE; |
| 698 if (new_spdy_session_.get()) { | 697 if (new_spdy_session_.get()) { |
| 699 base::ThreadTaskRunnerHandle::Get()->PostTask( | 698 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 700 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, | 699 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, |
| 701 ptr_factory_.GetWeakPtr())); | 700 ptr_factory_.GetWeakPtr())); |
| 702 } else if (stream_factory_->for_websockets_) { | 701 } else if (stream_factory_->for_websockets_) { |
| 703 DCHECK(websocket_stream_); | 702 DCHECK(websocket_stream_); |
| 704 base::ThreadTaskRunnerHandle::Get()->PostTask( | 703 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 705 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, | 704 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, |
| 706 ptr_factory_.GetWeakPtr())); | 705 ptr_factory_.GetWeakPtr())); |
| 707 } else if (for_bidirectional_) { | 706 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 708 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | 707 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
| 709 if (!bidirectional_stream_job_) { | 708 if (!bidirectional_stream_job_) { |
| 710 base::ThreadTaskRunnerHandle::Get()->PostTask( | 709 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 711 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, | 710 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, |
| 712 ptr_factory_.GetWeakPtr(), ERR_FAILED)); | 711 ptr_factory_.GetWeakPtr(), ERR_FAILED)); |
| 713 } else { | 712 } else { |
| 714 base::ThreadTaskRunnerHandle::Get()->PostTask( | 713 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 715 FROM_HERE, base::Bind(&Job::OnBidirectionalStreamJobReadyCallback, | 714 FROM_HERE, base::Bind(&Job::OnBidirectionalStreamJobReadyCallback, |
| 716 ptr_factory_.GetWeakPtr())); | 715 ptr_factory_.GetWeakPtr())); |
| 717 } | 716 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) | 1007 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) |
| 1009 return ERR_QUIC_PROTOCOL_ERROR; | 1008 return ERR_QUIC_PROTOCOL_ERROR; |
| 1010 } else { | 1009 } else { |
| 1011 DCHECK(using_ssl_); | 1010 DCHECK(using_ssl_); |
| 1012 // The certificate of a QUIC alternative server is expected to be valid | 1011 // The certificate of a QUIC alternative server is expected to be valid |
| 1013 // for the origin of the request (in addition to being valid for the | 1012 // for the origin of the request (in addition to being valid for the |
| 1014 // server itself). | 1013 // server itself). |
| 1015 destination = server_; | 1014 destination = server_; |
| 1016 ssl_config = &server_ssl_config_; | 1015 ssl_config = &server_ssl_config_; |
| 1017 } | 1016 } |
| 1018 | |
| 1019 int rv = | 1017 int rv = |
| 1020 quic_request_.Request(destination, request_info_.privacy_mode, | 1018 quic_request_.Request(destination, request_info_.privacy_mode, |
| 1021 ssl_config->GetCertVerifyFlags(), url, | 1019 ssl_config->GetCertVerifyFlags(), url, |
| 1022 request_info_.method, net_log_, io_callback_); | 1020 request_info_.method, net_log_, io_callback_); |
| 1023 if (rv == OK) { | 1021 if (rv == OK) { |
| 1024 using_existing_quic_session_ = true; | 1022 using_existing_quic_session_ = true; |
| 1025 } else { | 1023 } else { |
| 1026 // OK, there's no available QUIC session. Let |waiting_job_| resume | 1024 // OK, there's no available QUIC session. Let |waiting_job_| resume |
| 1027 // if it's paused. | 1025 // if it's paused. |
| 1028 if (waiting_job_) { | 1026 if (waiting_job_) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 MaybeMarkAlternativeServiceBroken(); | 1248 MaybeMarkAlternativeServiceBroken(); |
| 1251 return result; | 1249 return result; |
| 1252 } | 1250 } |
| 1253 | 1251 |
| 1254 if (using_quic_) { | 1252 if (using_quic_) { |
| 1255 if (result < 0) { | 1253 if (result < 0) { |
| 1256 job_status_ = STATUS_BROKEN; | 1254 job_status_ = STATUS_BROKEN; |
| 1257 MaybeMarkAlternativeServiceBroken(); | 1255 MaybeMarkAlternativeServiceBroken(); |
| 1258 return result; | 1256 return result; |
| 1259 } | 1257 } |
| 1260 stream_ = quic_request_.ReleaseStream(); | 1258 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 1259 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | |
| 1260 bidirectional_stream_job_ = quic_request_.ReleaseBidirectionalStreamJob(); | |
| 1261 #else | |
| 1262 NOTREACHED(); | |
| 1263 #endif | |
| 1264 } else { | |
| 1265 stream_ = quic_request_.ReleaseStream(); | |
| 1266 } | |
| 1261 next_state_ = STATE_NONE; | 1267 next_state_ = STATE_NONE; |
| 1262 return OK; | 1268 return OK; |
| 1263 } | 1269 } |
| 1264 | 1270 |
| 1265 if (result < 0 && !ssl_started) | 1271 if (result < 0 && !ssl_started) |
| 1266 return ReconsiderProxyAfterError(result); | 1272 return ReconsiderProxyAfterError(result); |
| 1267 establishing_tunnel_ = false; | 1273 establishing_tunnel_ = false; |
| 1268 | 1274 |
| 1269 if (connection_->socket()) { | 1275 if (connection_->socket()) { |
| 1270 // We officially have a new connection. Record the type. | 1276 // We officially have a new connection. Record the type. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 return ERR_IO_PENDING; | 1313 return ERR_IO_PENDING; |
| 1308 } | 1314 } |
| 1309 | 1315 |
| 1310 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamJob( | 1316 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamJob( |
| 1311 base::WeakPtr<SpdySession> session, | 1317 base::WeakPtr<SpdySession> session, |
| 1312 bool direct) { | 1318 bool direct) { |
| 1313 // TODO(ricea): Restore the code for WebSockets over SPDY once it's | 1319 // TODO(ricea): Restore the code for WebSockets over SPDY once it's |
| 1314 // implemented. | 1320 // implemented. |
| 1315 if (stream_factory_->for_websockets_) | 1321 if (stream_factory_->for_websockets_) |
| 1316 return ERR_NOT_IMPLEMENTED; | 1322 return ERR_NOT_IMPLEMENTED; |
| 1317 if (for_bidirectional_) { | 1323 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 1318 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | 1324 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
| 1319 // TODO(xunjieli): Create QUIC's version of BidirectionalStreamJob. | |
| 1320 bidirectional_stream_job_.reset(new BidirectionalStreamSpdyJob(session)); | 1325 bidirectional_stream_job_.reset(new BidirectionalStreamSpdyJob(session)); |
| 1321 return OK; | 1326 return OK; |
| 1322 #else | 1327 #else |
| 1323 DCHECK(false); | 1328 DCHECK(false); |
|
Ryan Hamilton
2016/03/07 20:12:37
nit: this should probably be NOTREACHED();
xunjieli
2016/03/08 15:39:32
Done.
| |
| 1324 return ERR_FAILED; | 1329 return ERR_FAILED; |
| 1325 #endif | 1330 #endif |
| 1326 } | 1331 } |
| 1327 | 1332 |
| 1328 // TODO(willchan): Delete this code, because eventually, the | 1333 // TODO(willchan): Delete this code, because eventually, the |
| 1329 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1334 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
| 1330 // will know when SpdySessions become available. | 1335 // will know when SpdySessions become available. |
| 1331 | 1336 |
| 1332 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1337 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); |
| 1333 stream_.reset(new SpdyHttpStream(session, use_relative_url)); | 1338 stream_.reset(new SpdyHttpStream(session, use_relative_url)); |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1798 if (connection_->socket()) { | 1803 if (connection_->socket()) { |
| 1799 ConnectionAttempts socket_attempts; | 1804 ConnectionAttempts socket_attempts; |
| 1800 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1805 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1801 request_->AddConnectionAttempts(socket_attempts); | 1806 request_->AddConnectionAttempts(socket_attempts); |
| 1802 } else { | 1807 } else { |
| 1803 request_->AddConnectionAttempts(connection_->connection_attempts()); | 1808 request_->AddConnectionAttempts(connection_->connection_attempts()); |
| 1804 } | 1809 } |
| 1805 } | 1810 } |
| 1806 | 1811 |
| 1807 } // namespace net | 1812 } // namespace net |
| OLD | NEW |