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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 | 1021 |
1022 int HttpStreamFactoryImpl::Job::DoWaitingUserAction(int result) { | 1022 int HttpStreamFactoryImpl::Job::DoWaitingUserAction(int result) { |
1023 // This state indicates that the stream request is in a partially | 1023 // This state indicates that the stream request is in a partially |
1024 // completed state, and we've called back to the delegate for more | 1024 // completed state, and we've called back to the delegate for more |
1025 // information. | 1025 // information. |
1026 | 1026 |
1027 // We're always waiting here for the delegate to call us back. | 1027 // We're always waiting here for the delegate to call us back. |
1028 return ERR_IO_PENDING; | 1028 return ERR_IO_PENDING; |
1029 } | 1029 } |
1030 | 1030 |
| 1031 int HttpStreamFactoryImpl::Job::SetSpdyHttpStream( |
| 1032 base::WeakPtr<SpdySession> session, bool direct) { |
| 1033 // TODO(ricea): Restore the code for WebSockets over SPDY once it's |
| 1034 // implemented. |
| 1035 if (stream_factory_->for_websockets_) |
| 1036 return ERR_NOT_IMPLEMENTED; |
| 1037 |
| 1038 // TODO(willchan): Delete this code, because eventually, the |
| 1039 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
| 1040 // will know when SpdySessions become available. |
| 1041 |
| 1042 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); |
| 1043 stream_.reset(new SpdyHttpStream(session, use_relative_url)); |
| 1044 return OK; |
| 1045 } |
| 1046 |
1031 int HttpStreamFactoryImpl::Job::DoCreateStream() { | 1047 int HttpStreamFactoryImpl::Job::DoCreateStream() { |
1032 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_); | 1048 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_); |
1033 | 1049 |
1034 next_state_ = STATE_CREATE_STREAM_COMPLETE; | 1050 next_state_ = STATE_CREATE_STREAM_COMPLETE; |
1035 | 1051 |
1036 // We only set the socket motivation if we're the first to use | 1052 // We only set the socket motivation if we're the first to use |
1037 // this socket. Is there a race for two SPDY requests? We really | 1053 // this socket. Is there a race for two SPDY requests? We really |
1038 // need to plumb this through to the connect level. | 1054 // need to plumb this through to the connect level. |
1039 if (connection_->socket() && !connection_->is_reused()) | 1055 if (connection_->socket() && !connection_->is_reused()) |
1040 SetSocketMotivation(); | 1056 SetSocketMotivation(); |
(...skipping 13 matching lines...) Expand all Loading... |
1054 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); | 1070 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); |
1055 } | 1071 } |
1056 return OK; | 1072 return OK; |
1057 } | 1073 } |
1058 | 1074 |
1059 CHECK(!stream_.get()); | 1075 CHECK(!stream_.get()); |
1060 | 1076 |
1061 bool direct = true; | 1077 bool direct = true; |
1062 const ProxyServer& proxy_server = proxy_info_.proxy_server(); | 1078 const ProxyServer& proxy_server = proxy_info_.proxy_server(); |
1063 PrivacyMode privacy_mode = request_info_.privacy_mode; | 1079 PrivacyMode privacy_mode = request_info_.privacy_mode; |
| 1080 if (IsHttpsProxyAndHttpUrl()) |
| 1081 direct = false; |
| 1082 |
| 1083 if (existing_spdy_session_.get()) { |
| 1084 // We picked up an existing session, so we don't need our socket. |
| 1085 if (connection_->socket()) |
| 1086 connection_->socket()->Disconnect(); |
| 1087 connection_->Reset(); |
| 1088 |
| 1089 int set_result = SetSpdyHttpStream(existing_spdy_session_, direct); |
| 1090 existing_spdy_session_.reset(); |
| 1091 return set_result; |
| 1092 } |
| 1093 |
1064 SpdySessionKey spdy_session_key(origin_, proxy_server, privacy_mode); | 1094 SpdySessionKey spdy_session_key(origin_, proxy_server, privacy_mode); |
1065 if (IsHttpsProxyAndHttpUrl()) { | 1095 if (IsHttpsProxyAndHttpUrl()) { |
1066 // If we don't have a direct SPDY session, and we're using an HTTPS | 1096 // If we don't have a direct SPDY session, and we're using an HTTPS |
1067 // proxy, then we might have a SPDY session to the proxy. | 1097 // proxy, then we might have a SPDY session to the proxy. |
1068 // We never use privacy mode for connection to proxy server. | 1098 // We never use privacy mode for connection to proxy server. |
1069 spdy_session_key = SpdySessionKey(proxy_server.host_port_pair(), | 1099 spdy_session_key = SpdySessionKey(proxy_server.host_port_pair(), |
1070 ProxyServer::Direct(), | 1100 ProxyServer::Direct(), |
1071 PRIVACY_MODE_DISABLED); | 1101 PRIVACY_MODE_DISABLED); |
1072 direct = false; | |
1073 } | 1102 } |
1074 | 1103 |
1075 base::WeakPtr<SpdySession> spdy_session; | 1104 SpdySessionPool* spdy_pool = session_->spdy_session_pool(); |
1076 if (existing_spdy_session_.get()) { | 1105 base::WeakPtr<SpdySession> spdy_session = |
1077 // We picked up an existing session, so we don't need our socket. | 1106 spdy_pool->FindAvailableSession(spdy_session_key, net_log_); |
1078 if (connection_->socket()) | |
1079 connection_->socket()->Disconnect(); | |
1080 connection_->Reset(); | |
1081 std::swap(spdy_session, existing_spdy_session_); | |
1082 } else { | |
1083 SpdySessionPool* spdy_pool = session_->spdy_session_pool(); | |
1084 spdy_session = spdy_pool->FindAvailableSession(spdy_session_key, net_log_); | |
1085 if (!spdy_session) { | |
1086 base::WeakPtr<SpdySession> new_spdy_session = | |
1087 spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key, | |
1088 connection_.Pass(), | |
1089 net_log_, | |
1090 spdy_certificate_error_, | |
1091 using_ssl_); | |
1092 if (!new_spdy_session->HasAcceptableTransportSecurity()) { | |
1093 new_spdy_session->CloseSessionOnError( | |
1094 ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, ""); | |
1095 return ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY; | |
1096 } | |
1097 | 1107 |
1098 new_spdy_session_ = new_spdy_session; | 1108 if (spdy_session) { |
1099 spdy_session_direct_ = direct; | 1109 return SetSpdyHttpStream(spdy_session, direct); |
1100 const HostPortPair& host_port_pair = spdy_session_key.host_port_pair(); | |
1101 base::WeakPtr<HttpServerProperties> http_server_properties = | |
1102 session_->http_server_properties(); | |
1103 if (http_server_properties) | |
1104 http_server_properties->SetSupportsSpdy(host_port_pair, true); | |
1105 | |
1106 // Create a SpdyHttpStream attached to the session; | |
1107 // OnNewSpdySessionReadyCallback is not called until an event loop | |
1108 // iteration later, so if the SpdySession is closed between then, allow | |
1109 // reuse state from the underlying socket, sampled by SpdyHttpStream, | |
1110 // bubble up to the request. | |
1111 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | |
1112 stream_.reset(new SpdyHttpStream(new_spdy_session_, use_relative_url)); | |
1113 | |
1114 return OK; | |
1115 } | |
1116 } | 1110 } |
1117 | 1111 |
1118 if (!spdy_session) | 1112 spdy_session = |
1119 return ERR_CONNECTION_CLOSED; | 1113 spdy_pool->CreateAvailableSessionFromSocket(spdy_session_key, |
| 1114 connection_.Pass(), |
| 1115 net_log_, |
| 1116 spdy_certificate_error_, |
| 1117 using_ssl_); |
| 1118 if (!spdy_session->HasAcceptableTransportSecurity()) { |
| 1119 spdy_session->CloseSessionOnError( |
| 1120 ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, ""); |
| 1121 return ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY; |
| 1122 } |
1120 | 1123 |
1121 // TODO(willchan): Delete this code, because eventually, the | 1124 new_spdy_session_ = spdy_session; |
1122 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1125 spdy_session_direct_ = direct; |
1123 // will know when SpdySessions become available. | 1126 const HostPortPair& host_port_pair = spdy_session_key.host_port_pair(); |
| 1127 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 1128 session_->http_server_properties(); |
| 1129 if (http_server_properties) |
| 1130 http_server_properties->SetSupportsSpdy(host_port_pair, true); |
1124 | 1131 |
1125 // TODO(ricea): Restore the code for WebSockets over SPDY once it's | 1132 // Create a SpdyHttpStream attached to the session; |
1126 // implemented. | 1133 // OnNewSpdySessionReadyCallback is not called until an event loop |
1127 if (stream_factory_->for_websockets_) | 1134 // iteration later, so if the SpdySession is closed between then, allow |
1128 return ERR_NOT_IMPLEMENTED; | 1135 // reuse state from the underlying socket, sampled by SpdyHttpStream, |
1129 | 1136 // bubble up to the request. |
1130 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1137 return SetSpdyHttpStream(new_spdy_session_, spdy_session_direct_); |
1131 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); | |
1132 | |
1133 return OK; | |
1134 } | 1138 } |
1135 | 1139 |
1136 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { | 1140 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { |
1137 if (result < 0) | 1141 if (result < 0) |
1138 return result; | 1142 return result; |
1139 | 1143 |
1140 session_->proxy_service()->ReportSuccess(proxy_info_, | 1144 session_->proxy_service()->ReportSuccess(proxy_info_, |
1141 session_->network_delegate()); | 1145 session_->network_delegate()); |
1142 next_state_ = STATE_NONE; | 1146 next_state_ = STATE_NONE; |
1143 return OK; | 1147 return OK; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 | 1478 |
1475 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { | 1479 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { |
1476 HistogramBrokenAlternateProtocolLocation( | 1480 HistogramBrokenAlternateProtocolLocation( |
1477 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); | 1481 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); |
1478 session_->http_server_properties()->SetBrokenAlternateProtocol( | 1482 session_->http_server_properties()->SetBrokenAlternateProtocol( |
1479 HostPortPair::FromURL(request_info_.url)); | 1483 HostPortPair::FromURL(request_info_.url)); |
1480 } | 1484 } |
1481 } | 1485 } |
1482 | 1486 |
1483 } // namespace net | 1487 } // namespace net |
OLD | NEW |