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 <string> | |
8 | |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 15 #include "base/values.h" |
14 #include "build/build_config.h" | 16 #include "build/build_config.h" |
15 #include "net/base/connection_type_histograms.h" | 17 #include "net/base/connection_type_histograms.h" |
16 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 base::MessageLoop::current()->PostTask( | 202 base::MessageLoop::current()->PostTask( |
201 FROM_HERE, | 203 FROM_HERE, |
202 base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete, | 204 base::Bind(&HttpStreamFactoryImpl::Job::OnIOComplete, |
203 ptr_factory_.GetWeakPtr(), OK)); | 205 ptr_factory_.GetWeakPtr(), OK)); |
204 } | 206 } |
205 } | 207 } |
206 | 208 |
207 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { | 209 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { |
208 DCHECK_EQ(request_, request); | 210 DCHECK_EQ(request_, request); |
209 request_ = NULL; | 211 request_ = NULL; |
210 // We've been orphaned, but there's a job we're blocked on. Don't bother | |
211 // racing, just cancel ourself. | |
212 if (blocking_job_) { | 212 if (blocking_job_) { |
213 // We've been orphaned, but there's a job we're blocked on. Don't bother | |
214 // racing, just cancel ourself. | |
213 DCHECK(blocking_job_->waiting_job_); | 215 DCHECK(blocking_job_->waiting_job_); |
214 blocking_job_->waiting_job_ = NULL; | 216 blocking_job_->waiting_job_ = NULL; |
215 blocking_job_ = NULL; | 217 blocking_job_ = NULL; |
218 if (stream_factory_->for_websockets_ && | |
219 connection_ && connection_->socket()) | |
220 connection_->socket()->Disconnect(); | |
221 stream_factory_->OnOrphanedJobComplete(this); | |
222 } else if (stream_factory_->for_websockets_) { | |
223 // We cancel this job because WebSocketStream can't be created | |
224 // without a WebSocketStreamBase::Factory which is stored in Request class | |
225 // and isn't accessible from this job. | |
226 if (connection_ && connection_->socket()) | |
227 connection_->socket()->Disconnect(); | |
216 stream_factory_->OnOrphanedJobComplete(this); | 228 stream_factory_->OnOrphanedJobComplete(this); |
217 } | 229 } |
218 } | 230 } |
219 | 231 |
220 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const { | 232 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const { |
221 return was_npn_negotiated_; | 233 return was_npn_negotiated_; |
222 } | 234 } |
223 | 235 |
224 NextProto HttpStreamFactoryImpl::Job::protocol_negotiated() | 236 NextProto HttpStreamFactoryImpl::Job::protocol_negotiated() |
225 const { | 237 const { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 } | 279 } |
268 } | 280 } |
269 | 281 |
270 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { | 282 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { |
271 // We need to make sure that if a spdy session was created for | 283 // We need to make sure that if a spdy session was created for |
272 // https://somehost/ that we don't use that session for http://somehost:443/. | 284 // https://somehost/ that we don't use that session for http://somehost:443/. |
273 // The only time we can use an existing session is if the request URL is | 285 // The only time we can use an existing session is if the request URL is |
274 // https (the normal case) or if we're connection to a SPDY proxy, or | 286 // https (the normal case) or if we're connection to a SPDY proxy, or |
275 // if we're running with force_spdy_always_. crbug.com/133176 | 287 // if we're running with force_spdy_always_. crbug.com/133176 |
276 return request_info_.url.SchemeIs("https") || | 288 return request_info_.url.SchemeIs("https") || |
289 request_info_.url.SchemeIs("wss") || | |
277 proxy_info_.proxy_server().is_https() || | 290 proxy_info_.proxy_server().is_https() || |
278 force_spdy_always_; | 291 force_spdy_always_; |
279 } | 292 } |
280 | 293 |
281 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { | 294 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { |
282 DCHECK(stream_.get()); | 295 DCHECK(stream_.get()); |
283 DCHECK(!IsPreconnecting()); | 296 DCHECK(!IsPreconnecting()); |
297 DCHECK(!stream_factory_->for_websockets_); | |
284 if (IsOrphaned()) { | 298 if (IsOrphaned()) { |
285 stream_factory_->OnOrphanedJobComplete(this); | 299 stream_factory_->OnOrphanedJobComplete(this); |
286 } else { | 300 } else { |
287 request_->Complete(was_npn_negotiated(), | 301 request_->Complete(was_npn_negotiated(), |
288 protocol_negotiated(), | 302 protocol_negotiated(), |
289 using_spdy(), | 303 using_spdy(), |
290 net_log_); | 304 net_log_); |
291 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, | 305 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, |
292 stream_.release()); | 306 stream_.release()); |
293 } | 307 } |
294 // |this| may be deleted after this call. | 308 // |this| may be deleted after this call. |
295 } | 309 } |
296 | 310 |
297 void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() { | 311 void HttpStreamFactoryImpl::Job::OnWebSocketStreamReadyCallback() { |
312 DCHECK(websocket_stream_); | |
313 DCHECK(!IsPreconnecting()); | |
314 DCHECK(stream_factory_->for_websockets_); | |
315 if (IsOrphaned()) { | |
mmenke
2013/06/19 14:30:28
This should be:
"DCHECK(!IsOrphaned());", without
yhirano
2013/06/20 05:01:44
Done.
| |
316 stream_factory_->OnOrphanedJobComplete(this); | |
317 } else { | |
318 request_->Complete(was_npn_negotiated(), | |
319 protocol_negotiated(), | |
320 using_spdy(), | |
321 net_log_); | |
322 request_->OnWebSocketStreamReady(this, | |
323 server_ssl_config_, | |
324 proxy_info_, | |
325 websocket_stream_.release()); | |
326 } | |
327 // |this| may be deleted after this call. | |
328 } | |
329 | |
330 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { | |
298 DCHECK(!stream_.get()); | 331 DCHECK(!stream_.get()); |
299 DCHECK(!IsPreconnecting()); | 332 DCHECK(!IsPreconnecting()); |
300 DCHECK(using_spdy()); | 333 DCHECK(using_spdy()); |
301 DCHECK(new_spdy_session_.get()); | 334 DCHECK(new_spdy_session_.get()); |
302 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; | 335 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; |
303 new_spdy_session_ = NULL; | 336 new_spdy_session_ = NULL; |
304 if (IsOrphaned()) { | 337 if (IsOrphaned()) { |
305 stream_factory_->OnSpdySessionReady( | 338 stream_factory_->OnNewSpdySessionReady( |
306 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, | 339 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, |
307 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); | 340 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); |
308 stream_factory_->OnOrphanedJobComplete(this); | 341 stream_factory_->OnOrphanedJobComplete(this); |
309 } else { | 342 } else { |
310 request_->OnSpdySessionReady(this, spdy_session, spdy_session_direct_); | 343 request_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_); |
311 } | 344 } |
312 // |this| may be deleted after this call. | 345 // |this| may be deleted after this call. |
313 } | 346 } |
314 | 347 |
315 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { | 348 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { |
316 DCHECK(!IsPreconnecting()); | 349 DCHECK(!IsPreconnecting()); |
317 if (IsOrphaned()) | 350 if (IsOrphaned()) |
318 stream_factory_->OnOrphanedJobComplete(this); | 351 stream_factory_->OnOrphanedJobComplete(this); |
319 else | 352 else |
320 request_->OnStreamFailed(this, result, server_ssl_config_); | 353 request_->OnStreamFailed(this, result, server_ssl_config_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 if (IsOrphaned()) | 393 if (IsOrphaned()) |
361 stream_factory_->OnOrphanedJobComplete(this); | 394 stream_factory_->OnOrphanedJobComplete(this); |
362 else | 395 else |
363 request_->OnHttpsProxyTunnelResponse( | 396 request_->OnHttpsProxyTunnelResponse( |
364 this, response_info, server_ssl_config_, proxy_info_, stream); | 397 this, response_info, server_ssl_config_, proxy_info_, stream); |
365 // |this| may be deleted after this call. | 398 // |this| may be deleted after this call. |
366 } | 399 } |
367 | 400 |
368 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { | 401 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { |
369 DCHECK(!request_); | 402 DCHECK(!request_); |
370 if (new_spdy_session_.get()) { | 403 if (new_spdy_session_) { |
371 stream_factory_->OnSpdySessionReady(new_spdy_session_, | 404 stream_factory_->OnNewSpdySessionReady( |
372 spdy_session_direct_, | 405 new_spdy_session_, spdy_session_direct_, server_ssl_config_, |
373 server_ssl_config_, | 406 proxy_info_, was_npn_negotiated(), protocol_negotiated(), using_spdy(), |
374 proxy_info_, | 407 net_log_); |
375 was_npn_negotiated(), | |
376 protocol_negotiated(), | |
377 using_spdy(), | |
378 net_log_); | |
379 } | 408 } |
380 stream_factory_->OnPreconnectsComplete(this); | 409 stream_factory_->OnPreconnectsComplete(this); |
381 // |this| may be deleted after this call. | 410 // |this| may be deleted after this call. |
382 } | 411 } |
383 | 412 |
384 // static | 413 // static |
385 int HttpStreamFactoryImpl::Job::OnHostResolution( | 414 int HttpStreamFactoryImpl::Job::OnHostResolution( |
386 SpdySessionPool* spdy_session_pool, | 415 SpdySessionPool* spdy_session_pool, |
387 const SpdySessionKey& spdy_session_key, | 416 const SpdySessionKey& spdy_session_key, |
388 const AddressList& addresses, | 417 const AddressList& addresses, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 | 470 |
442 ProxyClientSocket* proxy_socket = | 471 ProxyClientSocket* proxy_socket = |
443 static_cast<ProxyClientSocket*>(connection_->socket()); | 472 static_cast<ProxyClientSocket*>(connection_->socket()); |
444 const HttpResponseInfo* tunnel_auth_response = | 473 const HttpResponseInfo* tunnel_auth_response = |
445 proxy_socket->GetConnectResponseInfo(); | 474 proxy_socket->GetConnectResponseInfo(); |
446 | 475 |
447 next_state_ = STATE_WAITING_USER_ACTION; | 476 next_state_ = STATE_WAITING_USER_ACTION; |
448 base::MessageLoop::current()->PostTask( | 477 base::MessageLoop::current()->PostTask( |
449 FROM_HERE, | 478 FROM_HERE, |
450 base::Bind( | 479 base::Bind( |
451 &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback, | 480 &Job::OnNeedsProxyAuthCallback, |
452 ptr_factory_.GetWeakPtr(), | 481 ptr_factory_.GetWeakPtr(), |
453 *tunnel_auth_response, | 482 *tunnel_auth_response, |
454 proxy_socket->GetAuthController())); | 483 proxy_socket->GetAuthController())); |
455 } | 484 } |
456 return ERR_IO_PENDING; | 485 return ERR_IO_PENDING; |
457 | 486 |
458 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: | 487 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: |
459 base::MessageLoop::current()->PostTask( | 488 base::MessageLoop::current()->PostTask( |
460 FROM_HERE, | 489 FROM_HERE, |
461 base::Bind( | 490 base::Bind( |
462 &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback, | 491 &Job::OnNeedsClientAuthCallback, |
463 ptr_factory_.GetWeakPtr(), | 492 ptr_factory_.GetWeakPtr(), |
464 connection_->ssl_error_response_info().cert_request_info)); | 493 connection_->ssl_error_response_info().cert_request_info)); |
465 return ERR_IO_PENDING; | 494 return ERR_IO_PENDING; |
466 | 495 |
467 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE: | 496 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE: |
468 { | 497 { |
469 DCHECK(connection_.get()); | 498 DCHECK(connection_.get()); |
470 DCHECK(connection_->socket()); | 499 DCHECK(connection_->socket()); |
471 DCHECK(establishing_tunnel_); | 500 DCHECK(establishing_tunnel_); |
472 | 501 |
473 ProxyClientSocket* proxy_socket = | 502 ProxyClientSocket* proxy_socket = |
474 static_cast<ProxyClientSocket*>(connection_->socket()); | 503 static_cast<ProxyClientSocket*>(connection_->socket()); |
475 base::MessageLoop::current()->PostTask( | 504 base::MessageLoop::current()->PostTask( |
476 FROM_HERE, | 505 FROM_HERE, |
477 base::Bind( | 506 base::Bind( |
478 &HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback, | 507 &Job::OnHttpsProxyTunnelResponseCallback, |
479 ptr_factory_.GetWeakPtr(), | 508 ptr_factory_.GetWeakPtr(), |
480 *proxy_socket->GetConnectResponseInfo(), | 509 *proxy_socket->GetConnectResponseInfo(), |
481 proxy_socket->CreateConnectResponseStream())); | 510 proxy_socket->CreateConnectResponseStream())); |
482 return ERR_IO_PENDING; | 511 return ERR_IO_PENDING; |
483 } | 512 } |
484 | 513 |
485 case OK: | 514 case OK: |
486 next_state_ = STATE_DONE; | 515 next_state_ = STATE_DONE; |
487 if (new_spdy_session_.get()) { | 516 if (new_spdy_session_) { |
488 base::MessageLoop::current()->PostTask( | |
489 FROM_HERE, | |
490 base::Bind(&HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback, | |
491 ptr_factory_.GetWeakPtr())); | |
492 } else { | |
493 base::MessageLoop::current()->PostTask( | 517 base::MessageLoop::current()->PostTask( |
494 FROM_HERE, | 518 FROM_HERE, |
495 base::Bind( | 519 base::Bind( |
496 &HttpStreamFactoryImpl::Job::OnStreamReadyCallback, | 520 &Job::OnNewSpdySessionReadyCallback, |
521 ptr_factory_.GetWeakPtr())); | |
522 } else if (stream_factory_->for_websockets_) { | |
523 DCHECK(websocket_stream_); | |
524 base::MessageLoop::current()->PostTask( | |
525 FROM_HERE, | |
526 base::Bind( | |
527 &Job::OnWebSocketStreamReadyCallback, | |
528 ptr_factory_.GetWeakPtr())); | |
529 } else { | |
530 DCHECK(stream_.get()); | |
531 base::MessageLoop::current()->PostTask( | |
532 FROM_HERE, | |
533 base::Bind( | |
534 &Job::OnStreamReadyCallback, | |
497 ptr_factory_.GetWeakPtr())); | 535 ptr_factory_.GetWeakPtr())); |
498 } | 536 } |
499 return ERR_IO_PENDING; | 537 return ERR_IO_PENDING; |
500 | 538 |
501 default: | 539 default: |
502 base::MessageLoop::current()->PostTask( | 540 base::MessageLoop::current()->PostTask( |
503 FROM_HERE, | 541 FROM_HERE, |
504 base::Bind( | 542 base::Bind( |
505 &HttpStreamFactoryImpl::Job::OnStreamFailedCallback, | 543 &Job::OnStreamFailedCallback, |
506 ptr_factory_.GetWeakPtr(), | 544 ptr_factory_.GetWeakPtr(), |
507 result)); | 545 result)); |
508 return ERR_IO_PENDING; | 546 return ERR_IO_PENDING; |
509 } | 547 } |
510 return result; | 548 return result; |
511 } | 549 } |
512 | 550 |
513 int HttpStreamFactoryImpl::Job::DoLoop(int result) { | 551 int HttpStreamFactoryImpl::Job::DoLoop(int result) { |
514 DCHECK_NE(next_state_, STATE_NONE); | 552 DCHECK_NE(next_state_, STATE_NONE); |
515 int rv = result; | 553 int rv = result; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 next_state_ = STATE_INIT_CONNECTION; | 720 next_state_ = STATE_INIT_CONNECTION; |
683 return OK; | 721 return OK; |
684 } | 722 } |
685 | 723 |
686 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 724 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
687 DCHECK(!blocking_job_); | 725 DCHECK(!blocking_job_); |
688 DCHECK(!connection_->is_initialized()); | 726 DCHECK(!connection_->is_initialized()); |
689 DCHECK(proxy_info_.proxy_server().is_valid()); | 727 DCHECK(proxy_info_.proxy_server().is_valid()); |
690 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 728 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
691 | 729 |
692 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL(); | 730 using_ssl_ = request_info_.url.SchemeIs("https") || |
731 request_info_.url.SchemeIs("wss") || ShouldForceSpdySSL(); | |
693 using_spdy_ = false; | 732 using_spdy_ = false; |
694 | 733 |
695 if (ShouldForceQuic()) | 734 if (ShouldForceQuic()) |
696 using_quic_ = true; | 735 using_quic_ = true; |
697 | 736 |
698 if (using_quic_) { | 737 if (using_quic_) { |
699 DCHECK(session_->params().enable_quic); | 738 DCHECK(session_->params().enable_quic); |
700 if (!proxy_info_.is_direct()) { | 739 if (!proxy_info_.is_direct()) { |
701 NOTREACHED(); | 740 NOTREACHED(); |
702 // TODO(rch): support QUIC proxies. | 741 // TODO(rch): support QUIC proxies. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 // Disable revocation checking for HTTPS proxies since the revocation | 806 // Disable revocation checking for HTTPS proxies since the revocation |
768 // requests are probably going to need to go through the proxy too. | 807 // requests are probably going to need to go through the proxy too. |
769 proxy_ssl_config_.rev_checking_enabled = false; | 808 proxy_ssl_config_.rev_checking_enabled = false; |
770 } | 809 } |
771 if (using_ssl_) { | 810 if (using_ssl_) { |
772 InitSSLConfig(origin_, &server_ssl_config_, | 811 InitSSLConfig(origin_, &server_ssl_config_, |
773 false /* not a proxy server */); | 812 false /* not a proxy server */); |
774 } | 813 } |
775 | 814 |
776 if (IsPreconnecting()) { | 815 if (IsPreconnecting()) { |
816 DCHECK(!stream_factory_->for_websockets_); | |
777 return PreconnectSocketsForHttpRequest( | 817 return PreconnectSocketsForHttpRequest( |
778 origin_url_, | 818 origin_url_, |
779 request_info_.extra_headers, | 819 request_info_.extra_headers, |
780 request_info_.load_flags, | 820 request_info_.load_flags, |
781 priority_, | 821 priority_, |
782 session_, | 822 session_, |
783 proxy_info_, | 823 proxy_info_, |
784 ShouldForceSpdySSL(), | 824 ShouldForceSpdySSL(), |
785 want_spdy_over_npn, | 825 want_spdy_over_npn, |
786 server_ssl_config_, | 826 server_ssl_config_, |
787 proxy_ssl_config_, | 827 proxy_ssl_config_, |
788 request_info_.privacy_mode, | 828 request_info_.privacy_mode, |
789 net_log_, | 829 net_log_, |
790 num_streams_); | 830 num_streams_); |
791 } else { | 831 } else { |
792 // If we can't use a SPDY session, don't both checking for one after | 832 // If we can't use a SPDY session, don't both checking for one after |
793 // the hostname is resolved. | 833 // the hostname is resolved. |
794 OnHostResolutionCallback resolution_callback = CanUseExistingSpdySession() ? | 834 OnHostResolutionCallback resolution_callback = CanUseExistingSpdySession() ? |
795 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), | 835 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), |
796 GetSpdySessionKey()) : | 836 GetSpdySessionKey()) : |
797 OnHostResolutionCallback(); | 837 OnHostResolutionCallback(); |
838 if (stream_factory_->for_websockets_) { | |
839 return InitSocketHandleForWebSocketRequest( | |
840 origin_url_, request_info_.extra_headers, request_info_.load_flags, | |
841 priority_, session_, proxy_info_, ShouldForceSpdySSL(), | |
842 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, | |
843 request_info_.privacy_mode, net_log_, | |
844 connection_.get(), resolution_callback, io_callback_); | |
845 } | |
798 return InitSocketHandleForHttpRequest( | 846 return InitSocketHandleForHttpRequest( |
799 origin_url_, request_info_.extra_headers, request_info_.load_flags, | 847 origin_url_, request_info_.extra_headers, request_info_.load_flags, |
800 priority_, session_, proxy_info_, ShouldForceSpdySSL(), | 848 priority_, session_, proxy_info_, ShouldForceSpdySSL(), |
801 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, | 849 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, |
802 request_info_.privacy_mode, net_log_, | 850 request_info_.privacy_mode, net_log_, |
803 connection_.get(), resolution_callback, io_callback_); | 851 connection_.get(), resolution_callback, io_callback_); |
804 } | 852 } |
805 } | 853 } |
806 | 854 |
807 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 855 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 if (ssl_socket->WasNpnNegotiated()) { | 905 if (ssl_socket->WasNpnNegotiated()) { |
858 was_npn_negotiated_ = true; | 906 was_npn_negotiated_ = true; |
859 std::string proto; | 907 std::string proto; |
860 std::string server_protos; | 908 std::string server_protos; |
861 SSLClientSocket::NextProtoStatus status = | 909 SSLClientSocket::NextProtoStatus status = |
862 ssl_socket->GetNextProto(&proto, &server_protos); | 910 ssl_socket->GetNextProto(&proto, &server_protos); |
863 NextProto protocol_negotiated = | 911 NextProto protocol_negotiated = |
864 SSLClientSocket::NextProtoFromString(proto); | 912 SSLClientSocket::NextProtoFromString(proto); |
865 protocol_negotiated_ = protocol_negotiated; | 913 protocol_negotiated_ = protocol_negotiated; |
866 net_log_.AddEvent( | 914 net_log_.AddEvent( |
867 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, | 915 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, |
868 base::Bind(&NetLogHttpStreamProtoCallback, | 916 base::Bind(&NetLogHttpStreamProtoCallback, |
869 status, &proto, &server_protos)); | 917 status, &proto, &server_protos)); |
870 if (ssl_socket->was_spdy_negotiated()) | 918 if (ssl_socket->was_spdy_negotiated()) |
871 SwitchToSpdyMode(); | 919 SwitchToSpdyMode(); |
872 } | 920 } |
873 if (ShouldForceSpdySSL()) | 921 if (ShouldForceSpdySSL()) |
874 SwitchToSpdyMode(); | 922 SwitchToSpdyMode(); |
875 } else if (proxy_info_.is_https() && connection_->socket() && | 923 } else if (proxy_info_.is_https() && connection_->socket() && |
876 result == OK) { | 924 result == OK) { |
877 ProxyClientSocket* proxy_socket = | 925 ProxyClientSocket* proxy_socket = |
878 static_cast<ProxyClientSocket*>(connection_->socket()); | 926 static_cast<ProxyClientSocket*>(connection_->socket()); |
879 if (proxy_socket->IsUsingSpdy()) { | 927 if (proxy_socket->IsUsingSpdy()) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 if (connection_->socket() && !connection_->is_reused()) | 1023 if (connection_->socket() && !connection_->is_reused()) |
976 SetSocketMotivation(); | 1024 SetSocketMotivation(); |
977 | 1025 |
978 if (!using_spdy_) { | 1026 if (!using_spdy_) { |
979 // We may get ftp scheme when fetching ftp resources through proxy. | 1027 // We may get ftp scheme when fetching ftp resources through proxy. |
980 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && | 1028 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && |
981 (request_info_.url.SchemeIs("http") || | 1029 (request_info_.url.SchemeIs("http") || |
982 request_info_.url.SchemeIs("ftp")); | 1030 request_info_.url.SchemeIs("ftp")); |
983 if (stream_factory_->http_pipelined_host_pool_. | 1031 if (stream_factory_->http_pipelined_host_pool_. |
984 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { | 1032 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { |
1033 DCHECK(!stream_factory_->for_websockets_); | |
985 stream_.reset(stream_factory_->http_pipelined_host_pool_. | 1034 stream_.reset(stream_factory_->http_pipelined_host_pool_. |
986 CreateStreamOnExistingPipeline( | 1035 CreateStreamOnExistingPipeline( |
987 *http_pipelining_key_.get())); | 1036 *http_pipelining_key_.get())); |
988 CHECK(stream_.get()); | 1037 CHECK(stream_.get()); |
1038 } else if (stream_factory_->for_websockets_) { | |
1039 DCHECK(request_); | |
1040 DCHECK(request_->websocket_stream_factory()); | |
1041 websocket_stream_.reset( | |
1042 request_->websocket_stream_factory()->CreateBasicStream( | |
1043 connection_.release(), using_proxy)); | |
989 } else if (!using_proxy && IsRequestEligibleForPipelining()) { | 1044 } else if (!using_proxy && IsRequestEligibleForPipelining()) { |
990 // TODO(simonjam): Support proxies. | 1045 // TODO(simonjam): Support proxies. |
991 stream_.reset( | 1046 stream_.reset( |
992 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( | 1047 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( |
993 *http_pipelining_key_.get(), | 1048 *http_pipelining_key_.get(), |
994 connection_.release(), | 1049 connection_.release(), |
995 server_ssl_config_, | 1050 server_ssl_config_, |
996 proxy_info_, | 1051 proxy_info_, |
997 net_log_, | 1052 net_log_, |
998 was_npn_negotiated_, | 1053 was_npn_negotiated_, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1050 } | 1105 } |
1051 } | 1106 } |
1052 | 1107 |
1053 if (spdy_session->IsClosed()) | 1108 if (spdy_session->IsClosed()) |
1054 return ERR_CONNECTION_CLOSED; | 1109 return ERR_CONNECTION_CLOSED; |
1055 | 1110 |
1056 // TODO(willchan): Delete this code, because eventually, the | 1111 // TODO(willchan): Delete this code, because eventually, the |
1057 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1112 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
1058 // will know when SpdySessions become available. | 1113 // will know when SpdySessions become available. |
1059 | 1114 |
1060 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1115 if (stream_factory_->for_websockets_) { |
1061 stream_.reset(new SpdyHttpStream(spdy_session.get(), use_relative_url)); | 1116 DCHECK(request_); |
1117 DCHECK(request_->websocket_stream_factory()); | |
1118 bool use_relative_url = direct || request_info_.url.SchemeIs("wss"); | |
1119 websocket_stream_.reset( | |
1120 request_->websocket_stream_factory()->CreateSpdyStream( | |
1121 spdy_session, use_relative_url)); | |
1122 } else { | |
1123 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | |
1124 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); | |
1125 } | |
1062 return OK; | 1126 return OK; |
1063 } | 1127 } |
1064 | 1128 |
1065 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { | 1129 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { |
1066 if (result < 0) | 1130 if (result < 0) |
1067 return result; | 1131 return result; |
1068 | 1132 |
1069 session_->proxy_service()->ReportSuccess(proxy_info_); | 1133 session_->proxy_service()->ReportSuccess(proxy_info_); |
1070 next_state_ = STATE_NONE; | 1134 next_state_ = STATE_NONE; |
1071 return OK; | 1135 return OK; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1352 } | 1416 } |
1353 | 1417 |
1354 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { | 1418 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { |
1355 return !IsPreconnecting() && !request_; | 1419 return !IsPreconnecting() && !request_; |
1356 } | 1420 } |
1357 | 1421 |
1358 bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() { | 1422 bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() { |
1359 if (IsPreconnecting() || !request_) { | 1423 if (IsPreconnecting() || !request_) { |
1360 return false; | 1424 return false; |
1361 } | 1425 } |
1426 if (stream_factory_->for_websockets_) { | |
1427 return false; | |
1428 } | |
1362 if (session_->force_http_pipelining()) { | 1429 if (session_->force_http_pipelining()) { |
1363 return true; | 1430 return true; |
1364 } | 1431 } |
1365 if (!session_->params().http_pipelining_enabled) { | 1432 if (!session_->params().http_pipelining_enabled) { |
1366 return false; | 1433 return false; |
1367 } | 1434 } |
1368 if (using_ssl_) { | 1435 if (using_ssl_) { |
1369 return false; | 1436 return false; |
1370 } | 1437 } |
1371 if (request_info_.method != "GET" && request_info_.method != "HEAD") { | 1438 if (request_info_.method != "GET" && request_info_.method != "HEAD") { |
1372 return false; | 1439 return false; |
1373 } | 1440 } |
1374 if (request_info_.load_flags & | 1441 if (request_info_.load_flags & |
1375 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | | 1442 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | |
1376 net::LOAD_IS_DOWNLOAD)) { | 1443 net::LOAD_IS_DOWNLOAD)) { |
1377 // Avoid pipelining resources that may be streamed for a long time. | 1444 // Avoid pipelining resources that may be streamed for a long time. |
1378 return false; | 1445 return false; |
1379 } | 1446 } |
1380 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( | 1447 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( |
1381 *http_pipelining_key_.get()); | 1448 *http_pipelining_key_.get()); |
1382 } | 1449 } |
1383 | 1450 |
1384 } // namespace net | 1451 } // namespace net |
OLD | NEW |