| 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 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), | 219 for_bidirectional_(false), |
| 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 |stream_type_|, since request is nulled when job is orphaned. | 251 // Saves |for_bidirectional_|, since request is nulled when job is orphaned. |
| 252 stream_type_ = request_->stream_type(); | 252 for_bidirectional_ = request_->for_bidirectional(); |
| 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 (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 505 if (for_bidirectional_) { |
| 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 |
| 514 } else { | 515 } else { |
| 515 DCHECK(stream_); | 516 DCHECK(stream_); |
| 516 request_->OnNewSpdySessionReady(this, std::move(stream_), | 517 request_->OnNewSpdySessionReady(this, std::move(stream_), |
| 517 /** bidirectional_stream_job=*/nullptr, | 518 /** bidirectional_stream_job=*/nullptr, |
| 518 spdy_session, spdy_session_direct_); | 519 spdy_session, spdy_session_direct_); |
| 519 } | 520 } |
| 520 } | 521 } |
| 521 // |this| may be deleted after this call. | 522 // |this| may be deleted after this call. |
| 522 } | 523 } |
| 523 | 524 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 next_state_ = STATE_DONE; | 697 next_state_ = STATE_DONE; |
| 697 if (new_spdy_session_.get()) { | 698 if (new_spdy_session_.get()) { |
| 698 base::ThreadTaskRunnerHandle::Get()->PostTask( | 699 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 699 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, | 700 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, |
| 700 ptr_factory_.GetWeakPtr())); | 701 ptr_factory_.GetWeakPtr())); |
| 701 } else if (stream_factory_->for_websockets_) { | 702 } else if (stream_factory_->for_websockets_) { |
| 702 DCHECK(websocket_stream_); | 703 DCHECK(websocket_stream_); |
| 703 base::ThreadTaskRunnerHandle::Get()->PostTask( | 704 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 704 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, | 705 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, |
| 705 ptr_factory_.GetWeakPtr())); | 706 ptr_factory_.GetWeakPtr())); |
| 706 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 707 } else if (for_bidirectional_) { |
| 707 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | 708 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
| 708 if (!bidirectional_stream_job_) { | 709 if (!bidirectional_stream_job_) { |
| 709 base::ThreadTaskRunnerHandle::Get()->PostTask( | 710 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 710 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, | 711 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, |
| 711 ptr_factory_.GetWeakPtr(), ERR_FAILED)); | 712 ptr_factory_.GetWeakPtr(), ERR_FAILED)); |
| 712 } else { | 713 } else { |
| 713 base::ThreadTaskRunnerHandle::Get()->PostTask( | 714 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 714 FROM_HERE, base::Bind(&Job::OnBidirectionalStreamJobReadyCallback, | 715 FROM_HERE, base::Bind(&Job::OnBidirectionalStreamJobReadyCallback, |
| 715 ptr_factory_.GetWeakPtr())); | 716 ptr_factory_.GetWeakPtr())); |
| 716 } | 717 } |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) | 1010 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) |
| 1010 return ERR_QUIC_PROTOCOL_ERROR; | 1011 return ERR_QUIC_PROTOCOL_ERROR; |
| 1011 } else { | 1012 } else { |
| 1012 DCHECK(using_ssl_); | 1013 DCHECK(using_ssl_); |
| 1013 // The certificate of a QUIC alternative server is expected to be valid | 1014 // The certificate of a QUIC alternative server is expected to be valid |
| 1014 // for the origin of the request (in addition to being valid for the | 1015 // for the origin of the request (in addition to being valid for the |
| 1015 // server itself). | 1016 // server itself). |
| 1016 destination = server_; | 1017 destination = server_; |
| 1017 ssl_config = &server_ssl_config_; | 1018 ssl_config = &server_ssl_config_; |
| 1018 } | 1019 } |
| 1020 |
| 1019 int rv = | 1021 int rv = |
| 1020 quic_request_.Request(destination, request_info_.privacy_mode, | 1022 quic_request_.Request(destination, request_info_.privacy_mode, |
| 1021 ssl_config->GetCertVerifyFlags(), url, | 1023 ssl_config->GetCertVerifyFlags(), url, |
| 1022 request_info_.method, net_log_, io_callback_); | 1024 request_info_.method, net_log_, io_callback_); |
| 1023 if (rv == OK) { | 1025 if (rv == OK) { |
| 1024 using_existing_quic_session_ = true; | 1026 using_existing_quic_session_ = true; |
| 1025 } else { | 1027 } else { |
| 1026 // OK, there's no available QUIC session. Let |waiting_job_| resume | 1028 // OK, there's no available QUIC session. Let |waiting_job_| resume |
| 1027 // if it's paused. | 1029 // if it's paused. |
| 1028 if (waiting_job_) { | 1030 if (waiting_job_) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 MaybeMarkAlternativeServiceBroken(); | 1252 MaybeMarkAlternativeServiceBroken(); |
| 1251 return result; | 1253 return result; |
| 1252 } | 1254 } |
| 1253 | 1255 |
| 1254 if (using_quic_) { | 1256 if (using_quic_) { |
| 1255 if (result < 0) { | 1257 if (result < 0) { |
| 1256 job_status_ = STATUS_BROKEN; | 1258 job_status_ = STATUS_BROKEN; |
| 1257 MaybeMarkAlternativeServiceBroken(); | 1259 MaybeMarkAlternativeServiceBroken(); |
| 1258 return result; | 1260 return result; |
| 1259 } | 1261 } |
| 1260 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 1262 stream_ = quic_request_.ReleaseStream(); |
| 1261 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | |
| 1262 bidirectional_stream_job_ = quic_request_.CreateBidirectionalStreamJob(); | |
| 1263 if (!bidirectional_stream_job_) { | |
| 1264 // Quic session is closed before stream can be created. | |
| 1265 return ERR_CONNECTION_CLOSED; | |
| 1266 } | |
| 1267 #else | |
| 1268 NOTREACHED(); | |
| 1269 #endif | |
| 1270 } else { | |
| 1271 stream_ = quic_request_.CreateStream(); | |
| 1272 if (!stream_) { | |
| 1273 // Quic session is closed before stream can be created. | |
| 1274 return ERR_CONNECTION_CLOSED; | |
| 1275 } | |
| 1276 } | |
| 1277 next_state_ = STATE_NONE; | 1263 next_state_ = STATE_NONE; |
| 1278 return OK; | 1264 return OK; |
| 1279 } | 1265 } |
| 1280 | 1266 |
| 1281 if (result < 0 && !ssl_started) | 1267 if (result < 0 && !ssl_started) |
| 1282 return ReconsiderProxyAfterError(result); | 1268 return ReconsiderProxyAfterError(result); |
| 1283 establishing_tunnel_ = false; | 1269 establishing_tunnel_ = false; |
| 1284 | 1270 |
| 1285 if (connection_->socket()) { | 1271 if (connection_->socket()) { |
| 1286 // We officially have a new connection. Record the type. | 1272 // We officially have a new connection. Record the type. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 return ERR_IO_PENDING; | 1309 return ERR_IO_PENDING; |
| 1324 } | 1310 } |
| 1325 | 1311 |
| 1326 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamJob( | 1312 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamJob( |
| 1327 base::WeakPtr<SpdySession> session, | 1313 base::WeakPtr<SpdySession> session, |
| 1328 bool direct) { | 1314 bool direct) { |
| 1329 // TODO(ricea): Restore the code for WebSockets over SPDY once it's | 1315 // TODO(ricea): Restore the code for WebSockets over SPDY once it's |
| 1330 // implemented. | 1316 // implemented. |
| 1331 if (stream_factory_->for_websockets_) | 1317 if (stream_factory_->for_websockets_) |
| 1332 return ERR_NOT_IMPLEMENTED; | 1318 return ERR_NOT_IMPLEMENTED; |
| 1333 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 1319 if (for_bidirectional_) { |
| 1334 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | 1320 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
| 1321 // TODO(xunjieli): Create QUIC's version of BidirectionalStreamJob. |
| 1335 bidirectional_stream_job_.reset(new BidirectionalStreamSpdyJob(session)); | 1322 bidirectional_stream_job_.reset(new BidirectionalStreamSpdyJob(session)); |
| 1336 return OK; | 1323 return OK; |
| 1337 #else | 1324 #else |
| 1338 NOTREACHED(); | 1325 DCHECK(false); |
| 1339 return ERR_FAILED; | 1326 return ERR_FAILED; |
| 1340 #endif | 1327 #endif |
| 1341 } | 1328 } |
| 1342 | 1329 |
| 1343 // TODO(willchan): Delete this code, because eventually, the | 1330 // TODO(willchan): Delete this code, because eventually, the |
| 1344 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1331 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
| 1345 // will know when SpdySessions become available. | 1332 // will know when SpdySessions become available. |
| 1346 | 1333 |
| 1347 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1334 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); |
| 1348 stream_.reset(new SpdyHttpStream(session, use_relative_url)); | 1335 stream_.reset(new SpdyHttpStream(session, use_relative_url)); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 if (connection_->socket()) { | 1803 if (connection_->socket()) { |
| 1817 ConnectionAttempts socket_attempts; | 1804 ConnectionAttempts socket_attempts; |
| 1818 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1805 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1819 request_->AddConnectionAttempts(socket_attempts); | 1806 request_->AddConnectionAttempts(socket_attempts); |
| 1820 } else { | 1807 } else { |
| 1821 request_->AddConnectionAttempts(connection_->connection_attempts()); | 1808 request_->AddConnectionAttempts(connection_->connection_attempts()); |
| 1822 } | 1809 } |
| 1823 } | 1810 } |
| 1824 | 1811 |
| 1825 } // namespace net | 1812 } // namespace net |
| OLD | NEW |