Index: net/http/http_server_properties.cc |
=================================================================== |
--- net/http/http_server_properties.cc (revision 0) |
+++ net/http/http_server_properties.cc (revision 0) |
@@ -0,0 +1,77 @@ |
+// 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.h" |
+ |
+#include "base/stl_util.h" |
+#include "base/stringprintf.h" |
+ |
+namespace net { |
+ |
+HttpServerProperties::HttpServerProperties() { |
+} |
+ |
+HttpServerProperties::~HttpServerProperties() { |
+} |
+ |
+void HttpServerProperties::Initialize(StringVector* spdy_servers, |
+ bool support_spdy) { |
+ spdy_servers_table_.clear(); |
+ scoped_ptr<StringVector> scoped_spdy_servers(spdy_servers); |
+ for (StringVector::iterator it = spdy_servers->begin(); |
+ it != spdy_servers->end(); ++it) { |
+ spdy_servers_table_[*it] = support_spdy; |
+ } |
+} |
+ |
+bool HttpServerProperties::SupportsSpdy( |
+ const net::HostPortPair& host_port_pair) { |
+ if (host_port_pair.host().empty()) |
+ return false; |
+ std::string spdy_server; |
+ GetFlattenedSpdyServer(host_port_pair, spdy_server); |
+ |
+ 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 HttpServerProperties::SetSupportsSpdy( |
+ const net::HostPortPair& host_port_pair, |
+ bool support_spdy) { |
+ std::string spdy_server; |
+ GetFlattenedSpdyServer(host_port_pair, spdy_server); |
+ |
+ 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 HttpServerProperties::GetSpdyServerList( |
+ base::ListValue* spdy_server_list) { |
+ // Get the list of servers (host/port) that support SPDY. |
+ for (SpdyServerHostPortTable::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)); |
+ } |
+} |
+ |
+void HttpServerProperties::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()); |
+} |
+ |
+} // namespace net |