summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-12 07:05:18 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-12 07:05:18 +0000
commitde95f929772cb7214efb747f9a5a115b27561336 (patch)
tree3f376123413c93b064eb65baf2643a407f6dfc7e /net
parent817925aaf716cb623c56e21030650f075e510157 (diff)
downloadchromium_src-de95f929772cb7214efb747f9a5a115b27561336.zip
chromium_src-de95f929772cb7214efb747f9a5a115b27561336.tar.gz
chromium_src-de95f929772cb7214efb747f9a5a115b27561336.tar.bz2
Persist Alternate-Protocol.
Record Alternate-Protocol servers in spdy.alternate_protocol. Don't persist broken Alternate-Protocol so they will retry on next browser session. Also fix listening to notifications when we're the ones setting them. This was leading to unnecessary double updates, where we'd update the cache on the IO thread, and then propagate to the UI thread, where we'd set the prefs, and then observe that change and propagate back to the IO thread to update the cache. BUG=98472 TEST=Observe that spdy.alternate_protocol is empty in your Preferences file. Confirm that there is no alternate-protocol mapping in chrome://net-internals/#spdy. Browse to www.strangeloopnetworks.com. Check chrome://net-internals/#spdy again and notice that it populates with the mapping. Wait some seconds and then check the Preferences file again and note that it got persisted to disk. Restart Chrome and check chrome://net-internals/#spdy and note that the same alternate-protocol mappings reappear. Review URL: http://codereview.chromium.org/8221030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105028 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/host_port_pair.cc19
-rw-r--r--net/base/host_port_pair.h4
-rw-r--r--net/base/host_port_pair_unittest.cc23
-rw-r--r--net/http/http_server_properties.h4
-rw-r--r--net/http/http_server_properties_impl.cc15
-rw-r--r--net/http/http_server_properties_impl.h5
-rw-r--r--net/http/http_server_properties_impl_unittest.cc38
-rw-r--r--net/net.gyp1
8 files changed, 99 insertions, 10 deletions
diff --git a/net/base/host_port_pair.cc b/net/base/host_port_pair.cc
index 5164fcf..773c7ee 100644
--- a/net/base/host_port_pair.cc
+++ b/net/base/host_port_pair.cc
@@ -1,9 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/base/host_port_pair.h"
+#include "base/string_number_conversions.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "googleurl/src/gurl.h"
@@ -27,6 +29,21 @@ HostPortPair HostPortPair::FromAddrInfo(const struct addrinfo* ai) {
GetPortFromSockaddr(ai->ai_addr, ai->ai_addrlen));
}
+HostPortPair HostPortPair::FromString(const std::string& str) {
+ std::vector<std::string> key_port;
+ base::SplitString(str, ':', &key_port);
+ if (key_port.size() != 2)
+ return HostPortPair();
+ int port;
+ if (!base::StringToInt(key_port[1], &port))
+ return HostPortPair();
+ DCHECK_LT(port, 1 << 16);
+ HostPortPair host_port_pair;
+ host_port_pair.set_host(key_port[0]);
+ host_port_pair.set_port(port);
+ return host_port_pair;
+}
+
std::string HostPortPair::ToString() const {
return base::StringPrintf("%s:%u", HostForURL().c_str(), port_);
}
diff --git a/net/base/host_port_pair.h b/net/base/host_port_pair.h
index 7f009a9..ea95356 100644
--- a/net/base/host_port_pair.h
+++ b/net/base/host_port_pair.h
@@ -27,6 +27,10 @@ class NET_EXPORT HostPortPair {
// Creates a HostPortPair from an addrinfo struct.
static HostPortPair FromAddrInfo(const struct addrinfo* ai);
+ // Creates a HostPortPair from a string formatted in same manner as
+ // ToString().
+ static HostPortPair FromString(const std::string& str);
+
// TODO(willchan): Define a functor instead.
// Comparator function so this can be placed in a std::map.
bool operator<(const HostPortPair& other) const {
diff --git a/net/base/host_port_pair_unittest.cc b/net/base/host_port_pair_unittest.cc
new file mode 100644
index 0000000..de059904
--- /dev/null
+++ b/net/base/host_port_pair_unittest.cc
@@ -0,0 +1,23 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/host_port_pair.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+namespace {
+
+TEST(HostPortPairTest, Parsing) {
+ HostPortPair foo("foo.com", 10);
+ std::string foo_str = foo.ToString();
+ EXPECT_EQ("foo.com:10", foo_str);
+ HostPortPair bar = HostPortPair::FromString(foo_str);
+ EXPECT_TRUE(foo.Equals(bar));
+}
+
+} // namespace
+
+} // namespace net
diff --git a/net/http/http_server_properties.h b/net/http/http_server_properties.h
index a026458..06166f7 100644
--- a/net/http/http_server_properties.h
+++ b/net/http/http_server_properties.h
@@ -14,7 +14,7 @@
namespace net {
enum AlternateProtocol {
- NPN_SPDY_1,
+ NPN_SPDY_1 = 0,
NPN_SPDY_2,
NUM_ALTERNATE_PROTOCOLS,
ALTERNATE_PROTOCOL_BROKEN, // The alternate protocol is known to be broken.
@@ -47,7 +47,7 @@ class NET_EXPORT HttpServerProperties {
virtual ~HttpServerProperties() {}
// Deletes all data.
- virtual void DeleteAll() = 0;
+ virtual void Clear() = 0;
// Returns true if |server| supports SPDY.
virtual bool SupportsSpdy(const HostPortPair& server) const = 0;
diff --git a/net/http/http_server_properties_impl.cc b/net/http/http_server_properties_impl.cc
index 1226c9c..3ea973c 100644
--- a/net/http/http_server_properties_impl.cc
+++ b/net/http/http_server_properties_impl.cc
@@ -30,6 +30,19 @@ void HttpServerPropertiesImpl::InitializeSpdyServers(
}
}
+void HttpServerPropertiesImpl::InitializeAlternateProtocolServers(
+ AlternateProtocolMap* alternate_protocol_map) {
+ // First swap, and then add back all the ALTERNATE_PROTOCOL_BROKEN ones since
+ // those don't get persisted.
+ alternate_protocol_map_.swap(*alternate_protocol_map);
+ for (AlternateProtocolMap::const_iterator it =
+ alternate_protocol_map->begin();
+ it != alternate_protocol_map->end(); ++it) {
+ if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN)
+ alternate_protocol_map_[it->first] = it->second;
+ }
+}
+
void HttpServerPropertiesImpl::GetSpdyServerList(
base::ListValue* spdy_server_list) const {
DCHECK(CalledOnValidThread());
@@ -71,7 +84,7 @@ void HttpServerPropertiesImpl::DisableForcedAlternateProtocol() {
g_forced_alternate_protocol = NULL;
}
-void HttpServerPropertiesImpl::DeleteAll() {
+void HttpServerPropertiesImpl::Clear() {
DCHECK(CalledOnValidThread());
spdy_servers_table_.clear();
alternate_protocol_map_.clear();
diff --git a/net/http/http_server_properties_impl.h b/net/http/http_server_properties_impl.h
index 0bdf1f6..177802f 100644
--- a/net/http/http_server_properties_impl.h
+++ b/net/http/http_server_properties_impl.h
@@ -36,6 +36,9 @@ class NET_EXPORT HttpServerPropertiesImpl
void InitializeSpdyServers(std::vector<std::string>* spdy_servers,
bool support_spdy);
+ void InitializeAlternateProtocolServers(
+ AlternateProtocolMap* alternate_protocol_servers);
+
// Get the list of servers (host/port) that support SPDY.
void GetSpdyServerList(base::ListValue* spdy_server_list) const;
@@ -55,7 +58,7 @@ class NET_EXPORT HttpServerPropertiesImpl
// -----------------------------
// Deletes all data.
- virtual void DeleteAll() OVERRIDE;
+ virtual void Clear() OVERRIDE;
// Returns true if |server| supports SPDY.
virtual bool SupportsSpdy(const HostPortPair& server) const OVERRIDE;
diff --git a/net/http/http_server_properties_impl_unittest.cc b/net/http/http_server_properties_impl_unittest.cc
index 3539ef6..ac5d5fc 100644
--- a/net/http/http_server_properties_impl_unittest.cc
+++ b/net/http/http_server_properties_impl_unittest.cc
@@ -30,7 +30,7 @@ class HttpServerPropertiesImplTest : public testing::Test {
typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest;
-TEST_F(SpdyServerPropertiesTest, InitializeTest) {
+TEST_F(SpdyServerPropertiesTest, Initialize) {
HostPortPair spdy_server_google("www.google.com", 443);
std::string spdy_server_g =
HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google);
@@ -88,7 +88,7 @@ TEST_F(SpdyServerPropertiesTest, SupportsSpdyTest) {
EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs));
}
-TEST_F(SpdyServerPropertiesTest, SetSupportsSpdyTest) {
+TEST_F(SpdyServerPropertiesTest, SetSupportsSpdy) {
HostPortPair spdy_server_empty("", 443);
impl_.SetSupportsSpdy(spdy_server_empty, true);
EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty));
@@ -111,7 +111,7 @@ TEST_F(SpdyServerPropertiesTest, SetSupportsSpdyTest) {
EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
}
-TEST_F(SpdyServerPropertiesTest, DeleteAllTest) {
+TEST_F(SpdyServerPropertiesTest, Clear) {
// Add www.google.com:443 and mail.google.com:443 as supporting SPDY.
HostPortPair spdy_server_google("www.google.com", 443);
impl_.SetSupportsSpdy(spdy_server_google, true);
@@ -121,12 +121,12 @@ TEST_F(SpdyServerPropertiesTest, DeleteAllTest) {
EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google));
EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail));
- impl_.DeleteAll();
+ impl_.Clear();
EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
}
-TEST_F(SpdyServerPropertiesTest, GetSpdyServerListTest) {
+TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) {
base::ListValue spdy_server_list;
// Check there are no spdy_servers.
@@ -197,6 +197,34 @@ TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
impl_.GetAlternateProtocol(test_host_port_pair);
EXPECT_EQ(443, alternate.port);
EXPECT_EQ(NPN_SPDY_1, alternate.protocol);
+
+ impl_.Clear();
+ EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
+}
+
+TEST_F(AlternateProtocolServerPropertiesTest, Initialize) {
+ HostPortPair test_host_port_pair1("foo1", 80);
+ impl_.SetBrokenAlternateProtocol(test_host_port_pair1);
+ HostPortPair test_host_port_pair2("foo2", 80);
+ impl_.SetAlternateProtocol(
+ test_host_port_pair2, 443, NPN_SPDY_1);
+
+ AlternateProtocolMap alternate_protocol_map;
+ PortAlternateProtocolPair port_alternate_protocol_pair;
+ port_alternate_protocol_pair.port = 123;
+ port_alternate_protocol_pair.protocol = NPN_SPDY_2;
+ alternate_protocol_map[test_host_port_pair2] = port_alternate_protocol_pair;
+ impl_.InitializeAlternateProtocolServers(&alternate_protocol_map);
+
+ ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
+ ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2));
+ port_alternate_protocol_pair =
+ impl_.GetAlternateProtocol(test_host_port_pair1);
+ EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, port_alternate_protocol_pair.protocol);
+ port_alternate_protocol_pair =
+ impl_.GetAlternateProtocol(test_host_port_pair2);
+ EXPECT_EQ(123, port_alternate_protocol_pair.port);
+ EXPECT_EQ(NPN_SPDY_2, port_alternate_protocol_pair.protocol);
}
TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) {
diff --git a/net/net.gyp b/net/net.gyp
index 9021035..6bc9340 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -942,6 +942,7 @@
'base/gzip_filter_unittest.cc',
'base/host_cache_unittest.cc',
'base/host_mapping_rules_unittest.cc',
+ 'base/host_port_pair_unittest.cc',
'base/host_resolver_impl_unittest.cc',
'base/ip_endpoint_unittest.cc',
'base/keygen_handler_unittest.cc',