| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 const std::string* proto, | 146 const std::string* proto, |
| 147 NetLogCaptureMode /* capture_mode */) { | 147 NetLogCaptureMode /* capture_mode */) { |
| 148 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 148 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 149 | 149 |
| 150 dict->SetString("next_proto_status", | 150 dict->SetString("next_proto_status", |
| 151 SSLClientSocket::NextProtoStatusToString(status)); | 151 SSLClientSocket::NextProtoStatusToString(status)); |
| 152 dict->SetString("proto", *proto); | 152 dict->SetString("proto", *proto); |
| 153 return std::move(dict); | 153 return std::move(dict); |
| 154 } | 154 } |
| 155 | 155 |
| 156 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, | 156 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, |
| 157 JobType job_type, | |
| 158 HttpNetworkSession* session, | 157 HttpNetworkSession* session, |
| 159 const HttpRequestInfo& request_info, | 158 const HttpRequestInfo& request_info, |
| 160 RequestPriority priority, | 159 RequestPriority priority, |
| 161 const SSLConfig& server_ssl_config, | 160 const SSLConfig& server_ssl_config, |
| 162 const SSLConfig& proxy_ssl_config, | 161 const SSLConfig& proxy_ssl_config, |
| 163 HostPortPair destination, | 162 HostPortPair destination, |
| 164 GURL origin_url, | 163 GURL origin_url, |
| 165 NetLog* net_log) | 164 NetLog* net_log) |
| 166 : Job(delegate, | 165 : Job(stream_factory, |
| 167 job_type, | |
| 168 session, | 166 session, |
| 169 request_info, | 167 request_info, |
| 170 priority, | 168 priority, |
| 171 server_ssl_config, | 169 server_ssl_config, |
| 172 proxy_ssl_config, | 170 proxy_ssl_config, |
| 173 destination, | 171 destination, |
| 174 origin_url, | 172 origin_url, |
| 175 AlternativeService(), | 173 AlternativeService(), |
| 176 net_log) {} | 174 net_log) {} |
| 177 | 175 |
| 178 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, | 176 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, |
| 179 JobType job_type, | |
| 180 HttpNetworkSession* session, | 177 HttpNetworkSession* session, |
| 181 const HttpRequestInfo& request_info, | 178 const HttpRequestInfo& request_info, |
| 182 RequestPriority priority, | 179 RequestPriority priority, |
| 183 const SSLConfig& server_ssl_config, | 180 const SSLConfig& server_ssl_config, |
| 184 const SSLConfig& proxy_ssl_config, | 181 const SSLConfig& proxy_ssl_config, |
| 185 HostPortPair destination, | 182 HostPortPair destination, |
| 186 GURL origin_url, | 183 GURL origin_url, |
| 187 AlternativeService alternative_service, | 184 AlternativeService alternative_service, |
| 188 NetLog* net_log) | 185 NetLog* net_log) |
| 189 : request_info_(request_info), | 186 : request_(NULL), |
| 187 request_info_(request_info), |
| 190 priority_(priority), | 188 priority_(priority), |
| 191 server_ssl_config_(server_ssl_config), | 189 server_ssl_config_(server_ssl_config), |
| 192 proxy_ssl_config_(proxy_ssl_config), | 190 proxy_ssl_config_(proxy_ssl_config), |
| 193 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), | 191 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), |
| 194 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), | 192 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), |
| 195 connection_(new ClientSocketHandle), | 193 connection_(new ClientSocketHandle), |
| 196 session_(session), | 194 session_(session), |
| 195 stream_factory_(stream_factory), |
| 197 next_state_(STATE_NONE), | 196 next_state_(STATE_NONE), |
| 198 pac_request_(NULL), | 197 pac_request_(NULL), |
| 199 destination_(destination), | 198 destination_(destination), |
| 200 origin_url_(origin_url), | 199 origin_url_(origin_url), |
| 201 alternative_service_(alternative_service), | 200 alternative_service_(alternative_service), |
| 202 delegate_(delegate), | |
| 203 job_type_(job_type), | |
| 204 blocking_job_(NULL), | 201 blocking_job_(NULL), |
| 205 waiting_job_(NULL), | 202 waiting_job_(NULL), |
| 206 using_ssl_(false), | 203 using_ssl_(false), |
| 207 using_spdy_(false), | 204 using_spdy_(false), |
| 208 using_quic_(false), | 205 using_quic_(false), |
| 209 quic_request_(session_->quic_stream_factory()), | 206 quic_request_(session_->quic_stream_factory()), |
| 210 using_existing_quic_session_(false), | 207 using_existing_quic_session_(false), |
| 211 spdy_certificate_error_(OK), | 208 spdy_certificate_error_(OK), |
| 212 establishing_tunnel_(false), | 209 establishing_tunnel_(false), |
| 213 was_npn_negotiated_(false), | 210 was_npn_negotiated_(false), |
| 214 protocol_negotiated_(kProtoUnknown), | 211 protocol_negotiated_(kProtoUnknown), |
| 215 num_streams_(0), | 212 num_streams_(0), |
| 216 spdy_session_direct_(false), | 213 spdy_session_direct_(false), |
| 217 job_status_(STATUS_RUNNING), | 214 job_status_(STATUS_RUNNING), |
| 218 other_job_status_(STATUS_RUNNING), | 215 other_job_status_(STATUS_RUNNING), |
| 219 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), | 216 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), |
| 220 ptr_factory_(this) { | 217 ptr_factory_(this) { |
| 218 DCHECK(stream_factory); |
| 221 DCHECK(session); | 219 DCHECK(session); |
| 222 if (IsSpdyAlternative() && | 220 if (IsSpdyAlternative() && |
| 223 !session_->params().enable_alternative_service_for_insecure_origins) { | 221 !session_->params().enable_alternative_service_for_insecure_origins) { |
| 224 DCHECK(origin_url_.SchemeIs("https")); | 222 DCHECK(origin_url_.SchemeIs("https")); |
| 225 } | 223 } |
| 226 if (IsQuicAlternative()) { | 224 if (IsQuicAlternative()) { |
| 227 DCHECK(session_->params().enable_quic); | 225 DCHECK(session_->params().enable_quic); |
| 228 using_quic_ = true; | 226 using_quic_ = true; |
| 229 } | 227 } |
| 230 } | 228 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 241 } | 239 } |
| 242 | 240 |
| 243 if (pac_request_) | 241 if (pac_request_) |
| 244 session_->proxy_service()->CancelPacRequest(pac_request_); | 242 session_->proxy_service()->CancelPacRequest(pac_request_); |
| 245 | 243 |
| 246 // The stream could be in a partial state. It is not reusable. | 244 // The stream could be in a partial state. It is not reusable. |
| 247 if (stream_.get() && next_state_ != STATE_DONE) | 245 if (stream_.get() && next_state_ != STATE_DONE) |
| 248 stream_->Close(true /* not reusable */); | 246 stream_->Close(true /* not reusable */); |
| 249 } | 247 } |
| 250 | 248 |
| 251 void HttpStreamFactoryImpl::Job::Start( | 249 void HttpStreamFactoryImpl::Job::Start(Request* request) { |
| 252 HttpStreamRequest::StreamType stream_type) { | 250 DCHECK(request); |
| 253 stream_type_ = stream_type; | 251 request_ = request; |
| 252 // Saves |stream_type_|, since request is nulled when job is orphaned. |
| 253 stream_type_ = request_->stream_type(); |
| 254 StartInternal(); | 254 StartInternal(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) { | 257 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) { |
| 258 DCHECK_GT(num_streams, 0); | 258 DCHECK_GT(num_streams, 0); |
| 259 base::WeakPtr<HttpServerProperties> http_server_properties = | 259 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 260 session_->http_server_properties(); | 260 session_->http_server_properties(); |
| 261 if (http_server_properties && | 261 if (http_server_properties && |
| 262 http_server_properties->SupportsRequestPriority( | 262 http_server_properties->SupportsRequestPriority( |
| 263 url::SchemeHostPort(request_info_.url))) { | 263 url::SchemeHostPort(request_info_.url))) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // be delayed by the |wait_time_| when it resumes. | 322 // be delayed by the |wait_time_| when it resumes. |
| 323 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE) | 323 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE) |
| 324 wait_time_ = delay; | 324 wait_time_ = delay; |
| 325 | 325 |
| 326 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. | 326 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. |
| 327 // Unblock |this|. | 327 // Unblock |this|. |
| 328 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) | 328 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) |
| 329 ResumeAfterDelay(); | 329 ResumeAfterDelay(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void HttpStreamFactoryImpl::Job::Orphan() { | 332 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { |
| 333 DCHECK_EQ(request_, request); |
| 334 request_ = NULL; |
| 333 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); | 335 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); |
| 334 if (blocking_job_) { | 336 if (blocking_job_) { |
| 335 // We've been orphaned, but there's a job we're blocked on. Don't bother | 337 // We've been orphaned, but there's a job we're blocked on. Don't bother |
| 336 // racing, just cancel ourself. | 338 // racing, just cancel ourself. |
| 337 DCHECK(blocking_job_->waiting_job_); | 339 DCHECK(blocking_job_->waiting_job_); |
| 338 blocking_job_->waiting_job_ = NULL; | 340 blocking_job_->waiting_job_ = NULL; |
| 339 blocking_job_ = NULL; | 341 blocking_job_ = NULL; |
| 340 if (delegate_->for_websockets() && connection_ && connection_->socket()) { | 342 if (stream_factory_->for_websockets_ && |
| 343 connection_ && connection_->socket()) { |
| 341 connection_->socket()->Disconnect(); | 344 connection_->socket()->Disconnect(); |
| 342 } | 345 } |
| 343 delegate_->OnOrphanedJobComplete(this); | 346 stream_factory_->OnOrphanedJobComplete(this); |
| 344 } else if (delegate_->for_websockets()) { | 347 } else if (stream_factory_->for_websockets_) { |
| 345 // We cancel this job because a WebSocketHandshakeStream can't be created | 348 // We cancel this job because a WebSocketHandshakeStream can't be created |
| 346 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in | 349 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in |
| 347 // the Request class and isn't retrievable by this job. | 350 // the Request class and isn't accessible from this job. |
| 348 if (connection_ && connection_->socket()) { | 351 if (connection_ && connection_->socket()) { |
| 349 connection_->socket()->Disconnect(); | 352 connection_->socket()->Disconnect(); |
| 350 } | 353 } |
| 351 delegate_->OnOrphanedJobComplete(this); | 354 stream_factory_->OnOrphanedJobComplete(this); |
| 352 } | 355 } |
| 353 // |this| may be deleted after this call. | |
| 354 } | 356 } |
| 355 | 357 |
| 356 void HttpStreamFactoryImpl::Job::SetPriority(RequestPriority priority) { | 358 void HttpStreamFactoryImpl::Job::SetPriority(RequestPriority priority) { |
| 357 priority_ = priority; | 359 priority_ = priority; |
| 358 // TODO(akalin): Propagate this to |connection_| and maybe the | 360 // TODO(akalin): Propagate this to |connection_| and maybe the |
| 359 // preconnect state. | 361 // preconnect state. |
| 360 } | 362 } |
| 361 | 363 |
| 362 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const { | 364 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const { |
| 363 return was_npn_negotiated_; | 365 return was_npn_negotiated_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // https (the normal case) or if we're connection to a SPDY proxy. | 413 // https (the normal case) or if we're connection to a SPDY proxy. |
| 412 // https://crbug.com/133176 | 414 // https://crbug.com/133176 |
| 413 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is | 415 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is |
| 414 // working. | 416 // working. |
| 415 return origin_url_.SchemeIs("https") || | 417 return origin_url_.SchemeIs("https") || |
| 416 proxy_info_.proxy_server().is_https() || IsSpdyAlternative(); | 418 proxy_info_.proxy_server().is_https() || IsSpdyAlternative(); |
| 417 } | 419 } |
| 418 | 420 |
| 419 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { | 421 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { |
| 420 DCHECK(stream_.get()); | 422 DCHECK(stream_.get()); |
| 421 DCHECK_NE(job_type_, PRECONNECT); | 423 DCHECK(!IsPreconnecting()); |
| 422 DCHECK(!delegate_->for_websockets()); | 424 DCHECK(!stream_factory_->for_websockets_); |
| 423 | 425 |
| 424 UMA_HISTOGRAM_TIMES("Net.HttpStreamFactoryJob.StreamReadyCallbackTime", | 426 UMA_HISTOGRAM_TIMES("Net.HttpStreamFactoryJob.StreamReadyCallbackTime", |
| 425 base::TimeTicks::Now() - job_stream_ready_start_time_); | 427 base::TimeTicks::Now() - job_stream_ready_start_time_); |
| 426 | 428 |
| 427 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 429 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
| 428 | 430 |
| 429 delegate_->OnStreamReady(this, server_ssl_config_, proxy_info_); | 431 if (IsOrphaned()) { |
| 432 stream_factory_->OnOrphanedJobComplete(this); |
| 433 } else { |
| 434 request_->Complete(was_npn_negotiated(), protocol_negotiated(), |
| 435 using_spdy()); |
| 436 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, |
| 437 stream_.release()); |
| 438 } |
| 430 // |this| may be deleted after this call. | 439 // |this| may be deleted after this call. |
| 431 } | 440 } |
| 432 | 441 |
| 433 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() { | 442 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() { |
| 434 DCHECK(websocket_stream_); | 443 DCHECK(websocket_stream_); |
| 435 DCHECK_NE(job_type_, PRECONNECT); | 444 DCHECK(!IsPreconnecting()); |
| 436 DCHECK(delegate_->for_websockets()); | 445 DCHECK(stream_factory_->for_websockets_); |
| 446 // An orphaned WebSocket job will be closed immediately and |
| 447 // never be ready. |
| 448 DCHECK(!IsOrphaned()); |
| 437 | 449 |
| 438 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 450 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
| 439 | 451 |
| 440 delegate_->OnWebSocketHandshakeStreamReady( | 452 request_->Complete(was_npn_negotiated(), protocol_negotiated(), using_spdy()); |
| 441 this, server_ssl_config_, proxy_info_, websocket_stream_.release()); | 453 request_->OnWebSocketHandshakeStreamReady(this, |
| 454 server_ssl_config_, |
| 455 proxy_info_, |
| 456 websocket_stream_.release()); |
| 442 // |this| may be deleted after this call. | 457 // |this| may be deleted after this call. |
| 443 } | 458 } |
| 444 | 459 |
| 445 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamImplReadyCallback() { | 460 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamImplReadyCallback() { |
| 446 DCHECK(bidirectional_stream_impl_); | 461 DCHECK(bidirectional_stream_impl_); |
| 447 | 462 |
| 448 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 463 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
| 449 | 464 |
| 450 delegate_->OnBidirectionalStreamImplReady(this, server_ssl_config_, | 465 if (IsOrphaned()) { |
| 451 proxy_info_); | 466 stream_factory_->OnOrphanedJobComplete(this); |
| 452 // |this| may be deleted after this call. | 467 } else { |
| 468 request_->Complete(was_npn_negotiated(), protocol_negotiated(), |
| 469 using_spdy()); |
| 470 request_->OnBidirectionalStreamImplReady( |
| 471 this, server_ssl_config_, proxy_info_, |
| 472 bidirectional_stream_impl_.release()); |
| 473 } |
| 474 // |this| may be deleted after this call. |
| 453 } | 475 } |
| 454 | 476 |
| 455 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { | 477 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { |
| 456 DCHECK(stream_.get() || bidirectional_stream_impl_.get()); | 478 DCHECK(stream_.get() || bidirectional_stream_impl_.get()); |
| 457 DCHECK_NE(job_type_, PRECONNECT); | 479 DCHECK(!IsPreconnecting()); |
| 458 DCHECK(using_spdy()); | 480 DCHECK(using_spdy()); |
| 459 // Note: an event loop iteration has passed, so |new_spdy_session_| may be | 481 // Note: an event loop iteration has passed, so |new_spdy_session_| may be |
| 460 // NULL at this point if the SpdySession closed immediately after creation. | 482 // NULL at this point if the SpdySession closed immediately after creation. |
| 461 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; | 483 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; |
| 462 new_spdy_session_.reset(); | 484 new_spdy_session_.reset(); |
| 463 | 485 |
| 464 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 486 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
| 465 | 487 |
| 466 delegate_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_); | 488 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, |
| 467 | 489 // rather than notifying |request_| directly. |
| 490 if (IsOrphaned()) { |
| 491 if (spdy_session) { |
| 492 stream_factory_->OnNewSpdySessionReady( |
| 493 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, |
| 494 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); |
| 495 } |
| 496 stream_factory_->OnOrphanedJobComplete(this); |
| 497 } else { |
| 498 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 499 DCHECK(bidirectional_stream_impl_); |
| 500 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr, |
| 501 std::move(bidirectional_stream_impl_), |
| 502 spdy_session, spdy_session_direct_); |
| 503 } else { |
| 504 DCHECK(stream_); |
| 505 request_->OnNewSpdySessionReady(this, std::move(stream_), |
| 506 /** bidirectional_stream_impl=*/nullptr, |
| 507 spdy_session, spdy_session_direct_); |
| 508 } |
| 509 } |
| 468 // |this| may be deleted after this call. | 510 // |this| may be deleted after this call. |
| 469 } | 511 } |
| 470 | 512 |
| 471 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { | 513 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { |
| 472 DCHECK_NE(job_type_, PRECONNECT); | 514 DCHECK(!IsPreconnecting()); |
| 473 | 515 |
| 474 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 516 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
| 475 | 517 |
| 476 SSLFailureState ssl_failure_state = | 518 if (IsOrphaned()) { |
| 477 connection_ ? connection_->ssl_failure_state() : SSL_FAILURE_NONE; | 519 stream_factory_->OnOrphanedJobComplete(this); |
| 478 | 520 } else { |
| 479 delegate_->OnStreamFailed(this, result, server_ssl_config_, | 521 SSLFailureState ssl_failure_state = |
| 480 ssl_failure_state); | 522 connection_ ? connection_->ssl_failure_state() : SSL_FAILURE_NONE; |
| 523 request_->OnStreamFailed(this, result, server_ssl_config_, |
| 524 ssl_failure_state); |
| 525 } |
| 481 // |this| may be deleted after this call. | 526 // |this| may be deleted after this call. |
| 482 } | 527 } |
| 483 | 528 |
| 484 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback( | 529 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback( |
| 485 int result, const SSLInfo& ssl_info) { | 530 int result, const SSLInfo& ssl_info) { |
| 486 DCHECK_NE(job_type_, PRECONNECT); | 531 DCHECK(!IsPreconnecting()); |
| 487 | 532 |
| 488 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 533 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
| 489 | 534 |
| 490 delegate_->OnCertificateError(this, result, server_ssl_config_, ssl_info); | 535 if (IsOrphaned()) |
| 536 stream_factory_->OnOrphanedJobComplete(this); |
| 537 else |
| 538 request_->OnCertificateError(this, result, server_ssl_config_, ssl_info); |
| 491 // |this| may be deleted after this call. | 539 // |this| may be deleted after this call. |
| 492 } | 540 } |
| 493 | 541 |
| 494 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback( | 542 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback( |
| 495 const HttpResponseInfo& response, | 543 const HttpResponseInfo& response, |
| 496 HttpAuthController* auth_controller) { | 544 HttpAuthController* auth_controller) { |
| 497 DCHECK_NE(job_type_, PRECONNECT); | 545 DCHECK(!IsPreconnecting()); |
| 498 | 546 if (IsOrphaned()) |
| 499 delegate_->OnNeedsProxyAuth(this, response, server_ssl_config_, proxy_info_, | 547 stream_factory_->OnOrphanedJobComplete(this); |
| 500 auth_controller); | 548 else |
| 549 request_->OnNeedsProxyAuth( |
| 550 this, response, server_ssl_config_, proxy_info_, auth_controller); |
| 501 // |this| may be deleted after this call. | 551 // |this| may be deleted after this call. |
| 502 } | 552 } |
| 503 | 553 |
| 504 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( | 554 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( |
| 505 SSLCertRequestInfo* cert_info) { | 555 SSLCertRequestInfo* cert_info) { |
| 506 DCHECK_NE(job_type_, PRECONNECT); | 556 DCHECK(!IsPreconnecting()); |
| 507 | 557 if (IsOrphaned()) |
| 508 delegate_->OnNeedsClientAuth(this, server_ssl_config_, cert_info); | 558 stream_factory_->OnOrphanedJobComplete(this); |
| 559 else |
| 560 request_->OnNeedsClientAuth(this, server_ssl_config_, cert_info); |
| 509 // |this| may be deleted after this call. | 561 // |this| may be deleted after this call. |
| 510 } | 562 } |
| 511 | 563 |
| 512 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback( | 564 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback( |
| 513 const HttpResponseInfo& response_info, | 565 const HttpResponseInfo& response_info, |
| 514 HttpStream* stream) { | 566 HttpStream* stream) { |
| 515 DCHECK_NE(job_type_, PRECONNECT); | 567 DCHECK(!IsPreconnecting()); |
| 516 | 568 if (IsOrphaned()) |
| 517 delegate_->OnHttpsProxyTunnelResponse(this, response_info, server_ssl_config_, | 569 stream_factory_->OnOrphanedJobComplete(this); |
| 518 proxy_info_, stream); | 570 else |
| 571 request_->OnHttpsProxyTunnelResponse( |
| 572 this, response_info, server_ssl_config_, proxy_info_, stream); |
| 519 // |this| may be deleted after this call. | 573 // |this| may be deleted after this call. |
| 520 } | 574 } |
| 521 | 575 |
| 522 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { | 576 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { |
| 577 DCHECK(!request_); |
| 523 if (new_spdy_session_.get()) { | 578 if (new_spdy_session_.get()) { |
| 524 delegate_->OnNewSpdySessionReady(this, new_spdy_session_, | 579 stream_factory_->OnNewSpdySessionReady(new_spdy_session_, |
| 525 spdy_session_direct_); | 580 spdy_session_direct_, |
| 581 server_ssl_config_, |
| 582 proxy_info_, |
| 583 was_npn_negotiated(), |
| 584 protocol_negotiated(), |
| 585 using_spdy(), |
| 586 net_log_); |
| 526 } | 587 } |
| 527 delegate_->OnPreconnectsComplete(this); | 588 stream_factory_->OnPreconnectsComplete(this); |
| 528 // |this| may be deleted after this call. | 589 // |this| may be deleted after this call. |
| 529 } | 590 } |
| 530 | 591 |
| 531 // static | 592 // static |
| 532 int HttpStreamFactoryImpl::Job::OnHostResolution( | 593 int HttpStreamFactoryImpl::Job::OnHostResolution( |
| 533 SpdySessionPool* spdy_session_pool, | 594 SpdySessionPool* spdy_session_pool, |
| 534 const SpdySessionKey& spdy_session_key, | 595 const SpdySessionKey& spdy_session_key, |
| 535 const GURL& origin_url, | 596 const GURL& origin_url, |
| 536 const AddressList& addresses, | 597 const AddressList& addresses, |
| 537 const BoundNetLog& net_log) { | 598 const BoundNetLog& net_log) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 555 "HttpStreamFactoryImpl::Job::RunLoop"); | 616 "HttpStreamFactoryImpl::Job::RunLoop"); |
| 556 result = DoLoop(result); | 617 result = DoLoop(result); |
| 557 | 618 |
| 558 if (result == ERR_IO_PENDING) | 619 if (result == ERR_IO_PENDING) |
| 559 return result; | 620 return result; |
| 560 | 621 |
| 561 // If there was an error, we should have already resumed the |waiting_job_|, | 622 // If there was an error, we should have already resumed the |waiting_job_|, |
| 562 // if there was one. | 623 // if there was one. |
| 563 DCHECK(result == OK || waiting_job_ == NULL); | 624 DCHECK(result == OK || waiting_job_ == NULL); |
| 564 | 625 |
| 565 if (job_type_ == PRECONNECT) { | 626 if (IsPreconnecting()) { |
| 566 base::ThreadTaskRunnerHandle::Get()->PostTask( | 627 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 567 FROM_HERE, | 628 FROM_HERE, |
| 568 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, | 629 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, |
| 569 ptr_factory_.GetWeakPtr())); | 630 ptr_factory_.GetWeakPtr())); |
| 570 return ERR_IO_PENDING; | 631 return ERR_IO_PENDING; |
| 571 } | 632 } |
| 572 | 633 |
| 573 if (IsCertificateError(result)) { | 634 if (IsCertificateError(result)) { |
| 574 // Retrieve SSL information from the socket. | 635 // Retrieve SSL information from the socket. |
| 575 GetSSLInfo(); | 636 GetSSLInfo(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 } | 688 } |
| 628 | 689 |
| 629 case OK: | 690 case OK: |
| 630 job_status_ = STATUS_SUCCEEDED; | 691 job_status_ = STATUS_SUCCEEDED; |
| 631 MaybeMarkAlternativeServiceBroken(); | 692 MaybeMarkAlternativeServiceBroken(); |
| 632 next_state_ = STATE_DONE; | 693 next_state_ = STATE_DONE; |
| 633 if (new_spdy_session_.get()) { | 694 if (new_spdy_session_.get()) { |
| 634 base::ThreadTaskRunnerHandle::Get()->PostTask( | 695 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 635 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, | 696 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, |
| 636 ptr_factory_.GetWeakPtr())); | 697 ptr_factory_.GetWeakPtr())); |
| 637 } else if (delegate_->for_websockets()) { | 698 } else if (stream_factory_->for_websockets_) { |
| 638 DCHECK(websocket_stream_); | 699 DCHECK(websocket_stream_); |
| 639 base::ThreadTaskRunnerHandle::Get()->PostTask( | 700 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 640 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, | 701 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, |
| 641 ptr_factory_.GetWeakPtr())); | 702 ptr_factory_.GetWeakPtr())); |
| 642 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 703 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 643 if (!bidirectional_stream_impl_) { | 704 if (!bidirectional_stream_impl_) { |
| 644 base::ThreadTaskRunnerHandle::Get()->PostTask( | 705 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 645 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, | 706 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, |
| 646 ptr_factory_.GetWeakPtr(), ERR_FAILED)); | 707 ptr_factory_.GetWeakPtr(), ERR_FAILED)); |
| 647 } else { | 708 } else { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 CHECK_EQ(STATE_NONE, next_state_); | 800 CHECK_EQ(STATE_NONE, next_state_); |
| 740 next_state_ = STATE_START; | 801 next_state_ = STATE_START; |
| 741 int rv = RunLoop(OK); | 802 int rv = RunLoop(OK); |
| 742 DCHECK_EQ(ERR_IO_PENDING, rv); | 803 DCHECK_EQ(ERR_IO_PENDING, rv); |
| 743 return rv; | 804 return rv; |
| 744 } | 805 } |
| 745 | 806 |
| 746 int HttpStreamFactoryImpl::Job::DoStart() { | 807 int HttpStreamFactoryImpl::Job::DoStart() { |
| 747 valid_spdy_session_pool_.reset(new ValidSpdySessionPool( | 808 valid_spdy_session_pool_.reset(new ValidSpdySessionPool( |
| 748 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative())); | 809 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative())); |
| 749 const BoundNetLog* net_log = delegate_->GetNetLog(this); | |
| 750 | 810 |
| 751 if (net_log) { | 811 net_log_.BeginEvent( |
| 752 net_log_.BeginEvent( | 812 NetLog::TYPE_HTTP_STREAM_JOB, |
| 753 NetLog::TYPE_HTTP_STREAM_JOB, | 813 base::Bind(&NetLogHttpStreamJobCallback, |
| 754 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(), | 814 request_ ? request_->net_log().source() : NetLog::Source(), |
| 755 &request_info_.url, &origin_url_, &alternative_service_, | 815 &request_info_.url, &origin_url_, &alternative_service_, |
| 756 priority_)); | 816 priority_)); |
| 757 net_log->AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, | 817 if (request_) { |
| 758 net_log_.source().ToEventParametersCallback()); | 818 request_->net_log().AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, |
| 819 net_log_.source().ToEventParametersCallback()); |
| 759 } | 820 } |
| 760 | 821 |
| 761 // Don't connect to restricted ports. | 822 // Don't connect to restricted ports. |
| 762 if (!IsPortAllowedForScheme(destination_.port(), | 823 if (!IsPortAllowedForScheme(destination_.port(), |
| 763 request_info_.url.scheme())) { | 824 request_info_.url.scheme())) { |
| 764 if (waiting_job_) { | 825 if (waiting_job_) { |
| 765 waiting_job_->Resume(this, base::TimeDelta()); | 826 waiting_job_->Resume(this, base::TimeDelta()); |
| 766 waiting_job_ = NULL; | 827 waiting_job_ = NULL; |
| 767 } | 828 } |
| 768 return ERR_UNSAFE_PORT; | 829 return ERR_UNSAFE_PORT; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 // straight to using that. | 1044 // straight to using that. |
| 984 if (CanUseExistingSpdySession()) { | 1045 if (CanUseExistingSpdySession()) { |
| 985 base::WeakPtr<SpdySession> spdy_session; | 1046 base::WeakPtr<SpdySession> spdy_session; |
| 986 int result = valid_spdy_session_pool_->FindAvailableSession( | 1047 int result = valid_spdy_session_pool_->FindAvailableSession( |
| 987 spdy_session_key, net_log_, &spdy_session); | 1048 spdy_session_key, net_log_, &spdy_session); |
| 988 if (result != OK) | 1049 if (result != OK) |
| 989 return result; | 1050 return result; |
| 990 if (spdy_session) { | 1051 if (spdy_session) { |
| 991 // If we're preconnecting, but we already have a SpdySession, we don't | 1052 // If we're preconnecting, but we already have a SpdySession, we don't |
| 992 // actually need to preconnect any sockets, so we're done. | 1053 // actually need to preconnect any sockets, so we're done. |
| 993 if (job_type_ == PRECONNECT) | 1054 if (IsPreconnecting()) |
| 994 return OK; | 1055 return OK; |
| 995 using_spdy_ = true; | 1056 using_spdy_ = true; |
| 996 next_state_ = STATE_CREATE_STREAM; | 1057 next_state_ = STATE_CREATE_STREAM; |
| 997 existing_spdy_session_ = spdy_session; | 1058 existing_spdy_session_ = spdy_session; |
| 998 return OK; | 1059 return OK; |
| 999 } | 1060 } |
| 1000 } | 1061 } |
| 1001 if (using_ssl_) { | 1062 if (request_ && !request_->HasSpdySessionKey() && using_ssl_) { |
| 1002 // Ask |delegate_delegate_| to update the spdy session key for the request | 1063 // Update the spdy session key for the request that launched this job. |
| 1003 // that launched this job. | 1064 request_->SetSpdySessionKey(spdy_session_key); |
| 1004 delegate_->SetSpdySessionKey(this, spdy_session_key); | |
| 1005 } | 1065 } |
| 1006 | 1066 |
| 1007 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's | 1067 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's |
| 1008 // paused. | 1068 // paused. |
| 1009 if (waiting_job_) { | 1069 if (waiting_job_) { |
| 1010 waiting_job_->Resume(this, base::TimeDelta()); | 1070 waiting_job_->Resume(this, base::TimeDelta()); |
| 1011 waiting_job_ = NULL; | 1071 waiting_job_ = NULL; |
| 1012 } | 1072 } |
| 1013 | 1073 |
| 1014 if (proxy_info_.is_http() || proxy_info_.is_https()) | 1074 if (proxy_info_.is_http() || proxy_info_.is_https()) |
| 1015 establishing_tunnel_ = using_ssl_; | 1075 establishing_tunnel_ = using_ssl_; |
| 1016 | 1076 |
| 1017 const bool expect_spdy = IsSpdyAlternative(); | 1077 const bool expect_spdy = IsSpdyAlternative(); |
| 1018 | 1078 |
| 1019 base::WeakPtr<HttpServerProperties> http_server_properties = | 1079 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 1020 session_->http_server_properties(); | 1080 session_->http_server_properties(); |
| 1021 if (http_server_properties) { | 1081 if (http_server_properties) { |
| 1022 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); | 1082 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); |
| 1023 if (proxy_info_.is_http() || proxy_info_.is_https()) { | 1083 if (proxy_info_.is_http() || proxy_info_.is_https()) { |
| 1024 http_server_properties->MaybeForceHTTP11( | 1084 http_server_properties->MaybeForceHTTP11( |
| 1025 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_); | 1085 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_); |
| 1026 } | 1086 } |
| 1027 } | 1087 } |
| 1028 | 1088 |
| 1029 if (job_type_ == PRECONNECT) { | 1089 if (IsPreconnecting()) { |
| 1030 DCHECK(!delegate_->for_websockets()); | 1090 DCHECK(!stream_factory_->for_websockets_); |
| 1031 return PreconnectSocketsForHttpRequest( | 1091 return PreconnectSocketsForHttpRequest( |
| 1032 GetSocketGroup(), destination_, request_info_.extra_headers, | 1092 GetSocketGroup(), destination_, request_info_.extra_headers, |
| 1033 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, | 1093 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, |
| 1034 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, | 1094 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, |
| 1035 net_log_, num_streams_); | 1095 net_log_, num_streams_); |
| 1036 } | 1096 } |
| 1037 | 1097 |
| 1038 // If we can't use a SPDY session, don't bother checking for one after | 1098 // If we can't use a SPDY session, don't bother checking for one after |
| 1039 // the hostname is resolved. | 1099 // the hostname is resolved. |
| 1040 OnHostResolutionCallback resolution_callback = | 1100 OnHostResolutionCallback resolution_callback = |
| 1041 CanUseExistingSpdySession() | 1101 CanUseExistingSpdySession() |
| 1042 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), | 1102 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), |
| 1043 spdy_session_key, origin_url_) | 1103 spdy_session_key, origin_url_) |
| 1044 : OnHostResolutionCallback(); | 1104 : OnHostResolutionCallback(); |
| 1045 if (delegate_->for_websockets()) { | 1105 if (stream_factory_->for_websockets_) { |
| 1046 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. | 1106 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. |
| 1047 SSLConfig websocket_server_ssl_config = server_ssl_config_; | 1107 SSLConfig websocket_server_ssl_config = server_ssl_config_; |
| 1048 websocket_server_ssl_config.alpn_protos.clear(); | 1108 websocket_server_ssl_config.alpn_protos.clear(); |
| 1049 websocket_server_ssl_config.npn_protos.clear(); | 1109 websocket_server_ssl_config.npn_protos.clear(); |
| 1050 return InitSocketHandleForWebSocketRequest( | 1110 return InitSocketHandleForWebSocketRequest( |
| 1051 GetSocketGroup(), destination_, request_info_.extra_headers, | 1111 GetSocketGroup(), destination_, request_info_.extra_headers, |
| 1052 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, | 1112 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, |
| 1053 websocket_server_ssl_config, proxy_ssl_config_, | 1113 websocket_server_ssl_config, proxy_ssl_config_, |
| 1054 request_info_.privacy_mode, net_log_, connection_.get(), | 1114 request_info_.privacy_mode, net_log_, connection_.get(), |
| 1055 resolution_callback, io_callback_); | 1115 resolution_callback, io_callback_); |
| 1056 } | 1116 } |
| 1057 | 1117 |
| 1058 return InitSocketHandleForHttpRequest( | 1118 return InitSocketHandleForHttpRequest( |
| 1059 GetSocketGroup(), destination_, request_info_.extra_headers, | 1119 GetSocketGroup(), destination_, request_info_.extra_headers, |
| 1060 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, | 1120 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, |
| 1061 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, | 1121 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, |
| 1062 net_log_, connection_.get(), resolution_callback, io_callback_); | 1122 net_log_, connection_.get(), resolution_callback, io_callback_); |
| 1063 } | 1123 } |
| 1064 | 1124 |
| 1065 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 1125 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
| 1066 if (using_quic_ && result < 0 && waiting_job_) { | 1126 if (using_quic_ && result < 0 && waiting_job_) { |
| 1067 waiting_job_->Resume(this, base::TimeDelta()); | 1127 waiting_job_->Resume(this, base::TimeDelta()); |
| 1068 waiting_job_ = NULL; | 1128 waiting_job_ = NULL; |
| 1069 } | 1129 } |
| 1070 if (job_type_ == PRECONNECT) { | 1130 if (IsPreconnecting()) { |
| 1071 if (using_quic_) | 1131 if (using_quic_) |
| 1072 return result; | 1132 return result; |
| 1073 DCHECK_EQ(OK, result); | 1133 DCHECK_EQ(OK, result); |
| 1074 return OK; | 1134 return OK; |
| 1075 } | 1135 } |
| 1076 | 1136 |
| 1077 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { | 1137 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { |
| 1078 // We found a SPDY connection after resolving the host. This is | 1138 // We found a SPDY connection after resolving the host. This is |
| 1079 // probably an IP pooled connection. | 1139 // probably an IP pooled connection. |
| 1080 SpdySessionKey spdy_session_key = GetSpdySessionKey(); | 1140 SpdySessionKey spdy_session_key = GetSpdySessionKey(); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 | 1305 |
| 1246 // We're always waiting here for the delegate to call us back. | 1306 // We're always waiting here for the delegate to call us back. |
| 1247 return ERR_IO_PENDING; | 1307 return ERR_IO_PENDING; |
| 1248 } | 1308 } |
| 1249 | 1309 |
| 1250 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl( | 1310 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl( |
| 1251 base::WeakPtr<SpdySession> session, | 1311 base::WeakPtr<SpdySession> session, |
| 1252 bool direct) { | 1312 bool direct) { |
| 1253 // TODO(ricea): Restore the code for WebSockets over SPDY once it's | 1313 // TODO(ricea): Restore the code for WebSockets over SPDY once it's |
| 1254 // implemented. | 1314 // implemented. |
| 1255 if (delegate_->for_websockets()) | 1315 if (stream_factory_->for_websockets_) |
| 1256 return ERR_NOT_IMPLEMENTED; | 1316 return ERR_NOT_IMPLEMENTED; |
| 1257 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 1317 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 1258 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session)); | 1318 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session)); |
| 1259 return OK; | 1319 return OK; |
| 1260 } | 1320 } |
| 1261 | 1321 |
| 1262 // TODO(willchan): Delete this code, because eventually, the | 1322 // TODO(willchan): Delete this code, because eventually, the |
| 1263 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1323 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
| 1264 // will know when SpdySessions become available. | 1324 // will know when SpdySessions become available. |
| 1265 | 1325 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1290 // need to plumb this through to the connect level. | 1350 // need to plumb this through to the connect level. |
| 1291 if (connection_->socket() && !connection_->is_reused()) | 1351 if (connection_->socket() && !connection_->is_reused()) |
| 1292 SetSocketMotivation(); | 1352 SetSocketMotivation(); |
| 1293 | 1353 |
| 1294 if (!using_spdy_) { | 1354 if (!using_spdy_) { |
| 1295 DCHECK(!IsSpdyAlternative()); | 1355 DCHECK(!IsSpdyAlternative()); |
| 1296 // We may get ftp scheme when fetching ftp resources through proxy. | 1356 // We may get ftp scheme when fetching ftp resources through proxy. |
| 1297 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && | 1357 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && |
| 1298 (request_info_.url.SchemeIs("http") || | 1358 (request_info_.url.SchemeIs("http") || |
| 1299 request_info_.url.SchemeIs("ftp")); | 1359 request_info_.url.SchemeIs("ftp")); |
| 1300 if (delegate_->for_websockets()) { | 1360 if (stream_factory_->for_websockets_) { |
| 1301 DCHECK_NE(job_type_, PRECONNECT); | 1361 DCHECK(request_); |
| 1302 DCHECK(delegate_->websocket_handshake_stream_create_helper()); | 1362 DCHECK(request_->websocket_handshake_stream_create_helper()); |
| 1303 websocket_stream_.reset( | 1363 websocket_stream_.reset( |
| 1304 delegate_->websocket_handshake_stream_create_helper() | 1364 request_->websocket_handshake_stream_create_helper() |
| 1305 ->CreateBasicStream(std::move(connection_), using_proxy)); | 1365 ->CreateBasicStream(std::move(connection_), using_proxy)); |
| 1306 } else { | 1366 } else { |
| 1307 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); | 1367 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); |
| 1308 } | 1368 } |
| 1309 return OK; | 1369 return OK; |
| 1310 } | 1370 } |
| 1311 | 1371 |
| 1312 CHECK(!stream_.get()); | 1372 CHECK(!stream_.get()); |
| 1313 | 1373 |
| 1314 bool direct = !IsHttpsProxyAndHttpUrl(); | 1374 bool direct = !IsHttpsProxyAndHttpUrl(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 | 1476 |
| 1417 return ReconsiderProxyAfterError(result); | 1477 return ReconsiderProxyAfterError(result); |
| 1418 } | 1478 } |
| 1419 | 1479 |
| 1420 void HttpStreamFactoryImpl::Job::ReturnToStateInitConnection( | 1480 void HttpStreamFactoryImpl::Job::ReturnToStateInitConnection( |
| 1421 bool close_connection) { | 1481 bool close_connection) { |
| 1422 if (close_connection && connection_->socket()) | 1482 if (close_connection && connection_->socket()) |
| 1423 connection_->socket()->Disconnect(); | 1483 connection_->socket()->Disconnect(); |
| 1424 connection_->Reset(); | 1484 connection_->Reset(); |
| 1425 | 1485 |
| 1426 delegate_->RemoveRequestFromSpdySessionRequestMapForJob(this); | 1486 if (request_) |
| 1487 request_->RemoveRequestFromSpdySessionRequestMap(); |
| 1427 | 1488 |
| 1428 next_state_ = STATE_INIT_CONNECTION; | 1489 next_state_ = STATE_INIT_CONNECTION; |
| 1429 } | 1490 } |
| 1430 | 1491 |
| 1431 void HttpStreamFactoryImpl::Job::SetSocketMotivation() { | 1492 void HttpStreamFactoryImpl::Job::SetSocketMotivation() { |
| 1432 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED) | 1493 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED) |
| 1433 connection_->socket()->SetSubresourceSpeculation(); | 1494 connection_->socket()->SetSubresourceSpeculation(); |
| 1434 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED) | 1495 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED) |
| 1435 connection_->socket()->SetOmniboxSpeculation(); | 1496 connection_->socket()->SetOmniboxSpeculation(); |
| 1436 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED). | 1497 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED). |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 int rv = session_->proxy_service()->ReconsiderProxyAfterError( | 1619 int rv = session_->proxy_service()->ReconsiderProxyAfterError( |
| 1559 request_info_.url, request_info_.method, request_info_.load_flags, error, | 1620 request_info_.url, request_info_.method, request_info_.load_flags, error, |
| 1560 &proxy_info_, io_callback_, &pac_request_, | 1621 &proxy_info_, io_callback_, &pac_request_, |
| 1561 session_->params().proxy_delegate, net_log_); | 1622 session_->params().proxy_delegate, net_log_); |
| 1562 if (rv == OK || rv == ERR_IO_PENDING) { | 1623 if (rv == OK || rv == ERR_IO_PENDING) { |
| 1563 // If the error was during connection setup, there is no socket to | 1624 // If the error was during connection setup, there is no socket to |
| 1564 // disconnect. | 1625 // disconnect. |
| 1565 if (connection_->socket()) | 1626 if (connection_->socket()) |
| 1566 connection_->socket()->Disconnect(); | 1627 connection_->socket()->Disconnect(); |
| 1567 connection_->Reset(); | 1628 connection_->Reset(); |
| 1568 delegate_->RemoveRequestFromSpdySessionRequestMapForJob(this); | 1629 if (request_) |
| 1630 request_->RemoveRequestFromSpdySessionRequestMap(); |
| 1569 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; | 1631 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |
| 1570 } else { | 1632 } else { |
| 1571 // If ReconsiderProxyAfterError() failed synchronously, it means | 1633 // If ReconsiderProxyAfterError() failed synchronously, it means |
| 1572 // there was nothing left to fall-back to, so fail the transaction | 1634 // there was nothing left to fall-back to, so fail the transaction |
| 1573 // with the last connection error we got. | 1635 // with the last connection error we got. |
| 1574 // TODO(eroman): This is a confusing contract, make it more obvious. | 1636 // TODO(eroman): This is a confusing contract, make it more obvious. |
| 1575 rv = error; | 1637 rv = error; |
| 1576 } | 1638 } |
| 1577 | 1639 |
| 1578 return rv; | 1640 return rv; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1609 if (ssl_socket->IgnoreCertError(error, load_flags)) | 1671 if (ssl_socket->IgnoreCertError(error, load_flags)) |
| 1610 return OK; | 1672 return OK; |
| 1611 return error; | 1673 return error; |
| 1612 } | 1674 } |
| 1613 | 1675 |
| 1614 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() { | 1676 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() { |
| 1615 if (HttpStreamFactory::spdy_enabled()) | 1677 if (HttpStreamFactory::spdy_enabled()) |
| 1616 using_spdy_ = true; | 1678 using_spdy_ = true; |
| 1617 } | 1679 } |
| 1618 | 1680 |
| 1681 bool HttpStreamFactoryImpl::Job::IsPreconnecting() const { |
| 1682 DCHECK_GE(num_streams_, 0); |
| 1683 return num_streams_ > 0; |
| 1684 } |
| 1685 |
| 1686 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { |
| 1687 return !IsPreconnecting() && !request_; |
| 1688 } |
| 1689 |
| 1619 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() { | 1690 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() { |
| 1620 if (using_existing_quic_session_) { | 1691 if (using_existing_quic_session_) { |
| 1621 // If an existing session was used, then no TCP connection was | 1692 // If an existing session was used, then no TCP connection was |
| 1622 // started. | 1693 // started. |
| 1623 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); | 1694 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); |
| 1624 } else if (IsSpdyAlternative() || IsQuicAlternative()) { | 1695 } else if (IsSpdyAlternative() || IsQuicAlternative()) { |
| 1625 // This Job was the alternative Job, and hence won the race. | 1696 // This Job was the alternative Job, and hence won the race. |
| 1626 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); | 1697 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); |
| 1627 } else { | 1698 } else { |
| 1628 // This Job was the normal Job, and hence the alternative Job lost the race. | 1699 // This Job was the normal Job, and hence the alternative Job lost the race. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 return ClientSocketPoolManager::NORMAL_GROUP; | 1790 return ClientSocketPoolManager::NORMAL_GROUP; |
| 1720 } | 1791 } |
| 1721 | 1792 |
| 1722 // If the connection succeeds, failed connection attempts leading up to the | 1793 // If the connection succeeds, failed connection attempts leading up to the |
| 1723 // success will be returned via the successfully connected socket. If the | 1794 // success will be returned via the successfully connected socket. If the |
| 1724 // connection fails, failed connection attempts will be returned via the | 1795 // connection fails, failed connection attempts will be returned via the |
| 1725 // ClientSocketHandle. Check whether a socket was returned and copy the | 1796 // ClientSocketHandle. Check whether a socket was returned and copy the |
| 1726 // connection attempts from the proper place. | 1797 // connection attempts from the proper place. |
| 1727 void HttpStreamFactoryImpl::Job:: | 1798 void HttpStreamFactoryImpl::Job:: |
| 1728 MaybeCopyConnectionAttemptsFromSocketOrHandle() { | 1799 MaybeCopyConnectionAttemptsFromSocketOrHandle() { |
| 1729 if (!connection_) | 1800 if (IsOrphaned() || !connection_) |
| 1730 return; | 1801 return; |
| 1731 | 1802 |
| 1732 ConnectionAttempts socket_attempts = connection_->connection_attempts(); | |
| 1733 if (connection_->socket()) { | 1803 if (connection_->socket()) { |
| 1804 ConnectionAttempts socket_attempts; |
| 1734 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1805 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1806 request_->AddConnectionAttempts(socket_attempts); |
| 1807 } else { |
| 1808 request_->AddConnectionAttempts(connection_->connection_attempts()); |
| 1735 } | 1809 } |
| 1736 | |
| 1737 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); | |
| 1738 } | 1810 } |
| 1739 | 1811 |
| 1740 } // namespace net | 1812 } // namespace net |
| OLD | NEW |