| 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 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 } else { | 647 } else { |
| 648 DCHECK(stream_.get()); | 648 DCHECK(stream_.get()); |
| 649 job_stream_ready_start_time_ = base::TimeTicks::Now(); | 649 job_stream_ready_start_time_ = base::TimeTicks::Now(); |
| 650 base::ThreadTaskRunnerHandle::Get()->PostTask( | 650 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 651 FROM_HERE, | 651 FROM_HERE, |
| 652 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr())); | 652 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr())); |
| 653 } | 653 } |
| 654 return ERR_IO_PENDING; | 654 return ERR_IO_PENDING; |
| 655 | 655 |
| 656 default: | 656 default: |
| 657 DCHECK(result != ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN || | |
| 658 IsSpdyAlternative() || IsQuicAlternative()); | |
| 659 if (job_status_ != STATUS_BROKEN) { | 657 if (job_status_ != STATUS_BROKEN) { |
| 660 DCHECK_EQ(STATUS_RUNNING, job_status_); | 658 DCHECK_EQ(STATUS_RUNNING, job_status_); |
| 661 job_status_ = STATUS_FAILED; | 659 job_status_ = STATUS_FAILED; |
| 662 // TODO(bnc): If (result == ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN), | |
| 663 // then instead of marking alternative service broken, mark (origin, | |
| 664 // alternative service) couple as invalid. | |
| 665 MaybeMarkAlternativeServiceBroken(); | 660 MaybeMarkAlternativeServiceBroken(); |
| 666 } | 661 } |
| 667 base::ThreadTaskRunnerHandle::Get()->PostTask( | 662 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 668 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, | 663 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, |
| 669 ptr_factory_.GetWeakPtr(), result)); | 664 ptr_factory_.GetWeakPtr(), result)); |
| 670 return ERR_IO_PENDING; | 665 return ERR_IO_PENDING; |
| 671 } | 666 } |
| 672 } | 667 } |
| 673 | 668 |
| 674 int HttpStreamFactoryImpl::Job::DoLoop(int result) { | 669 int HttpStreamFactoryImpl::Job::DoLoop(int result) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 | 726 |
| 732 int HttpStreamFactoryImpl::Job::StartInternal() { | 727 int HttpStreamFactoryImpl::Job::StartInternal() { |
| 733 CHECK_EQ(STATE_NONE, next_state_); | 728 CHECK_EQ(STATE_NONE, next_state_); |
| 734 next_state_ = STATE_START; | 729 next_state_ = STATE_START; |
| 735 int rv = RunLoop(OK); | 730 int rv = RunLoop(OK); |
| 736 DCHECK_EQ(ERR_IO_PENDING, rv); | 731 DCHECK_EQ(ERR_IO_PENDING, rv); |
| 737 return rv; | 732 return rv; |
| 738 } | 733 } |
| 739 | 734 |
| 740 int HttpStreamFactoryImpl::Job::DoStart() { | 735 int HttpStreamFactoryImpl::Job::DoStart() { |
| 741 valid_spdy_session_pool_.reset(new ValidSpdySessionPool( | |
| 742 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative())); | |
| 743 const BoundNetLog* net_log = delegate_->GetNetLog(this); | 736 const BoundNetLog* net_log = delegate_->GetNetLog(this); |
| 744 | 737 |
| 745 if (net_log) { | 738 if (net_log) { |
| 746 net_log_.BeginEvent( | 739 net_log_.BeginEvent( |
| 747 NetLog::TYPE_HTTP_STREAM_JOB, | 740 NetLog::TYPE_HTTP_STREAM_JOB, |
| 748 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(), | 741 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(), |
| 749 &request_info_.url, &origin_url_, &alternative_service_, | 742 &request_info_.url, &origin_url_, &alternative_service_, |
| 750 priority_)); | 743 priority_)); |
| 751 net_log->AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, | 744 net_log->AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, |
| 752 net_log_.source().ToEventParametersCallback()); | 745 net_log_.source().ToEventParametersCallback()); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 } | 964 } |
| 972 } | 965 } |
| 973 return rv; | 966 return rv; |
| 974 } | 967 } |
| 975 | 968 |
| 976 SpdySessionKey spdy_session_key = GetSpdySessionKey(); | 969 SpdySessionKey spdy_session_key = GetSpdySessionKey(); |
| 977 | 970 |
| 978 // Check first if we have a spdy session for this group. If so, then go | 971 // Check first if we have a spdy session for this group. If so, then go |
| 979 // straight to using that. | 972 // straight to using that. |
| 980 if (CanUseExistingSpdySession()) { | 973 if (CanUseExistingSpdySession()) { |
| 981 base::WeakPtr<SpdySession> spdy_session; | 974 base::WeakPtr<SpdySession> spdy_session = |
| 982 int result = valid_spdy_session_pool_->FindAvailableSession( | 975 session_->spdy_session_pool()->FindAvailableSession( |
| 983 spdy_session_key, net_log_, &spdy_session); | 976 spdy_session_key, origin_url_, net_log_); |
| 984 if (result != OK) | |
| 985 return result; | |
| 986 if (spdy_session) { | 977 if (spdy_session) { |
| 987 // If we're preconnecting, but we already have a SpdySession, we don't | 978 // If we're preconnecting, but we already have a SpdySession, we don't |
| 988 // actually need to preconnect any sockets, so we're done. | 979 // actually need to preconnect any sockets, so we're done. |
| 989 if (job_type_ == PRECONNECT) | 980 if (job_type_ == PRECONNECT) |
| 990 return OK; | 981 return OK; |
| 991 using_spdy_ = true; | 982 using_spdy_ = true; |
| 992 next_state_ = STATE_CREATE_STREAM; | 983 next_state_ = STATE_CREATE_STREAM; |
| 993 existing_spdy_session_ = spdy_session; | 984 existing_spdy_session_ = spdy_session; |
| 994 return OK; | 985 return OK; |
| 995 } | 986 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 | 1159 |
| 1169 if (IsSpdyAlternative() && !using_spdy_) { | 1160 if (IsSpdyAlternative() && !using_spdy_) { |
| 1170 job_status_ = STATUS_BROKEN; | 1161 job_status_ = STATUS_BROKEN; |
| 1171 MaybeMarkAlternativeServiceBroken(); | 1162 MaybeMarkAlternativeServiceBroken(); |
| 1172 return ERR_NPN_NEGOTIATION_FAILED; | 1163 return ERR_NPN_NEGOTIATION_FAILED; |
| 1173 } | 1164 } |
| 1174 | 1165 |
| 1175 if (!ssl_started && result < 0 && | 1166 if (!ssl_started && result < 0 && |
| 1176 (IsSpdyAlternative() || IsQuicAlternative())) { | 1167 (IsSpdyAlternative() || IsQuicAlternative())) { |
| 1177 job_status_ = STATUS_BROKEN; | 1168 job_status_ = STATUS_BROKEN; |
| 1178 // TODO(bnc): if (result == ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN), then | |
| 1179 // instead of marking alternative service broken, mark (origin, alternative | |
| 1180 // service) couple as invalid. | |
| 1181 MaybeMarkAlternativeServiceBroken(); | 1169 MaybeMarkAlternativeServiceBroken(); |
| 1182 return result; | 1170 return result; |
| 1183 } | 1171 } |
| 1184 | 1172 |
| 1185 if (using_quic_) { | 1173 if (using_quic_) { |
| 1186 if (result < 0) { | 1174 if (result < 0) { |
| 1187 job_status_ = STATUS_BROKEN; | 1175 job_status_ = STATUS_BROKEN; |
| 1188 MaybeMarkAlternativeServiceBroken(); | 1176 MaybeMarkAlternativeServiceBroken(); |
| 1189 return result; | 1177 return result; |
| 1190 } | 1178 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 connection_->socket()->Disconnect(); | 1302 connection_->socket()->Disconnect(); |
| 1315 connection_->Reset(); | 1303 connection_->Reset(); |
| 1316 | 1304 |
| 1317 int set_result = SetSpdyHttpStreamOrBidirectionalStreamImpl( | 1305 int set_result = SetSpdyHttpStreamOrBidirectionalStreamImpl( |
| 1318 existing_spdy_session_, direct); | 1306 existing_spdy_session_, direct); |
| 1319 existing_spdy_session_.reset(); | 1307 existing_spdy_session_.reset(); |
| 1320 return set_result; | 1308 return set_result; |
| 1321 } | 1309 } |
| 1322 | 1310 |
| 1323 SpdySessionKey spdy_session_key = GetSpdySessionKey(); | 1311 SpdySessionKey spdy_session_key = GetSpdySessionKey(); |
| 1324 base::WeakPtr<SpdySession> spdy_session; | 1312 base::WeakPtr<SpdySession> spdy_session = |
| 1325 int result = valid_spdy_session_pool_->FindAvailableSession( | 1313 session_->spdy_session_pool()->FindAvailableSession( |
| 1326 spdy_session_key, net_log_, &spdy_session); | 1314 spdy_session_key, origin_url_, net_log_); |
| 1327 if (result != OK) { | |
| 1328 return result; | |
| 1329 } | |
| 1330 if (spdy_session) { | 1315 if (spdy_session) { |
| 1331 return SetSpdyHttpStreamOrBidirectionalStreamImpl(spdy_session, direct); | 1316 return SetSpdyHttpStreamOrBidirectionalStreamImpl(spdy_session, direct); |
| 1332 } | 1317 } |
| 1333 | 1318 |
| 1334 result = valid_spdy_session_pool_->CreateAvailableSessionFromSocket( | 1319 spdy_session = |
| 1335 spdy_session_key, std::move(connection_), net_log_, | 1320 session_->spdy_session_pool()->CreateAvailableSessionFromSocket( |
| 1336 spdy_certificate_error_, using_ssl_, &spdy_session); | 1321 spdy_session_key, std::move(connection_), net_log_, |
| 1337 if (result != OK) { | 1322 spdy_certificate_error_, using_ssl_); |
| 1338 return result; | |
| 1339 } | |
| 1340 | 1323 |
| 1341 if (!spdy_session->HasAcceptableTransportSecurity()) { | 1324 if (!spdy_session->HasAcceptableTransportSecurity()) { |
| 1342 spdy_session->CloseSessionOnError( | 1325 spdy_session->CloseSessionOnError( |
| 1343 ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, ""); | 1326 ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, ""); |
| 1344 return ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY; | 1327 return ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY; |
| 1345 } | 1328 } |
| 1346 | 1329 |
| 1347 SSLInfo ssl_info; | 1330 SSLInfo ssl_info; |
| 1348 bool was_npn_negotiated; | 1331 bool was_npn_negotiated; |
| 1349 NextProto protocol_negotiated; | 1332 NextProto protocol_negotiated; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 session_->quic_stream_factory()->OnTcpJobCompleted(job_status_ == | 1633 session_->quic_stream_factory()->OnTcpJobCompleted(job_status_ == |
| 1651 STATUS_SUCCEEDED); | 1634 STATUS_SUCCEEDED); |
| 1652 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { | 1635 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { |
| 1653 HistogramBrokenAlternateProtocolLocation( | 1636 HistogramBrokenAlternateProtocolLocation( |
| 1654 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); | 1637 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); |
| 1655 session_->http_server_properties()->MarkAlternativeServiceBroken( | 1638 session_->http_server_properties()->MarkAlternativeServiceBroken( |
| 1656 other_job_alternative_service_); | 1639 other_job_alternative_service_); |
| 1657 } | 1640 } |
| 1658 } | 1641 } |
| 1659 | 1642 |
| 1660 HttpStreamFactoryImpl::Job::ValidSpdySessionPool::ValidSpdySessionPool( | |
| 1661 SpdySessionPool* spdy_session_pool, | |
| 1662 GURL& origin_url, | |
| 1663 bool is_spdy_alternative) | |
| 1664 : spdy_session_pool_(spdy_session_pool), | |
| 1665 origin_url_(origin_url), | |
| 1666 is_spdy_alternative_(is_spdy_alternative) { | |
| 1667 } | |
| 1668 | |
| 1669 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool::FindAvailableSession( | |
| 1670 const SpdySessionKey& key, | |
| 1671 const BoundNetLog& net_log, | |
| 1672 base::WeakPtr<SpdySession>* spdy_session) { | |
| 1673 *spdy_session = | |
| 1674 spdy_session_pool_->FindAvailableSession(key, origin_url_, net_log); | |
| 1675 return CheckAlternativeServiceValidityForOrigin(*spdy_session); | |
| 1676 } | |
| 1677 | |
| 1678 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool:: | |
| 1679 CreateAvailableSessionFromSocket( | |
| 1680 const SpdySessionKey& key, | |
| 1681 std::unique_ptr<ClientSocketHandle> connection, | |
| 1682 const BoundNetLog& net_log, | |
| 1683 int certificate_error_code, | |
| 1684 bool is_secure, | |
| 1685 base::WeakPtr<SpdySession>* spdy_session) { | |
| 1686 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), | |
| 1687 "HttpStreamFactoryImpl::Job::CreateAvailableSessionFromSocket"); | |
| 1688 *spdy_session = spdy_session_pool_->CreateAvailableSessionFromSocket( | |
| 1689 key, std::move(connection), net_log, certificate_error_code, is_secure); | |
| 1690 return CheckAlternativeServiceValidityForOrigin(*spdy_session); | |
| 1691 } | |
| 1692 | |
| 1693 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool:: | |
| 1694 CheckAlternativeServiceValidityForOrigin( | |
| 1695 base::WeakPtr<SpdySession> spdy_session) { | |
| 1696 // For an alternative Job, destination_.host() might be different than | |
| 1697 // origin_url_.host(), therefore it needs to be verified that the former | |
| 1698 // provides a certificate that is valid for the latter. | |
| 1699 if (!is_spdy_alternative_ || !spdy_session || | |
| 1700 spdy_session->VerifyDomainAuthentication(origin_url_.host())) { | |
| 1701 return OK; | |
| 1702 } | |
| 1703 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | |
| 1704 } | |
| 1705 | |
| 1706 ClientSocketPoolManager::SocketGroupType | 1643 ClientSocketPoolManager::SocketGroupType |
| 1707 HttpStreamFactoryImpl::Job::GetSocketGroup() const { | 1644 HttpStreamFactoryImpl::Job::GetSocketGroup() const { |
| 1708 std::string scheme = origin_url_.scheme(); | 1645 std::string scheme = origin_url_.scheme(); |
| 1709 if (scheme == "https" || scheme == "wss" || IsSpdyAlternative()) | 1646 if (scheme == "https" || scheme == "wss" || IsSpdyAlternative()) |
| 1710 return ClientSocketPoolManager::SSL_GROUP; | 1647 return ClientSocketPoolManager::SSL_GROUP; |
| 1711 | 1648 |
| 1712 if (scheme == "ftp") | 1649 if (scheme == "ftp") |
| 1713 return ClientSocketPoolManager::FTP_GROUP; | 1650 return ClientSocketPoolManager::FTP_GROUP; |
| 1714 | 1651 |
| 1715 return ClientSocketPoolManager::NORMAL_GROUP; | 1652 return ClientSocketPoolManager::NORMAL_GROUP; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1727 | 1664 |
| 1728 ConnectionAttempts socket_attempts = connection_->connection_attempts(); | 1665 ConnectionAttempts socket_attempts = connection_->connection_attempts(); |
| 1729 if (connection_->socket()) { | 1666 if (connection_->socket()) { |
| 1730 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1667 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1731 } | 1668 } |
| 1732 | 1669 |
| 1733 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); | 1670 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); |
| 1734 } | 1671 } |
| 1735 | 1672 |
| 1736 } // namespace net | 1673 } // namespace net |
| OLD | NEW |