Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: net/http/http_server_properties_impl.cc

Issue 7827033: Introduce net::HttpServerPropertiesManager to manage server-specific properties. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/http/http_server_properties_impl.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/stl_util.h"
10 #include "base/stringprintf.h"
11
12 namespace net {
13
14 HttpServerPropertiesImpl::HttpServerPropertiesImpl() {
15 }
16
17 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() {
18 }
19
20 void HttpServerPropertiesImpl::Initialize(StringVector* spdy_servers,
21 bool support_spdy) {
22 DCHECK(CalledOnValidThread());
23 spdy_servers_table_.clear();
24 if (!spdy_servers)
25 return;
26 for (StringVector::iterator it = spdy_servers->begin();
27 it != spdy_servers->end(); ++it) {
28 spdy_servers_table_[*it] = support_spdy;
29 }
30 }
31
32 bool HttpServerPropertiesImpl::SupportsSpdy(
33 const net::HostPortPair& host_port_pair) const {
34 DCHECK(CalledOnValidThread());
35 if (host_port_pair.host().empty())
36 return false;
37 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair);
38
39 SpdyServerHostPortTable::const_iterator spdy_host_port =
40 spdy_servers_table_.find(spdy_server);
41 if (spdy_host_port != spdy_servers_table_.end())
42 return spdy_host_port->second;
43 return false;
44 }
45
46 void HttpServerPropertiesImpl::SetSupportsSpdy(
47 const net::HostPortPair& host_port_pair,
48 bool support_spdy) {
49 DCHECK(CalledOnValidThread());
50 if (host_port_pair.host().empty())
51 return;
52 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair);
53
54 SpdyServerHostPortTable::iterator spdy_host_port =
55 spdy_servers_table_.find(spdy_server);
56 if ((spdy_host_port != spdy_servers_table_.end()) &&
57 (spdy_host_port->second == support_spdy)) {
58 return;
59 }
60 // Cache the data.
61 spdy_servers_table_[spdy_server] = support_spdy;
62 }
63
64 void HttpServerPropertiesImpl::DeleteAll() {
65 DCHECK(CalledOnValidThread());
66 spdy_servers_table_.clear();
67 }
68
69 void HttpServerPropertiesImpl::GetSpdyServerList(
70 base::ListValue* spdy_server_list) const {
71 DCHECK(CalledOnValidThread());
72 DCHECK(spdy_server_list);
73 spdy_server_list->Clear();
74 // Get the list of servers (host/port) that support SPDY.
75 for (SpdyServerHostPortTable::const_iterator it = spdy_servers_table_.begin();
76 it != spdy_servers_table_.end(); ++it) {
77 const std::string spdy_server_host_port = it->first;
78 if (it->second)
79 spdy_server_list->Append(new StringValue(spdy_server_host_port));
80 }
81 }
82
83 // static
84 std::string HttpServerPropertiesImpl::GetFlattenedSpdyServer(
85 const net::HostPortPair& host_port_pair) {
86 std::string spdy_server;
87 spdy_server.append(host_port_pair.host());
88 spdy_server.append(":");
89 base::StringAppendF(&spdy_server, "%d", host_port_pair.port());
90 return spdy_server;
91 }
92
93 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698