Chromium Code Reviews| 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; | |
|
tyoshino (SeeGerritForStatus)
2013/05/13 11:04:44
these lines need to be placed out of the following
yhirano
2013/05/13 11:45:50
This code is differenct from OnSocketReadyCallback
| |
| 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 (connection_) { | |
| 520 MessageLoop::current()->PostTask( | |
| 521 FROM_HERE, | |
| 522 base::Bind( | |
| 523 &HttpStreamFactoryImpl::Job::OnSocketReadyCallback, | |
| 524 ptr_factory_.GetWeakPtr())); | |
| 525 } else if (spdy_session_to_pass_) { | |
| 526 MessageLoop::current()->PostTask( | |
| 527 FROM_HERE, | |
| 528 base::Bind( | |
| 529 &HttpStreamFactoryImpl::Job::OnSpdySessionReadyForWSCallback, | |
| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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())) { |
| 973 stream_.reset(stream_factory_->http_pipelined_host_pool_. | 1027 stream_.reset(stream_factory_->http_pipelined_host_pool_. |
| 974 CreateStreamOnExistingPipeline( | 1028 CreateStreamOnExistingPipeline( |
| 975 *http_pipelining_key_.get())); | 1029 *http_pipelining_key_.get())); |
| 976 CHECK(stream_.get()); | 1030 CHECK(stream_.get()); |
| 1031 } else if (request_->for_websocket()) { | |
| 1032 // Do nothing. | |
| 1033 // connection_ will be passed to the delegate. | |
| 977 } else if (!using_proxy && IsRequestEligibleForPipelining()) { | 1034 } else if (!using_proxy && IsRequestEligibleForPipelining()) { |
| 978 // TODO(simonjam): Support proxies. | 1035 // TODO(simonjam): Support proxies. |
| 979 stream_.reset( | 1036 stream_.reset( |
| 980 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( | 1037 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( |
| 981 *http_pipelining_key_.get(), | 1038 *http_pipelining_key_.get(), |
| 982 connection_.release(), | 1039 connection_.release(), |
| 983 server_ssl_config_, | 1040 server_ssl_config_, |
| 984 proxy_info_, | 1041 proxy_info_, |
| 985 net_log_, | 1042 net_log_, |
| 986 was_npn_negotiated_, | 1043 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_, | 1078 pair, connection_.release(), net_log_, spdy_certificate_error_, |
| 1022 &new_spdy_session_, using_ssl_); | 1079 &new_spdy_session_, using_ssl_); |
| 1023 if (error != OK) | 1080 if (error != OK) |
| 1024 return error; | 1081 return error; |
| 1025 const HostPortPair& host_port_pair = pair.first; | 1082 const HostPortPair& host_port_pair = pair.first; |
| 1026 HttpServerProperties* http_server_properties = | 1083 HttpServerProperties* http_server_properties = |
| 1027 session_->http_server_properties(); | 1084 session_->http_server_properties(); |
| 1028 if (http_server_properties) | 1085 if (http_server_properties) |
| 1029 http_server_properties->SetSupportsSpdy(host_port_pair, true); | 1086 http_server_properties->SetSupportsSpdy(host_port_pair, true); |
| 1030 spdy_session_direct_ = direct; | 1087 spdy_session_direct_ = direct; |
| 1088 if (request_->for_websocket()) { | |
| 1089 spdy_session_to_pass_ = new_spdy_session_; | |
| 1090 new_spdy_session_ = NULL; | |
| 1091 } | |
| 1031 return OK; | 1092 return OK; |
| 1032 } | 1093 } |
| 1033 } | 1094 } |
| 1034 | 1095 |
| 1035 if (spdy_session->IsClosed()) | 1096 if (spdy_session->IsClosed()) |
| 1036 return ERR_CONNECTION_CLOSED; | 1097 return ERR_CONNECTION_CLOSED; |
| 1037 | 1098 |
| 1099 if (request_->for_websocket()) { | |
| 1100 spdy_session_to_pass_ = spdy_session; | |
| 1101 return OK; | |
| 1102 } | |
| 1103 | |
| 1038 // TODO(willchan): Delete this code, because eventually, the | 1104 // TODO(willchan): Delete this code, because eventually, the |
| 1039 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1105 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
| 1040 // will know when SpdySessions become available. | 1106 // will know when SpdySessions become available. |
| 1041 | 1107 |
| 1042 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1108 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); |
| 1043 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); | 1109 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); |
| 1044 return OK; | 1110 return OK; |
| 1045 } | 1111 } |
| 1046 | 1112 |
| 1047 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { | 1113 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1353 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | | 1419 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | |
| 1354 net::LOAD_IS_DOWNLOAD)) { | 1420 net::LOAD_IS_DOWNLOAD)) { |
| 1355 // Avoid pipelining resources that may be streamed for a long time. | 1421 // Avoid pipelining resources that may be streamed for a long time. |
| 1356 return false; | 1422 return false; |
| 1357 } | 1423 } |
| 1358 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( | 1424 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( |
| 1359 *http_pipelining_key_.get()); | 1425 *http_pipelining_key_.get()); |
| 1360 } | 1426 } |
| 1361 | 1427 |
| 1362 } // namespace net | 1428 } // namespace net |
| OLD | NEW |