Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: net/http/http_stream_factory_impl_job.cc

Issue 14813024: Introduce RequestWebSocketStream into HttpStreamFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/string_util.h" 13 #include "base/string_util.h"
12 #include "base/stringprintf.h" 14 #include "base/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const HttpRequestInfo& request_info, 77 const HttpRequestInfo& request_info,
76 RequestPriority priority, 78 RequestPriority priority,
77 const SSLConfig& server_ssl_config, 79 const SSLConfig& server_ssl_config,
78 const SSLConfig& proxy_ssl_config, 80 const SSLConfig& proxy_ssl_config,
79 NetLog* net_log) 81 NetLog* net_log)
80 : request_(NULL), 82 : request_(NULL),
81 request_info_(request_info), 83 request_info_(request_info),
82 priority_(priority), 84 priority_(priority),
83 server_ssl_config_(server_ssl_config), 85 server_ssl_config_(server_ssl_config),
84 proxy_ssl_config_(proxy_ssl_config), 86 proxy_ssl_config_(proxy_ssl_config),
85 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), 87 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)),
mmenke 2013/06/10 20:26:03 Suggestion for another CL: If this is for a WebSo
yhirano 2013/06/11 11:13:16 Filed a bug.
86 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), 88 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))),
87 connection_(new ClientSocketHandle), 89 connection_(new ClientSocketHandle),
88 session_(session), 90 session_(session),
89 stream_factory_(stream_factory), 91 stream_factory_(stream_factory),
90 next_state_(STATE_NONE), 92 next_state_(STATE_NONE),
91 pac_request_(NULL), 93 pac_request_(NULL),
92 blocking_job_(NULL), 94 blocking_job_(NULL),
93 waiting_job_(NULL), 95 waiting_job_(NULL),
94 using_ssl_(false), 96 using_ssl_(false),
95 using_spdy_(false), 97 using_spdy_(false),
(...skipping 22 matching lines...) Expand all
118 if (next_state_ == STATE_WAITING_USER_ACTION) { 120 if (next_state_ == STATE_WAITING_USER_ACTION) {
119 connection_->socket()->Disconnect(); 121 connection_->socket()->Disconnect();
120 connection_.reset(); 122 connection_.reset();
121 } 123 }
122 124
123 if (pac_request_) 125 if (pac_request_)
124 session_->proxy_service()->CancelPacRequest(pac_request_); 126 session_->proxy_service()->CancelPacRequest(pac_request_);
125 127
126 // The stream could be in a partial state. It is not reusable. 128 // The stream could be in a partial state. It is not reusable.
127 if (stream_.get() && next_state_ != STATE_DONE) 129 if (stream_.get() && next_state_ != STATE_DONE)
128 stream_->Close(true /* not reusable */); 130 stream_->Close(true /* not reusable */);
mmenke 2013/06/10 20:26:03 I'm assuming that WebSocketStreams do not need sim
yhirano 2013/06/11 11:13:16 I think so.
129 } 131 }
130 132
131 void HttpStreamFactoryImpl::Job::Start(Request* request) { 133 void HttpStreamFactoryImpl::Job::Start(Request* request) {
132 DCHECK(request); 134 DCHECK(request);
133 request_ = request; 135 request_ = request;
134 StartInternal(); 136 StartInternal();
135 } 137 }
136 138
137 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) { 139 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) {
138 DCHECK_GT(num_streams, 0); 140 DCHECK_GT(num_streams, 0);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 269 }
268 } 270 }
269 271
270 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { 272 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const {
271 // We need to make sure that if a spdy session was created for 273 // 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/. 274 // 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 275 // 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 276 // 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 277 // if we're running with force_spdy_always_. crbug.com/133176
276 return request_info_.url.SchemeIs("https") || 278 return request_info_.url.SchemeIs("https") ||
279 request_info_.url.SchemeIs("wss") ||
277 proxy_info_.proxy_server().is_https() || 280 proxy_info_.proxy_server().is_https() ||
278 force_spdy_always_; 281 force_spdy_always_;
279 } 282 }
280 283
281 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { 284 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
282 DCHECK(stream_.get()); 285 DCHECK(stream_.get());
283 DCHECK(!IsPreconnecting()); 286 DCHECK(!IsPreconnecting());
287 DCHECK(!stream_factory_->for_websockets_);
284 if (IsOrphaned()) { 288 if (IsOrphaned()) {
285 stream_factory_->OnOrphanedJobComplete(this); 289 stream_factory_->OnOrphanedJobComplete(this);
286 } else { 290 } else {
287 request_->Complete(was_npn_negotiated(), 291 request_->Complete(was_npn_negotiated(),
288 protocol_negotiated(), 292 protocol_negotiated(),
289 using_spdy(), 293 using_spdy(),
290 net_log_); 294 net_log_);
291 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, 295 request_->OnStreamReady(this, server_ssl_config_, proxy_info_,
292 stream_.release()); 296 stream_.release());
293 } 297 }
294 // |this| may be deleted after this call. 298 // |this| may be deleted after this call.
295 } 299 }
296 300
297 void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() { 301 void HttpStreamFactoryImpl::Job::OnWebSocketStreamReadyCallback() {
302 DCHECK(websocket_stream_);
303 DCHECK(!IsPreconnecting());
304 DCHECK(stream_factory_->for_websockets_);
305 if (IsOrphaned()) {
306 stream_factory_->OnOrphanedJobComplete(this);
307 } else {
308 request_->Complete(was_npn_negotiated(),
309 protocol_negotiated(),
310 using_spdy(),
311 net_log_);
312 request_->OnWebSocketStreamReady(this,
313 server_ssl_config_,
314 proxy_info_,
315 websocket_stream_.release());
316 }
317 // |this| may be deleted after this call.
318 }
319
320 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() {
298 DCHECK(!stream_.get()); 321 DCHECK(!stream_.get());
299 DCHECK(!IsPreconnecting()); 322 DCHECK(!IsPreconnecting());
300 DCHECK(using_spdy()); 323 DCHECK(using_spdy());
301 DCHECK(new_spdy_session_.get()); 324 DCHECK(new_spdy_session_.get());
302 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; 325 scoped_refptr<SpdySession> spdy_session = new_spdy_session_;
303 new_spdy_session_ = NULL; 326 new_spdy_session_ = NULL;
304 if (IsOrphaned()) { 327 if (IsOrphaned()) {
305 stream_factory_->OnSpdySessionReady( 328 stream_factory_->OnNewSpdySessionReady(
306 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, 329 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_,
307 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); 330 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_);
308 stream_factory_->OnOrphanedJobComplete(this); 331 stream_factory_->OnOrphanedJobComplete(this);
309 } else { 332 } else {
310 request_->OnSpdySessionReady(this, spdy_session, spdy_session_direct_); 333 request_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_);
311 } 334 }
312 // |this| may be deleted after this call. 335 // |this| may be deleted after this call.
313 } 336 }
314 337
315 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { 338 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) {
316 DCHECK(!IsPreconnecting()); 339 DCHECK(!IsPreconnecting());
317 if (IsOrphaned()) 340 if (IsOrphaned())
318 stream_factory_->OnOrphanedJobComplete(this); 341 stream_factory_->OnOrphanedJobComplete(this);
319 else 342 else
320 request_->OnStreamFailed(this, result, server_ssl_config_); 343 request_->OnStreamFailed(this, result, server_ssl_config_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (IsOrphaned()) 383 if (IsOrphaned())
361 stream_factory_->OnOrphanedJobComplete(this); 384 stream_factory_->OnOrphanedJobComplete(this);
362 else 385 else
363 request_->OnHttpsProxyTunnelResponse( 386 request_->OnHttpsProxyTunnelResponse(
364 this, response_info, server_ssl_config_, proxy_info_, stream); 387 this, response_info, server_ssl_config_, proxy_info_, stream);
365 // |this| may be deleted after this call. 388 // |this| may be deleted after this call.
366 } 389 }
367 390
368 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { 391 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() {
369 DCHECK(!request_); 392 DCHECK(!request_);
370 if (new_spdy_session_.get()) { 393 if (new_spdy_session_) {
371 stream_factory_->OnSpdySessionReady(new_spdy_session_, 394 stream_factory_->OnNewSpdySessionReady(
372 spdy_session_direct_, 395 new_spdy_session_, spdy_session_direct_, server_ssl_config_,
373 server_ssl_config_, 396 proxy_info_, was_npn_negotiated(), protocol_negotiated(), using_spdy(),
374 proxy_info_, 397 net_log_);
375 was_npn_negotiated(),
376 protocol_negotiated(),
377 using_spdy(),
378 net_log_);
379 } 398 }
380 stream_factory_->OnPreconnectsComplete(this); 399 stream_factory_->OnPreconnectsComplete(this);
381 // |this| may be deleted after this call. 400 // |this| may be deleted after this call.
382 } 401 }
383 402
384 // static 403 // static
385 int HttpStreamFactoryImpl::Job::OnHostResolution( 404 int HttpStreamFactoryImpl::Job::OnHostResolution(
386 SpdySessionPool* spdy_session_pool, 405 SpdySessionPool* spdy_session_pool,
387 const SpdySessionKey& spdy_session_key, 406 const SpdySessionKey& spdy_session_key,
388 const AddressList& addresses, 407 const AddressList& addresses,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 460
442 ProxyClientSocket* proxy_socket = 461 ProxyClientSocket* proxy_socket =
443 static_cast<ProxyClientSocket*>(connection_->socket()); 462 static_cast<ProxyClientSocket*>(connection_->socket());
444 const HttpResponseInfo* tunnel_auth_response = 463 const HttpResponseInfo* tunnel_auth_response =
445 proxy_socket->GetConnectResponseInfo(); 464 proxy_socket->GetConnectResponseInfo();
446 465
447 next_state_ = STATE_WAITING_USER_ACTION; 466 next_state_ = STATE_WAITING_USER_ACTION;
448 base::MessageLoop::current()->PostTask( 467 base::MessageLoop::current()->PostTask(
449 FROM_HERE, 468 FROM_HERE,
450 base::Bind( 469 base::Bind(
451 &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback, 470 &Job::OnNeedsProxyAuthCallback,
452 ptr_factory_.GetWeakPtr(), 471 ptr_factory_.GetWeakPtr(),
453 *tunnel_auth_response, 472 *tunnel_auth_response,
454 proxy_socket->GetAuthController())); 473 proxy_socket->GetAuthController()));
455 } 474 }
456 return ERR_IO_PENDING; 475 return ERR_IO_PENDING;
457 476
458 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: 477 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED:
459 base::MessageLoop::current()->PostTask( 478 base::MessageLoop::current()->PostTask(
460 FROM_HERE, 479 FROM_HERE,
461 base::Bind( 480 base::Bind(
462 &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback, 481 &Job::OnNeedsClientAuthCallback,
463 ptr_factory_.GetWeakPtr(), 482 ptr_factory_.GetWeakPtr(),
464 connection_->ssl_error_response_info().cert_request_info)); 483 connection_->ssl_error_response_info().cert_request_info));
465 return ERR_IO_PENDING; 484 return ERR_IO_PENDING;
466 485
467 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE: 486 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE:
468 { 487 {
469 DCHECK(connection_.get()); 488 DCHECK(connection_.get());
470 DCHECK(connection_->socket()); 489 DCHECK(connection_->socket());
471 DCHECK(establishing_tunnel_); 490 DCHECK(establishing_tunnel_);
472 491
473 ProxyClientSocket* proxy_socket = 492 ProxyClientSocket* proxy_socket =
474 static_cast<ProxyClientSocket*>(connection_->socket()); 493 static_cast<ProxyClientSocket*>(connection_->socket());
475 base::MessageLoop::current()->PostTask( 494 base::MessageLoop::current()->PostTask(
476 FROM_HERE, 495 FROM_HERE,
477 base::Bind( 496 base::Bind(
478 &HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback, 497 &Job::OnHttpsProxyTunnelResponseCallback,
479 ptr_factory_.GetWeakPtr(), 498 ptr_factory_.GetWeakPtr(),
480 *proxy_socket->GetConnectResponseInfo(), 499 *proxy_socket->GetConnectResponseInfo(),
481 proxy_socket->CreateConnectResponseStream())); 500 proxy_socket->CreateConnectResponseStream()));
482 return ERR_IO_PENDING; 501 return ERR_IO_PENDING;
483 } 502 }
484 503
485 case OK: 504 case OK:
486 next_state_ = STATE_DONE; 505 next_state_ = STATE_DONE;
487 if (new_spdy_session_.get()) { 506 if (new_spdy_session_) {
488 base::MessageLoop::current()->PostTask( 507 base::MessageLoop::current()->PostTask(
489 FROM_HERE, 508 FROM_HERE,
490 base::Bind(&HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback, 509 base::Bind(
491 ptr_factory_.GetWeakPtr())); 510 &Job::OnNewSpdySessionReadyCallback,
511 ptr_factory_.GetWeakPtr()));
512 } else if (stream_factory_->for_websockets_) {
513 DCHECK(websocket_stream_);
514 base::MessageLoop::current()->PostTask(
515 FROM_HERE,
516 base::Bind(
517 &Job::OnWebSocketStreamReadyCallback,
518 ptr_factory_.GetWeakPtr()));
492 } else { 519 } else {
mmenke 2013/06/10 20:26:03 optional nit: Just to keep this structure paralle
yhirano 2013/06/11 11:13:16 Done.
493 base::MessageLoop::current()->PostTask( 520 base::MessageLoop::current()->PostTask(
494 FROM_HERE, 521 FROM_HERE,
495 base::Bind( 522 base::Bind(
496 &HttpStreamFactoryImpl::Job::OnStreamReadyCallback, 523 &Job::OnStreamReadyCallback,
497 ptr_factory_.GetWeakPtr())); 524 ptr_factory_.GetWeakPtr()));
498 } 525 }
499 return ERR_IO_PENDING; 526 return ERR_IO_PENDING;
500 527
501 default: 528 default:
502 base::MessageLoop::current()->PostTask( 529 base::MessageLoop::current()->PostTask(
503 FROM_HERE, 530 FROM_HERE,
504 base::Bind( 531 base::Bind(
505 &HttpStreamFactoryImpl::Job::OnStreamFailedCallback, 532 &Job::OnStreamFailedCallback,
506 ptr_factory_.GetWeakPtr(), 533 ptr_factory_.GetWeakPtr(),
507 result)); 534 result));
508 return ERR_IO_PENDING; 535 return ERR_IO_PENDING;
509 } 536 }
510 return result; 537 return result;
511 } 538 }
512 539
513 int HttpStreamFactoryImpl::Job::DoLoop(int result) { 540 int HttpStreamFactoryImpl::Job::DoLoop(int result) {
514 DCHECK_NE(next_state_, STATE_NONE); 541 DCHECK_NE(next_state_, STATE_NONE);
515 int rv = result; 542 int rv = result;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 next_state_ = STATE_INIT_CONNECTION; 709 next_state_ = STATE_INIT_CONNECTION;
683 return OK; 710 return OK;
684 } 711 }
685 712
686 int HttpStreamFactoryImpl::Job::DoInitConnection() { 713 int HttpStreamFactoryImpl::Job::DoInitConnection() {
687 DCHECK(!blocking_job_); 714 DCHECK(!blocking_job_);
688 DCHECK(!connection_->is_initialized()); 715 DCHECK(!connection_->is_initialized());
689 DCHECK(proxy_info_.proxy_server().is_valid()); 716 DCHECK(proxy_info_.proxy_server().is_valid());
690 next_state_ = STATE_INIT_CONNECTION_COMPLETE; 717 next_state_ = STATE_INIT_CONNECTION_COMPLETE;
691 718
692 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL(); 719 using_ssl_ = request_info_.url.SchemeIs("https") ||
720 request_info_.url.SchemeIs("wss") || ShouldForceSpdySSL();
693 using_spdy_ = false; 721 using_spdy_ = false;
694 722
695 if (ShouldForceQuic()) 723 if (ShouldForceQuic())
696 using_quic_ = true; 724 using_quic_ = true;
697 725
698 if (using_quic_) { 726 if (using_quic_) {
699 DCHECK(session_->params().enable_quic); 727 DCHECK(session_->params().enable_quic);
700 if (!proxy_info_.is_direct()) { 728 if (!proxy_info_.is_direct()) {
701 NOTREACHED(); 729 NOTREACHED();
702 // TODO(rch): support QUIC proxies. 730 // TODO(rch): support QUIC proxies.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 // Disable revocation checking for HTTPS proxies since the revocation 795 // Disable revocation checking for HTTPS proxies since the revocation
768 // requests are probably going to need to go through the proxy too. 796 // requests are probably going to need to go through the proxy too.
769 proxy_ssl_config_.rev_checking_enabled = false; 797 proxy_ssl_config_.rev_checking_enabled = false;
770 } 798 }
771 if (using_ssl_) { 799 if (using_ssl_) {
772 InitSSLConfig(origin_, &server_ssl_config_, 800 InitSSLConfig(origin_, &server_ssl_config_,
773 false /* not a proxy server */); 801 false /* not a proxy server */);
774 } 802 }
775 803
776 if (IsPreconnecting()) { 804 if (IsPreconnecting()) {
805 DCHECK(!stream_factory_->for_websockets_);
777 return PreconnectSocketsForHttpRequest( 806 return PreconnectSocketsForHttpRequest(
778 origin_url_, 807 origin_url_,
779 request_info_.extra_headers, 808 request_info_.extra_headers,
780 request_info_.load_flags, 809 request_info_.load_flags,
781 priority_, 810 priority_,
782 session_, 811 session_,
783 proxy_info_, 812 proxy_info_,
784 ShouldForceSpdySSL(), 813 ShouldForceSpdySSL(),
785 want_spdy_over_npn, 814 want_spdy_over_npn,
786 server_ssl_config_, 815 server_ssl_config_,
787 proxy_ssl_config_, 816 proxy_ssl_config_,
788 request_info_.privacy_mode, 817 request_info_.privacy_mode,
789 net_log_, 818 net_log_,
790 num_streams_); 819 num_streams_);
791 } else { 820 } else {
792 // If we can't use a SPDY session, don't both checking for one after 821 // If we can't use a SPDY session, don't both checking for one after
793 // the hostname is resolved. 822 // the hostname is resolved.
794 OnHostResolutionCallback resolution_callback = CanUseExistingSpdySession() ? 823 OnHostResolutionCallback resolution_callback = CanUseExistingSpdySession() ?
795 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), 824 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(),
796 GetSpdySessionKey()) : 825 GetSpdySessionKey()) :
797 OnHostResolutionCallback(); 826 OnHostResolutionCallback();
827 if (stream_factory_->for_websockets_) {
828 return InitSocketHandleForWebSocketRequest(
829 origin_url_, request_info_.extra_headers, request_info_.load_flags,
830 priority_, session_, proxy_info_, ShouldForceSpdySSL(),
831 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_,
832 request_info_.privacy_mode, net_log_,
833 connection_.get(), resolution_callback, io_callback_);
834 }
798 return InitSocketHandleForHttpRequest( 835 return InitSocketHandleForHttpRequest(
799 origin_url_, request_info_.extra_headers, request_info_.load_flags, 836 origin_url_, request_info_.extra_headers, request_info_.load_flags,
800 priority_, session_, proxy_info_, ShouldForceSpdySSL(), 837 priority_, session_, proxy_info_, ShouldForceSpdySSL(),
801 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, 838 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_,
802 request_info_.privacy_mode, net_log_, 839 request_info_.privacy_mode, net_log_,
803 connection_.get(), resolution_callback, io_callback_); 840 connection_.get(), resolution_callback, io_callback_);
804 } 841 }
805 } 842 }
806 843
807 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { 844 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 if (ssl_socket->WasNpnNegotiated()) { 894 if (ssl_socket->WasNpnNegotiated()) {
858 was_npn_negotiated_ = true; 895 was_npn_negotiated_ = true;
859 std::string proto; 896 std::string proto;
860 std::string server_protos; 897 std::string server_protos;
861 SSLClientSocket::NextProtoStatus status = 898 SSLClientSocket::NextProtoStatus status =
862 ssl_socket->GetNextProto(&proto, &server_protos); 899 ssl_socket->GetNextProto(&proto, &server_protos);
863 NextProto protocol_negotiated = 900 NextProto protocol_negotiated =
864 SSLClientSocket::NextProtoFromString(proto); 901 SSLClientSocket::NextProtoFromString(proto);
865 protocol_negotiated_ = protocol_negotiated; 902 protocol_negotiated_ = protocol_negotiated;
866 net_log_.AddEvent( 903 net_log_.AddEvent(
867 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, 904 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO,
868 base::Bind(&NetLogHttpStreamProtoCallback, 905 base::Bind(&NetLogHttpStreamProtoCallback,
869 status, &proto, &server_protos)); 906 status, &proto, &server_protos));
870 if (ssl_socket->was_spdy_negotiated()) 907 if (ssl_socket->was_spdy_negotiated())
871 SwitchToSpdyMode(); 908 SwitchToSpdyMode();
872 } 909 }
873 if (ShouldForceSpdySSL()) 910 if (ShouldForceSpdySSL())
874 SwitchToSpdyMode(); 911 SwitchToSpdyMode();
875 } else if (proxy_info_.is_https() && connection_->socket() && 912 } else if (proxy_info_.is_https() && connection_->socket() &&
876 result == OK) { 913 result == OK) {
877 ProxyClientSocket* proxy_socket = 914 ProxyClientSocket* proxy_socket =
878 static_cast<ProxyClientSocket*>(connection_->socket()); 915 static_cast<ProxyClientSocket*>(connection_->socket());
879 if (proxy_socket->IsUsingSpdy()) { 916 if (proxy_socket->IsUsingSpdy()) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 if (connection_->socket() && !connection_->is_reused()) 1012 if (connection_->socket() && !connection_->is_reused())
976 SetSocketMotivation(); 1013 SetSocketMotivation();
977 1014
978 if (!using_spdy_) { 1015 if (!using_spdy_) {
979 // We may get ftp scheme when fetching ftp resources through proxy. 1016 // We may get ftp scheme when fetching ftp resources through proxy.
980 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && 1017 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) &&
981 (request_info_.url.SchemeIs("http") || 1018 (request_info_.url.SchemeIs("http") ||
982 request_info_.url.SchemeIs("ftp")); 1019 request_info_.url.SchemeIs("ftp"));
983 if (stream_factory_->http_pipelined_host_pool_. 1020 if (stream_factory_->http_pipelined_host_pool_.
984 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { 1021 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) {
1022 DCHECK(!stream_factory_->for_websockets_);
985 stream_.reset(stream_factory_->http_pipelined_host_pool_. 1023 stream_.reset(stream_factory_->http_pipelined_host_pool_.
986 CreateStreamOnExistingPipeline( 1024 CreateStreamOnExistingPipeline(
987 *http_pipelining_key_.get())); 1025 *http_pipelining_key_.get()));
988 CHECK(stream_.get()); 1026 CHECK(stream_.get());
1027 } else if (stream_factory_->for_websockets_) {
1028 DCHECK(request_ && request_->websocket_stream_factory());
mmenke 2013/06/10 20:26:03 If we're orphaned before this point, request_ will
yhirano 2013/06/11 11:13:16 I chose the third way.
mmenke 2013/06/12 02:27:05 Just deleting the waiter in the unit tests before
mmenke 2013/06/12 02:31:13 You may need to create mock socket data that conne
mmenke 2013/06/12 02:54:25 Actually, I think we should make sure there is a p
yhirano 2013/06/12 06:44:56 Neither deleting waiter nor request call HttpStrea
mmenke 2013/06/12 18:21:33 You're right - all calls to OrphanJobs go through
yhirano 2013/06/13 14:20:38 Done. To control the timing of socket connection,
1029 websocket_stream_.reset(
1030 request_->websocket_stream_factory()->CreateBasicStream(
1031 connection_.release(), using_proxy));
989 } else if (!using_proxy && IsRequestEligibleForPipelining()) { 1032 } else if (!using_proxy && IsRequestEligibleForPipelining()) {
990 // TODO(simonjam): Support proxies. 1033 // TODO(simonjam): Support proxies.
991 stream_.reset( 1034 stream_.reset(
992 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( 1035 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline(
993 *http_pipelining_key_.get(), 1036 *http_pipelining_key_.get(),
994 connection_.release(), 1037 connection_.release(),
995 server_ssl_config_, 1038 server_ssl_config_,
996 proxy_info_, 1039 proxy_info_,
997 net_log_, 1040 net_log_,
998 was_npn_negotiated_, 1041 was_npn_negotiated_,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 } 1093 }
1051 } 1094 }
1052 1095
1053 if (spdy_session->IsClosed()) 1096 if (spdy_session->IsClosed())
1054 return ERR_CONNECTION_CLOSED; 1097 return ERR_CONNECTION_CLOSED;
1055 1098
1056 // TODO(willchan): Delete this code, because eventually, the 1099 // TODO(willchan): Delete this code, because eventually, the
1057 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it 1100 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
1058 // will know when SpdySessions become available. 1101 // will know when SpdySessions become available.
1059 1102
1060 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); 1103 if (stream_factory_->for_websockets_) {
1061 stream_.reset(new SpdyHttpStream(spdy_session.get(), use_relative_url)); 1104 bool use_relative_url = direct || request_info_.url.SchemeIs("wss");
1105 websocket_stream_.reset(
1106 request_->websocket_stream_factory()->CreateSpdyStream(
1107 spdy_session, use_relative_url));
1108 } else {
1109 bool use_relative_url = direct || request_info_.url.SchemeIs("https");
1110 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url));
1111 }
1062 return OK; 1112 return OK;
1063 } 1113 }
1064 1114
1065 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { 1115 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) {
1066 if (result < 0) 1116 if (result < 0)
1067 return result; 1117 return result;
1068 1118
1069 session_->proxy_service()->ReportSuccess(proxy_info_); 1119 session_->proxy_service()->ReportSuccess(proxy_info_);
1070 next_state_ = STATE_NONE; 1120 next_state_ = STATE_NONE;
1071 return OK; 1121 return OK;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 } 1402 }
1353 1403
1354 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { 1404 bool HttpStreamFactoryImpl::Job::IsOrphaned() const {
1355 return !IsPreconnecting() && !request_; 1405 return !IsPreconnecting() && !request_;
1356 } 1406 }
1357 1407
1358 bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() { 1408 bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() {
1359 if (IsPreconnecting() || !request_) { 1409 if (IsPreconnecting() || !request_) {
1360 return false; 1410 return false;
1361 } 1411 }
1412 if (stream_factory_->for_websockets_) {
1413 return false;
1414 }
1362 if (session_->force_http_pipelining()) { 1415 if (session_->force_http_pipelining()) {
1363 return true; 1416 return true;
1364 } 1417 }
1365 if (!session_->params().http_pipelining_enabled) { 1418 if (!session_->params().http_pipelining_enabled) {
1366 return false; 1419 return false;
1367 } 1420 }
1368 if (using_ssl_) { 1421 if (using_ssl_) {
1369 return false; 1422 return false;
1370 } 1423 }
1371 if (request_info_.method != "GET" && request_info_.method != "HEAD") { 1424 if (request_info_.method != "GET" && request_info_.method != "HEAD") {
1372 return false; 1425 return false;
1373 } 1426 }
1374 if (request_info_.load_flags & 1427 if (request_info_.load_flags &
1375 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | 1428 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH |
1376 net::LOAD_IS_DOWNLOAD)) { 1429 net::LOAD_IS_DOWNLOAD)) {
1377 // Avoid pipelining resources that may be streamed for a long time. 1430 // Avoid pipelining resources that may be streamed for a long time.
1378 return false; 1431 return false;
1379 } 1432 }
1380 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( 1433 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining(
1381 *http_pipelining_key_.get()); 1434 *http_pipelining_key_.get());
1382 } 1435 }
1383 1436
1384 } // namespace net 1437 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698