| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 alternative_proxy_server_(alternative_proxy_server), | 195 alternative_proxy_server_(alternative_proxy_server), |
| 196 delegate_(delegate), | 196 delegate_(delegate), |
| 197 job_type_(job_type), | 197 job_type_(job_type), |
| 198 using_ssl_(false), | 198 using_ssl_(false), |
| 199 using_spdy_(false), | 199 using_spdy_(false), |
| 200 using_quic_(false), | 200 using_quic_(false), |
| 201 quic_request_(session_->quic_stream_factory()), | 201 quic_request_(session_->quic_stream_factory()), |
| 202 using_existing_quic_session_(false), | 202 using_existing_quic_session_(false), |
| 203 spdy_certificate_error_(OK), | 203 spdy_certificate_error_(OK), |
| 204 establishing_tunnel_(false), | 204 establishing_tunnel_(false), |
| 205 was_npn_negotiated_(false), | 205 was_alpn_negotiated_(false), |
| 206 negotiated_protocol_(kProtoUnknown), | 206 negotiated_protocol_(kProtoUnknown), |
| 207 num_streams_(0), | 207 num_streams_(0), |
| 208 spdy_session_direct_(false), | 208 spdy_session_direct_(false), |
| 209 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), | 209 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), |
| 210 ptr_factory_(this) { | 210 ptr_factory_(this) { |
| 211 DCHECK(session); | 211 DCHECK(session); |
| 212 // The job can't have alternative service and alternative proxy server set at | 212 // The job can't have alternative service and alternative proxy server set at |
| 213 // the same time since alternative services are used for requests that are | 213 // the same time since alternative services are used for requests that are |
| 214 // fetched directly, while the alternative proxy server is used for requests | 214 // fetched directly, while the alternative proxy server is used for requests |
| 215 // that should be fetched using proxy. | 215 // that should be fetched using proxy. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 315 } |
| 316 // |this| may be deleted after this call. | 316 // |this| may be deleted after this call. |
| 317 } | 317 } |
| 318 | 318 |
| 319 void HttpStreamFactoryImpl::Job::SetPriority(RequestPriority priority) { | 319 void HttpStreamFactoryImpl::Job::SetPriority(RequestPriority priority) { |
| 320 priority_ = priority; | 320 priority_ = priority; |
| 321 // TODO(akalin): Propagate this to |connection_| and maybe the | 321 // TODO(akalin): Propagate this to |connection_| and maybe the |
| 322 // preconnect state. | 322 // preconnect state. |
| 323 } | 323 } |
| 324 | 324 |
| 325 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const { | 325 bool HttpStreamFactoryImpl::Job::was_alpn_negotiated() const { |
| 326 return was_npn_negotiated_; | 326 return was_alpn_negotiated_; |
| 327 } | 327 } |
| 328 | 328 |
| 329 NextProto HttpStreamFactoryImpl::Job::negotiated_protocol() const { | 329 NextProto HttpStreamFactoryImpl::Job::negotiated_protocol() const { |
| 330 return negotiated_protocol_; | 330 return negotiated_protocol_; |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool HttpStreamFactoryImpl::Job::using_spdy() const { | 333 bool HttpStreamFactoryImpl::Job::using_spdy() const { |
| 334 return using_spdy_; | 334 return using_spdy_; |
| 335 } | 335 } |
| 336 | 336 |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 // and connection_->socket() != NULL, then the SSL handshake ran and it | 999 // and connection_->socket() != NULL, then the SSL handshake ran and it |
| 1000 // is a potentially recoverable error. | 1000 // is a potentially recoverable error. |
| 1001 // and connection_->socket == NULL and connection_->is_ssl_error() is true, | 1001 // and connection_->socket == NULL and connection_->is_ssl_error() is true, |
| 1002 // then the SSL handshake ran with an unrecoverable error. | 1002 // then the SSL handshake ran with an unrecoverable error. |
| 1003 // otherwise, the error came from one of the other pools. | 1003 // otherwise, the error came from one of the other pools. |
| 1004 bool ssl_started = using_ssl_ && (result == OK || connection_->socket() || | 1004 bool ssl_started = using_ssl_ && (result == OK || connection_->socket() || |
| 1005 connection_->is_ssl_error()); | 1005 connection_->is_ssl_error()); |
| 1006 | 1006 |
| 1007 if (ssl_started && (result == OK || IsCertificateError(result))) { | 1007 if (ssl_started && (result == OK || IsCertificateError(result))) { |
| 1008 if (using_quic_ && result == OK) { | 1008 if (using_quic_ && result == OK) { |
| 1009 was_npn_negotiated_ = true; | 1009 was_alpn_negotiated_ = true; |
| 1010 negotiated_protocol_ = kProtoQUIC1SPDY3; | 1010 negotiated_protocol_ = kProtoQUIC1SPDY3; |
| 1011 } else { | 1011 } else { |
| 1012 SSLClientSocket* ssl_socket = | 1012 SSLClientSocket* ssl_socket = |
| 1013 static_cast<SSLClientSocket*>(connection_->socket()); | 1013 static_cast<SSLClientSocket*>(connection_->socket()); |
| 1014 if (ssl_socket->WasNpnNegotiated()) { | 1014 if (ssl_socket->WasNpnNegotiated()) { |
| 1015 was_npn_negotiated_ = true; | 1015 was_alpn_negotiated_ = true; |
| 1016 negotiated_protocol_ = ssl_socket->GetNegotiatedProtocol(); | 1016 negotiated_protocol_ = ssl_socket->GetNegotiatedProtocol(); |
| 1017 net_log_.AddEvent( | 1017 net_log_.AddEvent( |
| 1018 NetLogEventType::HTTP_STREAM_REQUEST_PROTO, | 1018 NetLogEventType::HTTP_STREAM_REQUEST_PROTO, |
| 1019 base::Bind(&NetLogHttpStreamProtoCallback, negotiated_protocol_)); | 1019 base::Bind(&NetLogHttpStreamProtoCallback, negotiated_protocol_)); |
| 1020 if (negotiated_protocol_ == kProtoHTTP2) | 1020 if (negotiated_protocol_ == kProtoHTTP2) |
| 1021 SwitchToSpdyMode(); | 1021 SwitchToSpdyMode(); |
| 1022 } | 1022 } |
| 1023 } | 1023 } |
| 1024 } else if (proxy_info_.is_https() && connection_->socket() && | 1024 } else if (proxy_info_.is_https() && connection_->socket() && |
| 1025 result == OK) { | 1025 result == OK) { |
| 1026 ProxyClientSocket* proxy_socket = | 1026 ProxyClientSocket* proxy_socket = |
| 1027 static_cast<ProxyClientSocket*>(connection_->socket()); | 1027 static_cast<ProxyClientSocket*>(connection_->socket()); |
| 1028 // http://crbug.com/642354 | 1028 // http://crbug.com/642354 |
| 1029 if (!proxy_socket->IsConnected()) | 1029 if (!proxy_socket->IsConnected()) |
| 1030 return ERR_CONNECTION_CLOSED; | 1030 return ERR_CONNECTION_CLOSED; |
| 1031 if (proxy_socket->IsUsingSpdy()) { | 1031 if (proxy_socket->IsUsingSpdy()) { |
| 1032 was_npn_negotiated_ = true; | 1032 was_alpn_negotiated_ = true; |
| 1033 negotiated_protocol_ = proxy_socket->GetProxyNegotiatedProtocol(); | 1033 negotiated_protocol_ = proxy_socket->GetProxyNegotiatedProtocol(); |
| 1034 SwitchToSpdyMode(); | 1034 SwitchToSpdyMode(); |
| 1035 } | 1035 } |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 if (result == ERR_PROXY_AUTH_REQUESTED || | 1038 if (result == ERR_PROXY_AUTH_REQUESTED || |
| 1039 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { | 1039 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
| 1040 DCHECK(!ssl_started); | 1040 DCHECK(!ssl_started); |
| 1041 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an | 1041 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an |
| 1042 // SSL socket, but there was an error before that could happen. This | 1042 // SSL socket, but there was an error before that could happen. This |
| 1043 // puts the in progress HttpProxy socket into |connection_| in order to | 1043 // puts the in progress HttpProxy socket into |connection_| in order to |
| 1044 // complete the auth (or read the response body). The tunnel restart code | 1044 // complete the auth (or read the response body). The tunnel restart code |
| 1045 // is careful to remove it before returning control to the rest of this | 1045 // is careful to remove it before returning control to the rest of this |
| 1046 // class. | 1046 // class. |
| 1047 connection_.reset(connection_->release_pending_http_proxy_connection()); | 1047 connection_.reset(connection_->release_pending_http_proxy_connection()); |
| 1048 return result; | 1048 return result; |
| 1049 } | 1049 } |
| 1050 | 1050 |
| 1051 if (proxy_info_.is_quic() && using_quic_ && result < 0) { | 1051 if (proxy_info_.is_quic() && using_quic_ && result < 0) { |
| 1052 using_quic_ = false; | 1052 using_quic_ = false; |
| 1053 return ReconsiderProxyAfterError(result); | 1053 return ReconsiderProxyAfterError(result); |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 if (IsSpdyAlternative() && !using_spdy_) | 1056 if (IsSpdyAlternative() && !using_spdy_) |
| 1057 return ERR_NPN_NEGOTIATION_FAILED; | 1057 return ERR_ALPN_NEGOTIATION_FAILED; |
| 1058 | 1058 |
| 1059 if (!ssl_started && result < 0 && | 1059 if (!ssl_started && result < 0 && |
| 1060 (IsSpdyAlternative() || IsQuicAlternative())) | 1060 (IsSpdyAlternative() || IsQuicAlternative())) |
| 1061 return result; | 1061 return result; |
| 1062 | 1062 |
| 1063 if (using_quic_) { | 1063 if (using_quic_) { |
| 1064 if (result < 0) | 1064 if (result < 0) |
| 1065 return result; | 1065 return result; |
| 1066 | 1066 |
| 1067 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 1067 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1521 | 1521 |
| 1522 ConnectionAttempts socket_attempts = connection_->connection_attempts(); | 1522 ConnectionAttempts socket_attempts = connection_->connection_attempts(); |
| 1523 if (connection_->socket()) { | 1523 if (connection_->socket()) { |
| 1524 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1524 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1525 } | 1525 } |
| 1526 | 1526 |
| 1527 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); | 1527 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); |
| 1528 } | 1528 } |
| 1529 | 1529 |
| 1530 } // namespace net | 1530 } // namespace net |
| OLD | NEW |