| 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/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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 request_->Complete(was_npn_negotiated(), | 286 request_->Complete(was_npn_negotiated(), |
| 285 protocol_negotiated(), | 287 protocol_negotiated(), |
| 286 using_spdy(), | 288 using_spdy(), |
| 287 net_log_); | 289 net_log_); |
| 288 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, | 290 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, |
| 289 stream_.release()); | 291 stream_.release()); |
| 290 } | 292 } |
| 291 // |this| may be deleted after this call. | 293 // |this| may be deleted after this call. |
| 292 } | 294 } |
| 293 | 295 |
| 296 void HttpStreamFactoryImpl::Job::OnSocketReadyCallback() { |
| 297 DCHECK(request_->for_websocket()); |
| 298 DCHECK(connection_.get()); |
| 299 DCHECK(!IsPreconnecting()); |
| 300 if (IsOrphaned()) { |
| 301 stream_factory_->OnOrphanedJobComplete(this); |
| 302 } else { |
| 303 request_->Complete(was_npn_negotiated(), |
| 304 protocol_negotiated(), |
| 305 using_spdy(), |
| 306 net_log_); |
| 307 request_->OnSocketReady(this, server_ssl_config_, proxy_info_, |
| 308 connection_.release()); |
| 309 } |
| 310 // |this| may be deleted after this call. |
| 311 } |
| 312 |
| 313 void HttpStreamFactoryImpl::Job::OnSpdySessionReadyForWSCallback() { |
| 314 DCHECK(request_->for_websocket()); |
| 315 DCHECK(spdy_session_to_pass_); |
| 316 DCHECK(!IsPreconnecting()); |
| 317 scoped_refptr<SpdySession> session = spdy_session_to_pass_; |
| 318 spdy_session_to_pass_ = NULL; |
| 319 if (IsOrphaned()) { |
| 320 stream_factory_->OnOrphanedJobComplete(this); |
| 321 } else { |
| 322 request_->Complete(was_npn_negotiated(), |
| 323 protocol_negotiated(), |
| 324 using_spdy(), |
| 325 net_log_); |
| 326 request_->OnSpdySessionReadyForWS(this, server_ssl_config_, proxy_info_, |
| 327 session); |
| 328 } |
| 329 // |this| may be deleted after this call. |
| 330 } |
| 331 |
| 294 void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() { | 332 void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() { |
| 295 DCHECK(!stream_.get()); | 333 DCHECK(!stream_.get()); |
| 296 DCHECK(!IsPreconnecting()); | 334 DCHECK(!IsPreconnecting()); |
| 297 DCHECK(using_spdy()); | 335 DCHECK(using_spdy()); |
| 298 DCHECK(new_spdy_session_); | 336 DCHECK(new_spdy_session_); |
| 299 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; | 337 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; |
| 300 new_spdy_session_ = NULL; | 338 new_spdy_session_ = NULL; |
| 301 if (IsOrphaned()) { | 339 if (IsOrphaned()) { |
| 302 stream_factory_->OnSpdySessionReady( | 340 stream_factory_->OnSpdySessionReady( |
| 303 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, | 341 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 base::Bind( | 508 base::Bind( |
| 471 &HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback, | 509 &HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback, |
| 472 ptr_factory_.GetWeakPtr(), | 510 ptr_factory_.GetWeakPtr(), |
| 473 *proxy_socket->GetConnectResponseInfo(), | 511 *proxy_socket->GetConnectResponseInfo(), |
| 474 proxy_socket->CreateConnectResponseStream())); | 512 proxy_socket->CreateConnectResponseStream())); |
| 475 return ERR_IO_PENDING; | 513 return ERR_IO_PENDING; |
| 476 } | 514 } |
| 477 | 515 |
| 478 case OK: | 516 case OK: |
| 479 next_state_ = STATE_DONE; | 517 next_state_ = STATE_DONE; |
| 480 if (new_spdy_session_) { | 518 if (request_->for_websocket()) { |
| 519 if (spdy_session_to_pass_) { |
| 520 MessageLoop::current()->PostTask( |
| 521 FROM_HERE, |
| 522 base::Bind( |
| 523 &HttpStreamFactoryImpl::Job::OnSpdySessionReadyForWSCallback, |
| 524 ptr_factory_.GetWeakPtr())); |
| 525 } else if (connection_ && connection_->is_initialized()) { |
| 526 MessageLoop::current()->PostTask( |
| 527 FROM_HERE, |
| 528 base::Bind( |
| 529 &HttpStreamFactoryImpl::Job::OnSocketReadyCallback, |
| 530 ptr_factory_.GetWeakPtr())); |
| 531 } else { |
| 532 return ERR_FAILED; |
| 533 } |
| 534 } else if (new_spdy_session_) { |
| 481 MessageLoop::current()->PostTask( | 535 MessageLoop::current()->PostTask( |
| 482 FROM_HERE, | 536 FROM_HERE, |
| 483 base::Bind( | 537 base::Bind( |
| 484 &HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback, | 538 &HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback, |
| 485 ptr_factory_.GetWeakPtr())); | 539 ptr_factory_.GetWeakPtr())); |
| 486 } else { | 540 } else { |
| 487 MessageLoop::current()->PostTask( | 541 MessageLoop::current()->PostTask( |
| 488 FROM_HERE, | 542 FROM_HERE, |
| 489 base::Bind( | 543 base::Bind( |
| 490 &HttpStreamFactoryImpl::Job::OnStreamReadyCallback, | 544 &HttpStreamFactoryImpl::Job::OnStreamReadyCallback, |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 if (ssl_socket->WasNpnNegotiated()) { | 901 if (ssl_socket->WasNpnNegotiated()) { |
| 848 was_npn_negotiated_ = true; | 902 was_npn_negotiated_ = true; |
| 849 std::string proto; | 903 std::string proto; |
| 850 std::string server_protos; | 904 std::string server_protos; |
| 851 SSLClientSocket::NextProtoStatus status = | 905 SSLClientSocket::NextProtoStatus status = |
| 852 ssl_socket->GetNextProto(&proto, &server_protos); | 906 ssl_socket->GetNextProto(&proto, &server_protos); |
| 853 NextProto protocol_negotiated = | 907 NextProto protocol_negotiated = |
| 854 SSLClientSocket::NextProtoFromString(proto); | 908 SSLClientSocket::NextProtoFromString(proto); |
| 855 protocol_negotiated_ = protocol_negotiated; | 909 protocol_negotiated_ = protocol_negotiated; |
| 856 net_log_.AddEvent( | 910 net_log_.AddEvent( |
| 857 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, | 911 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, |
| 858 base::Bind(&NetLogHttpStreamProtoCallback, | 912 base::Bind(&NetLogHttpStreamProtoCallback, |
| 859 status, &proto, &server_protos)); | 913 status, &proto, &server_protos)); |
| 860 if (ssl_socket->was_spdy_negotiated()) | 914 if (ssl_socket->was_spdy_negotiated()) |
| 861 SwitchToSpdyMode(); | 915 SwitchToSpdyMode(); |
| 862 } | 916 } |
| 863 if (ShouldForceSpdySSL()) | 917 if (ShouldForceSpdySSL()) |
| 864 SwitchToSpdyMode(); | 918 SwitchToSpdyMode(); |
| 865 } else if (proxy_info_.is_https() && connection_->socket() && | 919 } else if (proxy_info_.is_https() && connection_->socket() && |
| 866 result == OK) { | 920 result == OK) { |
| 867 ProxyClientSocket* proxy_socket = | 921 ProxyClientSocket* proxy_socket = |
| 868 static_cast<ProxyClientSocket*>(connection_->socket()); | 922 static_cast<ProxyClientSocket*>(connection_->socket()); |
| 869 if (proxy_socket->IsUsingSpdy()) { | 923 if (proxy_socket->IsUsingSpdy()) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 if (connection_->socket() && !connection_->is_reused()) | 1017 if (connection_->socket() && !connection_->is_reused()) |
| 964 SetSocketMotivation(); | 1018 SetSocketMotivation(); |
| 965 | 1019 |
| 966 if (!using_spdy_) { | 1020 if (!using_spdy_) { |
| 967 // We may get ftp scheme when fetching ftp resources through proxy. | 1021 // We may get ftp scheme when fetching ftp resources through proxy. |
| 968 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && | 1022 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && |
| 969 (request_info_.url.SchemeIs("http") || | 1023 (request_info_.url.SchemeIs("http") || |
| 970 request_info_.url.SchemeIs("ftp")); | 1024 request_info_.url.SchemeIs("ftp")); |
| 971 if (stream_factory_->http_pipelined_host_pool_. | 1025 if (stream_factory_->http_pipelined_host_pool_. |
| 972 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { | 1026 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { |
| 1027 DCHECK(!request_->for_websocket()); |
| 973 stream_.reset(stream_factory_->http_pipelined_host_pool_. | 1028 stream_.reset(stream_factory_->http_pipelined_host_pool_. |
| 974 CreateStreamOnExistingPipeline( | 1029 CreateStreamOnExistingPipeline( |
| 975 *http_pipelining_key_.get())); | 1030 *http_pipelining_key_.get())); |
| 976 CHECK(stream_.get()); | 1031 CHECK(stream_.get()); |
| 1032 } else if (request_->for_websocket()) { |
| 1033 // Do nothing. |
| 1034 // connection_ will be passed to the delegate. |
| 977 } else if (!using_proxy && IsRequestEligibleForPipelining()) { | 1035 } else if (!using_proxy && IsRequestEligibleForPipelining()) { |
| 978 // TODO(simonjam): Support proxies. | 1036 // TODO(simonjam): Support proxies. |
| 979 stream_.reset( | 1037 stream_.reset( |
| 980 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( | 1038 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( |
| 981 *http_pipelining_key_.get(), | 1039 *http_pipelining_key_.get(), |
| 982 connection_.release(), | 1040 connection_.release(), |
| 983 server_ssl_config_, | 1041 server_ssl_config_, |
| 984 proxy_info_, | 1042 proxy_info_, |
| 985 net_log_, | 1043 net_log_, |
| 986 was_npn_negotiated_, | 1044 was_npn_negotiated_, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 pair, connection_.release(), net_log_, spdy_certificate_error_, | 1079 pair, connection_.release(), net_log_, spdy_certificate_error_, |
| 1022 &new_spdy_session_, using_ssl_); | 1080 &new_spdy_session_, using_ssl_); |
| 1023 if (error != OK) | 1081 if (error != OK) |
| 1024 return error; | 1082 return error; |
| 1025 const HostPortPair& host_port_pair = pair.first; | 1083 const HostPortPair& host_port_pair = pair.first; |
| 1026 HttpServerProperties* http_server_properties = | 1084 HttpServerProperties* http_server_properties = |
| 1027 session_->http_server_properties(); | 1085 session_->http_server_properties(); |
| 1028 if (http_server_properties) | 1086 if (http_server_properties) |
| 1029 http_server_properties->SetSupportsSpdy(host_port_pair, true); | 1087 http_server_properties->SetSupportsSpdy(host_port_pair, true); |
| 1030 spdy_session_direct_ = direct; | 1088 spdy_session_direct_ = direct; |
| 1089 if (request_->for_websocket()) { |
| 1090 DCHECK(!spdy_session_to_pass_); |
| 1091 spdy_session_to_pass_.swap(new_spdy_session_); |
| 1092 } |
| 1031 return OK; | 1093 return OK; |
| 1032 } | 1094 } |
| 1033 } | 1095 } |
| 1034 | 1096 |
| 1035 if (spdy_session->IsClosed()) | 1097 if (spdy_session->IsClosed()) |
| 1036 return ERR_CONNECTION_CLOSED; | 1098 return ERR_CONNECTION_CLOSED; |
| 1037 | 1099 |
| 1100 if (request_->for_websocket()) { |
| 1101 DCHECK(!spdy_session_to_pass_); |
| 1102 spdy_session_to_pass_.swap(spdy_session); |
| 1103 return OK; |
| 1104 } |
| 1105 |
| 1038 // TODO(willchan): Delete this code, because eventually, the | 1106 // TODO(willchan): Delete this code, because eventually, the |
| 1039 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1107 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
| 1040 // will know when SpdySessions become available. | 1108 // will know when SpdySessions become available. |
| 1041 | 1109 |
| 1042 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1110 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); |
| 1043 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); | 1111 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); |
| 1044 return OK; | 1112 return OK; |
| 1045 } | 1113 } |
| 1046 | 1114 |
| 1047 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { | 1115 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 } | 1398 } |
| 1331 | 1399 |
| 1332 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { | 1400 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { |
| 1333 return !IsPreconnecting() && !request_; | 1401 return !IsPreconnecting() && !request_; |
| 1334 } | 1402 } |
| 1335 | 1403 |
| 1336 bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() { | 1404 bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() { |
| 1337 if (IsPreconnecting() || !request_) { | 1405 if (IsPreconnecting() || !request_) { |
| 1338 return false; | 1406 return false; |
| 1339 } | 1407 } |
| 1408 if (request_->for_websocket()) { |
| 1409 return false; |
| 1410 } |
| 1340 if (session_->force_http_pipelining()) { | 1411 if (session_->force_http_pipelining()) { |
| 1341 return true; | 1412 return true; |
| 1342 } | 1413 } |
| 1343 if (!session_->params().http_pipelining_enabled) { | 1414 if (!session_->params().http_pipelining_enabled) { |
| 1344 return false; | 1415 return false; |
| 1345 } | 1416 } |
| 1346 if (using_ssl_) { | 1417 if (using_ssl_) { |
| 1347 return false; | 1418 return false; |
| 1348 } | 1419 } |
| 1349 if (request_info_.method != "GET" && request_info_.method != "HEAD") { | 1420 if (request_info_.method != "GET" && request_info_.method != "HEAD") { |
| 1350 return false; | 1421 return false; |
| 1351 } | 1422 } |
| 1352 if (request_info_.load_flags & | 1423 if (request_info_.load_flags & |
| 1353 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | | 1424 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | |
| 1354 net::LOAD_IS_DOWNLOAD)) { | 1425 net::LOAD_IS_DOWNLOAD)) { |
| 1355 // Avoid pipelining resources that may be streamed for a long time. | 1426 // Avoid pipelining resources that may be streamed for a long time. |
| 1356 return false; | 1427 return false; |
| 1357 } | 1428 } |
| 1358 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( | 1429 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( |
| 1359 *http_pipelining_key_.get()); | 1430 *http_pipelining_key_.get()); |
| 1360 } | 1431 } |
| 1361 | 1432 |
| 1362 } // namespace net | 1433 } // namespace net |
| OLD | NEW |