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

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

Powered by Google App Engine
This is Rietveld 408576698