diff options
author | bnc <bnc@chromium.org> | 2015-02-03 15:12:01 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-03 23:13:00 +0000 |
commit | 3c255331e787370ef99f38319ce2d812a89f5b82 (patch) | |
tree | 676f03fc59a464fc8419bdb2afc56a51f757ff58 /net | |
parent | 8b497e74ddd1a3be65c311419a57307119473a53 (diff) | |
download | chromium_src-3c255331e787370ef99f38319ce2d812a89f5b82.zip chromium_src-3c255331e787370ef99f38319ce2d812a89f5b82.tar.gz chromium_src-3c255331e787370ef99f38319ce2d812a89f5b82.tar.bz2 |
Remove HasAlternateProtocol().
If GetAlternateProtocol() is called but there is no alternate protocol, it
now returns one with UNINITIALIZED_ALTERNATE_PROTOCOL.
See https://crrev.com/665083009 for the context of this change and how draft
future changes might rely on this CL.
BUG=392575
Review URL: https://codereview.chromium.org/874603004
Cr-Commit-Position: refs/heads/master@{#314428}
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 18 | ||||
-rw-r--r-- | net/http/http_server_properties.h | 8 | ||||
-rw-r--r-- | net/http/http_server_properties_impl.cc | 36 | ||||
-rw-r--r-- | net/http/http_server_properties_impl.h | 1 | ||||
-rw-r--r-- | net/http/http_server_properties_impl_unittest.cc | 73 | ||||
-rw-r--r-- | net/http/http_server_properties_manager.cc | 6 | ||||
-rw-r--r-- | net/http/http_server_properties_manager.h | 1 | ||||
-rw-r--r-- | net/http/http_server_properties_manager_unittest.cc | 38 | ||||
-rw-r--r-- | net/http/http_stream_factory.cc | 8 | ||||
-rw-r--r-- | net/http/http_stream_factory_impl.cc | 13 | ||||
-rw-r--r-- | net/quic/quic_network_transaction_unittest.cc | 5 | ||||
-rw-r--r-- | net/quic/quic_stream_factory.cc | 6 |
12 files changed, 79 insertions, 134 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 1c70393..c3eab76 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -8508,8 +8508,9 @@ TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { HostPortPair http_host_port_pair("www.google.com", 80); HttpServerProperties& http_server_properties = *session->http_server_properties(); - EXPECT_FALSE( - http_server_properties.HasAlternateProtocol(http_host_port_pair)); + AlternateProtocolInfo alternate = + http_server_properties.GetAlternateProtocol(http_host_port_pair); + EXPECT_EQ(alternate.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); EXPECT_EQ(OK, callback.WaitForResult()); @@ -8524,12 +8525,10 @@ TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); EXPECT_EQ("hello world", response_data); - ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); - const AlternateProtocolInfo alternate = - http_server_properties.GetAlternateProtocol(http_host_port_pair); - AlternateProtocolInfo expected_alternate( - 443, AlternateProtocolFromNextProto(GetParam()), 1); - EXPECT_TRUE(expected_alternate.Equals(alternate)); + alternate = http_server_properties.GetAlternateProtocol(http_host_port_pair); + EXPECT_EQ(443, alternate.port); + EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), alternate.protocol); + EXPECT_EQ(1.0, alternate.probability); } TEST_P(HttpNetworkTransactionTest, @@ -8583,11 +8582,10 @@ TEST_P(HttpNetworkTransactionTest, ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); EXPECT_EQ("hello world", response_data); - ASSERT_TRUE(http_server_properties->HasAlternateProtocol( - HostPortPair::FromURL(request.url))); const AlternateProtocolInfo alternate = http_server_properties->GetAlternateProtocol( HostPortPair::FromURL(request.url)); + EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate.protocol); EXPECT_TRUE(alternate.is_broken); } diff --git a/net/http/http_server_properties.h b/net/http/http_server_properties.h index 840a359..a73b4eb 100644 --- a/net/http/http_server_properties.h +++ b/net/http/http_server_properties.h @@ -190,11 +190,9 @@ class NET_EXPORT HttpServerProperties { virtual void MaybeForceHTTP11(const HostPortPair& server, SSLConfig* ssl_config) = 0; - // Returns true if |server| has an Alternate-Protocol header. - virtual bool HasAlternateProtocol(const HostPortPair& server) = 0; - - // Returns the Alternate-Protocol and port for |server|. - // HasAlternateProtocol(server) must be true. + // Returns the AlternateProtocol for |server| if it has probability equal to + // or exceeding threshold, or else the forced AlternateProtocol if there is + // one, or else one with UNINITIALIZED_ALTERNATE_PROTOCOL. virtual AlternateProtocolInfo GetAlternateProtocol( const HostPortPair& server) = 0; diff --git a/net/http/http_server_properties_impl.cc b/net/http/http_server_properties_impl.cc index a53e73f..0b6b974 100644 --- a/net/http/http_server_properties_impl.cc +++ b/net/http/http_server_properties_impl.cc @@ -179,10 +179,7 @@ bool HttpServerPropertiesImpl::SupportsRequestPriority( if (spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second) return true; - if (!HasAlternateProtocol(host_port_pair)) - return false; - - AlternateProtocolInfo info = GetAlternateProtocol(host_port_pair); + const AlternateProtocolInfo info = GetAlternateProtocol(host_port_pair); return info.protocol == QUIC; } @@ -228,16 +225,6 @@ void HttpServerPropertiesImpl::MaybeForceHTTP11(const HostPortPair& server, } } -bool HttpServerPropertiesImpl::HasAlternateProtocol( - const HostPortPair& server) { - if (g_forced_alternate_protocol) - return true; - AlternateProtocolMap::const_iterator it = - GetAlternateProtocolIterator(server); - return it != alternate_protocol_map_.end() && - it->second.probability >= alternate_protocol_probability_threshold_; -} - std::string HttpServerPropertiesImpl::GetCanonicalSuffix( const std::string& host) { // If this host ends with a canonical suffix, then return the canonical @@ -251,19 +238,19 @@ std::string HttpServerPropertiesImpl::GetCanonicalSuffix( return std::string(); } -AlternateProtocolInfo -HttpServerPropertiesImpl::GetAlternateProtocol( +AlternateProtocolInfo HttpServerPropertiesImpl::GetAlternateProtocol( const HostPortPair& server) { - DCHECK(HasAlternateProtocol(server)); - AlternateProtocolMap::const_iterator it = GetAlternateProtocolIterator(server); - if (it != alternate_protocol_map_.end()) + if (it != alternate_protocol_map_.end() && + it->second.probability >= alternate_protocol_probability_threshold_) return it->second; - // We must be forcing an alternate. - DCHECK(g_forced_alternate_protocol); - return *g_forced_alternate_protocol; + if (g_forced_alternate_protocol) + return *g_forced_alternate_protocol; + + AlternateProtocolInfo uninitialized_alternate_protocol; + return uninitialized_alternate_protocol; } void HttpServerPropertiesImpl::SetAlternateProtocol( @@ -322,15 +309,16 @@ void HttpServerPropertiesImpl::SetAlternateProtocol( void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( const HostPortPair& server) { AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); + const AlternateProtocolInfo alternate = GetAlternateProtocol(server); if (it == alternate_protocol_map_.end()) { - if (!HasAlternateProtocol(server)) { + if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; return; } // This server's alternate protocol information is coming from a canonical // server. Add an entry in the map for this server explicitly so that // it can be marked as broken. - it = alternate_protocol_map_.Put(server, GetAlternateProtocol(server)); + it = alternate_protocol_map_.Put(server, alternate); } it->second.is_broken = true; int count = ++broken_alternate_protocol_map_[server]; diff --git a/net/http/http_server_properties_impl.h b/net/http/http_server_properties_impl.h index 8d251a2..9c2a73c 100644 --- a/net/http/http_server_properties_impl.h +++ b/net/http/http_server_properties_impl.h @@ -79,7 +79,6 @@ class NET_EXPORT HttpServerPropertiesImpl void SetHTTP11Required(const HostPortPair& server) override; void MaybeForceHTTP11(const HostPortPair& server, SSLConfig* ssl_config) override; - bool HasAlternateProtocol(const HostPortPair& server) override; AlternateProtocolInfo GetAlternateProtocol( const HostPortPair& server) override; void SetAlternateProtocol(const HostPortPair& server, diff --git a/net/http/http_server_properties_impl_unittest.cc b/net/http/http_server_properties_impl_unittest.cc index be5e6b9..e4d7047 100644 --- a/net/http/http_server_properties_impl_unittest.cc +++ b/net/http/http_server_properties_impl_unittest.cc @@ -27,6 +27,11 @@ namespace { class HttpServerPropertiesImplTest : public testing::Test { protected: + bool HasAlternateProtocol(const HostPortPair& server) { + const AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(server); + return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; + } + HttpServerPropertiesImpl impl_; }; @@ -219,23 +224,23 @@ typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; TEST_F(AlternateProtocolServerPropertiesTest, Basic) { HostPortPair test_host_port_pair("foo", 80); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); + ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); const AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(test_host_port_pair); EXPECT_EQ(443, alternate.port); EXPECT_EQ(NPN_SPDY_3, alternate.protocol); impl_.Clear(); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); } TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { HostPortPair test_host_port_pair("foo", 80); impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .99); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); } TEST_F(AlternateProtocolServerPropertiesTest, Probability) { @@ -244,7 +249,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, Probability) { HostPortPair test_host_port_pair("foo", 80); impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); + ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); const AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(test_host_port_pair); EXPECT_EQ(443, alternate.port); @@ -258,7 +263,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { HostPortPair test_host_port_pair("foo", 80); impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); } TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { @@ -284,8 +289,8 @@ TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { EXPECT_EQ(1234, it->second.port); EXPECT_EQ(NPN_SPDY_3, it->second.protocol); - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); + ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair1)); + ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair2)); alternate = impl_.GetAlternateProtocol(test_host_port_pair1); EXPECT_TRUE(alternate.is_broken); alternate = impl_.GetAlternateProtocol(test_host_port_pair2); @@ -293,26 +298,6 @@ TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { EXPECT_EQ(NPN_SPDY_3, alternate.protocol); } -TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) { - HostPortPair test_host_port_pair1("foo1", 80); - impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); - HostPortPair test_host_port_pair2("foo2", 80); - impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); - - const AlternateProtocolMap& map = impl_.alternate_protocol_map(); - AlternateProtocolMap::const_iterator it = map.begin(); - EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); - EXPECT_EQ(1234, it->second.port); - EXPECT_EQ(NPN_SPDY_3, it->second.protocol); - - // HasAlternateProtocol should reorder the AlternateProtocol map. - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); - it = map.begin(); - EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); - EXPECT_EQ(443, it->second.port); - EXPECT_EQ(NPN_SPDY_3, it->second.protocol); -} - TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { HostPortPair test_host_port_pair1("foo1", 80); impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); @@ -340,7 +325,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { HostPortPair test_host_port_pair("foo", 80); impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); impl_.SetBrokenAlternateProtocol(test_host_port_pair); - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); + ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(test_host_port_pair); EXPECT_TRUE(alternate.is_broken); @@ -354,12 +339,12 @@ TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { HostPortPair test_host_port_pair("foo", 80); impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); impl_.SetBrokenAlternateProtocol(test_host_port_pair); - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); + ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(test_host_port_pair); EXPECT_TRUE(alternate.is_broken); impl_.ClearAlternateProtocol(test_host_port_pair); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); } TEST_F(AlternateProtocolServerPropertiesTest, Forced) { @@ -370,7 +355,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, Forced) { // Verify the forced protocol. HostPortPair test_host_port_pair("foo", 80); - EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(test_host_port_pair); EXPECT_EQ(default_protocol.port, alternate.port); @@ -378,7 +363,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, Forced) { // Verify the real protocol overrides the forced protocol. impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); + ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); alternate = impl_.GetAlternateProtocol(test_host_port_pair); EXPECT_EQ(443, alternate.port); EXPECT_EQ(NPN_SPDY_3, alternate.protocol); @@ -389,22 +374,22 @@ TEST_F(AlternateProtocolServerPropertiesTest, Forced) { // Verify the forced protocol is off. HostPortPair test_host_port_pair2("bar", 80); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair2)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair2)); } TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { HostPortPair test_host_port_pair("foo.c.youtube.com", 80); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); HostPortPair canonical_port_pair("bar.c.youtube.com", 80); - EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, canonical_protocol.protocol, 1.0); // Verify the forced protocol. - ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); + ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(test_host_port_pair); EXPECT_EQ(canonical_protocol.port, alternate.port); @@ -427,8 +412,8 @@ TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, canonical_protocol.protocol, canonical_protocol.probability); - EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair)); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); } TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { @@ -441,8 +426,8 @@ TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, canonical_protocol.protocol, canonical_protocol.probability); - EXPECT_TRUE(impl_.HasAlternateProtocol(canonical_port_pair)); - EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_TRUE(HasAlternateProtocol(canonical_port_pair)); + EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); } TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { @@ -456,7 +441,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { canonical_protocol.probability); impl_.ClearAlternateProtocol(canonical_port_pair); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); } TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { @@ -470,7 +455,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { canonical_protocol.probability); impl_.SetBrokenAlternateProtocol(canonical_port_pair); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); } TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) { @@ -500,7 +485,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { canonical_protocol.probability); impl_.Clear(); - EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); + EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); } typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; diff --git a/net/http/http_server_properties_manager.cc b/net/http/http_server_properties_manager.cc index c2f6f56..c6783d3 100644 --- a/net/http/http_server_properties_manager.cc +++ b/net/http/http_server_properties_manager.cc @@ -180,12 +180,6 @@ void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); } -bool HttpServerPropertiesManager::HasAlternateProtocol( - const HostPortPair& server) { - DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); - return http_server_properties_impl_->HasAlternateProtocol(server); -} - AlternateProtocolInfo HttpServerPropertiesManager::GetAlternateProtocol( const HostPortPair& server) { DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); diff --git a/net/http/http_server_properties_manager.h b/net/http/http_server_properties_manager.h index 56679cb..21d817a 100644 --- a/net/http/http_server_properties_manager.h +++ b/net/http/http_server_properties_manager.h @@ -86,7 +86,6 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties { void SetHTTP11Required(const HostPortPair& server) override; void MaybeForceHTTP11(const HostPortPair& server, SSLConfig* ssl_config) override; - bool HasAlternateProtocol(const HostPortPair& server) override; AlternateProtocolInfo GetAlternateProtocol( const HostPortPair& server) override; void SetAlternateProtocol(const HostPortPair& server, diff --git a/net/http/http_server_properties_manager_unittest.cc b/net/http/http_server_properties_manager_unittest.cc index d021fc5..cbc2275 100644 --- a/net/http/http_server_properties_manager_unittest.cc +++ b/net/http/http_server_properties_manager_unittest.cc @@ -134,6 +134,12 @@ class HttpServerPropertiesManagerTest : public testing::Test { UpdatePrefsFromCacheOnNetworkThreadConcrete)); } + bool HasAlternateProtocol(const HostPortPair& server) { + const AlternateProtocolInfo alternate = + http_server_props_manager_->GetAlternateProtocol(server); + return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; + } + //base::RunLoop loop_; TestingPrefServiceSimple pref_service_; scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; @@ -230,8 +236,6 @@ TEST_F(HttpServerPropertiesManagerTest, HostPortPair::FromString("foo.google.com:1337"))); // Verify AlternateProtocol. - ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); - ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); AlternateProtocolInfo port_alternate_protocol = http_server_props_manager_->GetAlternateProtocol(google_server); EXPECT_EQ(443, port_alternate_protocol.port); @@ -307,8 +311,8 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { // Verify that nothing is set. EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( HostPortPair::FromString("www.google.com:65536"))); - EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( - HostPortPair::FromString("www.google.com:65536"))); + EXPECT_FALSE( + HasAlternateProtocol(HostPortPair::FromString("www.google.com:65536"))); SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( HostPortPair::FromString("www.google.com:65536")); EXPECT_FALSE(supports_quic2.used_quic); @@ -352,8 +356,8 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); // Verify AlternateProtocol is not set. - EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( - HostPortPair::FromString("www.google.com:80"))); + EXPECT_FALSE( + HasAlternateProtocol(HostPortPair::FromString("www.google.com:80"))); } TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { @@ -477,12 +481,11 @@ TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); } -TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { +TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) { ExpectPrefsUpdate(); HostPortPair spdy_server_mail("mail.google.com", 80); - EXPECT_FALSE( - http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); + EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, NPN_SPDY_3, 1.0); @@ -490,12 +493,11 @@ TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { base::RunLoop().RunUntilIdle(); Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); - ASSERT_TRUE( - http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); - AlternateProtocolInfo port_alternate_protocol = + const AlternateProtocolInfo alternate_protocol = http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); - EXPECT_EQ(443, port_alternate_protocol.port); - EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); + EXPECT_EQ(443, alternate_protocol.port); + EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol); + EXPECT_EQ(1.0, alternate_protocol.probability); } TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { @@ -561,8 +563,7 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) { EXPECT_TRUE( http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); - EXPECT_TRUE( - http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); + EXPECT_TRUE(HasAlternateProtocol(spdy_server_mail)); SupportsQuic supports_quic = http_server_props_manager_->GetSupportsQuic(spdy_server_mail); EXPECT_TRUE(supports_quic.used_quic); @@ -591,8 +592,7 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) { EXPECT_FALSE( http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); - EXPECT_FALSE( - http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); + EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic(spdy_server_mail); EXPECT_FALSE(supports_quic1.used_quic); @@ -654,8 +654,6 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { // Verify AlternateProtocol. for (int i = 0; i < 200; ++i) { std::string server = StringPrintf("www.google.com:%d", i); - ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( - HostPortPair::FromString(server))); AlternateProtocolInfo port_alternate_protocol = http_server_props_manager_->GetAlternateProtocol( HostPortPair::FromString(server)); diff --git a/net/http/http_stream_factory.cc b/net/http/http_stream_factory.cc index f84b80c..754372b 100644 --- a/net/http/http_stream_factory.cc +++ b/net/http/http_stream_factory.cc @@ -86,14 +86,6 @@ void HttpStreamFactory::ProcessAlternateProtocol( if (mapping_rules) mapping_rules->RewriteHost(&host_port); - if (http_server_properties->HasAlternateProtocol(host_port)) { - const AlternateProtocolInfo existing_alternate = - http_server_properties->GetAlternateProtocol(host_port); - // If we think the alternate protocol is broken, don't change it. - if (existing_alternate.is_broken) - return; - } - http_server_properties->SetAlternateProtocol( host_port, static_cast<uint16>(port), protocol, probability); } diff --git a/net/http/http_stream_factory_impl.cc b/net/http/http_stream_factory_impl.cc index 9e932ee..78238b9 100644 --- a/net/http/http_stream_factory_impl.cc +++ b/net/http/http_stream_factory_impl.cc @@ -175,8 +175,7 @@ const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { AlternateProtocolInfo HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( const GURL& original_url, GURL* alternate_url) { - const AlternateProtocolInfo kNoAlternateProtocol = - AlternateProtocolInfo(0, UNINITIALIZED_ALTERNATE_PROTOCOL, 0); + const AlternateProtocolInfo kNoAlternateProtocol; if (!session_->params().use_alternate_protocols) return kNoAlternateProtocol; @@ -185,19 +184,17 @@ AlternateProtocolInfo HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( return kNoAlternateProtocol; HostPortPair origin = HostPortPair::FromURL(original_url); - HttpServerProperties& http_server_properties = *session_->http_server_properties(); - if (!http_server_properties.HasAlternateProtocol(origin)) - return kNoAlternateProtocol; - - AlternateProtocolInfo alternate = + const AlternateProtocolInfo alternate = http_server_properties.GetAlternateProtocol(origin); + + if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) + return kNoAlternateProtocol; if (alternate.is_broken) { HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); return kNoAlternateProtocol; } - if (!IsAlternateProtocolValid(alternate.protocol)) { NOTREACHED(); return kNoAlternateProtocol; diff --git a/net/quic/quic_network_transaction_unittest.cc b/net/quic/quic_network_transaction_unittest.cc index 5219d1e..203aa3e 100644 --- a/net/quic/quic_network_transaction_unittest.cc +++ b/net/quic/quic_network_transaction_unittest.cc @@ -284,17 +284,14 @@ class QuicNetworkTransactionTest } void ExpectBrokenAlternateProtocolMapping() { - ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( - HostPortPair::FromURL(request_.url))); const AlternateProtocolInfo alternate = session_->http_server_properties()->GetAlternateProtocol( HostPortPair::FromURL(request_.url)); + EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate.protocol); EXPECT_TRUE(alternate.is_broken); } void ExpectQuicAlternateProtocolMapping() { - ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( - HostPortPair::FromURL(request_.url))); const AlternateProtocolInfo alternate = session_->http_server_properties()->GetAlternateProtocol( HostPortPair::FromURL(request_.url)); diff --git a/net/quic/quic_stream_factory.cc b/net/quic/quic_stream_factory.cc index f957c18..f38ae01 100644 --- a/net/quic/quic_stream_factory.cc +++ b/net/quic/quic_stream_factory.cc @@ -1249,7 +1249,9 @@ void QuicStreamFactory::ProcessGoingAwaySession( const HostPortPair& server = server_id.host_port_pair(); // Don't try to change the alternate-protocol state, if the // alternate-protocol state is unknown. - if (!http_server_properties_->HasAlternateProtocol(server)) + const AlternateProtocolInfo alternate = + http_server_properties_->GetAlternateProtocol(server); + if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) return; // TODO(rch): In the special case where the session has received no @@ -1258,8 +1260,6 @@ void QuicStreamFactory::ProcessGoingAwaySession( // session connected until the handshake has been confirmed. HistogramBrokenAlternateProtocolLocation( BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); - AlternateProtocolInfo alternate = - http_server_properties_->GetAlternateProtocol(server); DCHECK_EQ(QUIC, alternate.protocol); // Since the session was active, there's no longer an |