summaryrefslogtreecommitdiffstats
path: root/net/http/http_server_properties_impl.cc
diff options
context:
space:
mode:
authorrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-09 02:01:54 +0000
committerrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-09 02:01:54 +0000
commitdb96a88617afc0e619c06234bd4f4670ccfe1ae3 (patch)
treed31503fd03c1726882c8ce9eb1fc3338cf966809 /net/http/http_server_properties_impl.cc
parentb7333cbad3132c305a3c0032d16b5655bef5fc8b (diff)
downloadchromium_src-db96a88617afc0e619c06234bd4f4670ccfe1ae3.zip
chromium_src-db96a88617afc0e619c06234bd4f4670ccfe1ae3.tar.gz
chromium_src-db96a88617afc0e619c06234bd4f4670ccfe1ae3.tar.bz2
Introduce net::HttpServerPropertiesManager to manage server-specific properties.
Currently the only property we manage is whether or not a server supports SPDY, as indicated by NPN. Also introduce a chrome/ implementation of HttpServerPropertiesManager that persists the information to Prefererences. When we get a SpdySession for a SPDY server, record that that server supports SPDY in HttpServerPropertiesManager. When preconnecting, if we know that the server supports SPDY, only preconnect 1 socket. R=willchan BUG=66472 TEST=browser ui and unit tests,network unit tests Review URL: http://codereview.chromium.org/7827033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104666 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_server_properties_impl.cc')
-rw-r--r--net/http/http_server_properties_impl.cc93
1 files changed, 93 insertions, 0 deletions
diff --git a/net/http/http_server_properties_impl.cc b/net/http/http_server_properties_impl.cc
new file mode 100644
index 0000000..9dd341d
--- /dev/null
+++ b/net/http/http_server_properties_impl.cc
@@ -0,0 +1,93 @@
+// 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/http/http_server_properties_impl.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/stl_util.h"
+#include "base/stringprintf.h"
+
+namespace net {
+
+HttpServerPropertiesImpl::HttpServerPropertiesImpl() {
+}
+
+HttpServerPropertiesImpl::~HttpServerPropertiesImpl() {
+}
+
+void HttpServerPropertiesImpl::Initialize(StringVector* spdy_servers,
+ bool support_spdy) {
+ DCHECK(CalledOnValidThread());
+ spdy_servers_table_.clear();
+ if (!spdy_servers)
+ return;
+ for (StringVector::iterator it = spdy_servers->begin();
+ it != spdy_servers->end(); ++it) {
+ spdy_servers_table_[*it] = support_spdy;
+ }
+}
+
+bool HttpServerPropertiesImpl::SupportsSpdy(
+ const net::HostPortPair& host_port_pair) const {
+ DCHECK(CalledOnValidThread());
+ if (host_port_pair.host().empty())
+ return false;
+ std::string spdy_server = GetFlattenedSpdyServer(host_port_pair);
+
+ SpdyServerHostPortTable::const_iterator spdy_host_port =
+ spdy_servers_table_.find(spdy_server);
+ if (spdy_host_port != spdy_servers_table_.end())
+ return spdy_host_port->second;
+ return false;
+}
+
+void HttpServerPropertiesImpl::SetSupportsSpdy(
+ const net::HostPortPair& host_port_pair,
+ bool support_spdy) {
+ DCHECK(CalledOnValidThread());
+ if (host_port_pair.host().empty())
+ return;
+ std::string spdy_server = GetFlattenedSpdyServer(host_port_pair);
+
+ SpdyServerHostPortTable::iterator spdy_host_port =
+ spdy_servers_table_.find(spdy_server);
+ if ((spdy_host_port != spdy_servers_table_.end()) &&
+ (spdy_host_port->second == support_spdy)) {
+ return;
+ }
+ // Cache the data.
+ spdy_servers_table_[spdy_server] = support_spdy;
+}
+
+void HttpServerPropertiesImpl::DeleteAll() {
+ DCHECK(CalledOnValidThread());
+ spdy_servers_table_.clear();
+}
+
+void HttpServerPropertiesImpl::GetSpdyServerList(
+ base::ListValue* spdy_server_list) const {
+ DCHECK(CalledOnValidThread());
+ DCHECK(spdy_server_list);
+ spdy_server_list->Clear();
+ // Get the list of servers (host/port) that support SPDY.
+ for (SpdyServerHostPortTable::const_iterator it = spdy_servers_table_.begin();
+ it != spdy_servers_table_.end(); ++it) {
+ const std::string spdy_server_host_port = it->first;
+ if (it->second)
+ spdy_server_list->Append(new StringValue(spdy_server_host_port));
+ }
+}
+
+// static
+std::string HttpServerPropertiesImpl::GetFlattenedSpdyServer(
+ const net::HostPortPair& host_port_pair) {
+ std::string spdy_server;
+ spdy_server.append(host_port_pair.host());
+ spdy_server.append(":");
+ base::StringAppendF(&spdy_server, "%d", host_port_pair.port());
+ return spdy_server;
+}
+
+} // namespace net