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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) | 1009 if (session_->quic_stream_factory()->IsQuicDisabled(destination.port())) |
1011 return ERR_QUIC_PROTOCOL_ERROR; | 1010 return ERR_QUIC_PROTOCOL_ERROR; |
1012 } else { | 1011 } else { |
1013 DCHECK(using_ssl_); | 1012 DCHECK(using_ssl_); |
1014 // The certificate of a QUIC alternative server is expected to be valid | 1013 // The certificate of a QUIC alternative server is expected to be valid |
1015 // for the origin of the request (in addition to being valid for the | 1014 // for the origin of the request (in addition to being valid for the |
1016 // server itself). | 1015 // server itself). |
1017 destination = server_; | 1016 destination = server_; |
1018 ssl_config = &server_ssl_config_; | 1017 ssl_config = &server_ssl_config_; |
1019 } | 1018 } |
1020 | |
1021 int rv = | 1019 int rv = |
1022 quic_request_.Request(destination, request_info_.privacy_mode, | 1020 quic_request_.Request(destination, request_info_.privacy_mode, |
1023 ssl_config->GetCertVerifyFlags(), url, | 1021 ssl_config->GetCertVerifyFlags(), url, |
1024 request_info_.method, net_log_, io_callback_); | 1022 request_info_.method, net_log_, io_callback_); |
1025 if (rv == OK) { | 1023 if (rv == OK) { |
1026 using_existing_quic_session_ = true; | 1024 using_existing_quic_session_ = true; |
1027 } else { | 1025 } else { |
1028 // OK, there's no available QUIC session. Let |waiting_job_| resume | 1026 // OK, there's no available QUIC session. Let |waiting_job_| resume |
1029 // if it's paused. | 1027 // if it's paused. |
1030 if (waiting_job_) { | 1028 if (waiting_job_) { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 MaybeMarkAlternativeServiceBroken(); | 1250 MaybeMarkAlternativeServiceBroken(); |
1253 return result; | 1251 return result; |
1254 } | 1252 } |
1255 | 1253 |
1256 if (using_quic_) { | 1254 if (using_quic_) { |
1257 if (result < 0) { | 1255 if (result < 0) { |
1258 job_status_ = STATUS_BROKEN; | 1256 job_status_ = STATUS_BROKEN; |
1259 MaybeMarkAlternativeServiceBroken(); | 1257 MaybeMarkAlternativeServiceBroken(); |
1260 return result; | 1258 return result; |
1261 } | 1259 } |
1262 stream_ = quic_request_.ReleaseStream(); | 1260 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 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 } |
1263 next_state_ = STATE_NONE; | 1277 next_state_ = STATE_NONE; |
1264 return OK; | 1278 return OK; |
1265 } | 1279 } |
1266 | 1280 |
1267 if (result < 0 && !ssl_started) | 1281 if (result < 0 && !ssl_started) |
1268 return ReconsiderProxyAfterError(result); | 1282 return ReconsiderProxyAfterError(result); |
1269 establishing_tunnel_ = false; | 1283 establishing_tunnel_ = false; |
1270 | 1284 |
1271 if (connection_->socket()) { | 1285 if (connection_->socket()) { |
1272 // We officially have a new connection. Record the type. | 1286 // We officially have a new connection. Record the type. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 return ERR_IO_PENDING; | 1323 return ERR_IO_PENDING; |
1310 } | 1324 } |
1311 | 1325 |
1312 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamJob( | 1326 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamJob( |
1313 base::WeakPtr<SpdySession> session, | 1327 base::WeakPtr<SpdySession> session, |
1314 bool direct) { | 1328 bool direct) { |
1315 // TODO(ricea): Restore the code for WebSockets over SPDY once it's | 1329 // TODO(ricea): Restore the code for WebSockets over SPDY once it's |
1316 // implemented. | 1330 // implemented. |
1317 if (stream_factory_->for_websockets_) | 1331 if (stream_factory_->for_websockets_) |
1318 return ERR_NOT_IMPLEMENTED; | 1332 return ERR_NOT_IMPLEMENTED; |
1319 if (for_bidirectional_) { | 1333 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
1320 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | 1334 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
1321 // TODO(xunjieli): Create QUIC's version of BidirectionalStreamJob. | |
1322 bidirectional_stream_job_.reset(new BidirectionalStreamSpdyJob(session)); | 1335 bidirectional_stream_job_.reset(new BidirectionalStreamSpdyJob(session)); |
1323 return OK; | 1336 return OK; |
1324 #else | 1337 #else |
1325 DCHECK(false); | 1338 NOTREACHED(); |
1326 return ERR_FAILED; | 1339 return ERR_FAILED; |
1327 #endif | 1340 #endif |
1328 } | 1341 } |
1329 | 1342 |
1330 // TODO(willchan): Delete this code, because eventually, the | 1343 // TODO(willchan): Delete this code, because eventually, the |
1331 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1344 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
1332 // will know when SpdySessions become available. | 1345 // will know when SpdySessions become available. |
1333 | 1346 |
1334 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1347 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); |
1335 stream_.reset(new SpdyHttpStream(session, use_relative_url)); | 1348 stream_.reset(new SpdyHttpStream(session, use_relative_url)); |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 if (connection_->socket()) { | 1816 if (connection_->socket()) { |
1804 ConnectionAttempts socket_attempts; | 1817 ConnectionAttempts socket_attempts; |
1805 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1818 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
1806 request_->AddConnectionAttempts(socket_attempts); | 1819 request_->AddConnectionAttempts(socket_attempts); |
1807 } else { | 1820 } else { |
1808 request_->AddConnectionAttempts(connection_->connection_attempts()); | 1821 request_->AddConnectionAttempts(connection_->connection_attempts()); |
1809 } | 1822 } |
1810 } | 1823 } |
1811 | 1824 |
1812 } // namespace net | 1825 } // namespace net |
OLD | NEW |