OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "net/http/http_pipelined_host_capability.h" | |
11 | 12 |
12 namespace net { | 13 namespace net { |
13 | 14 |
14 HttpServerPropertiesImpl::HttpServerPropertiesImpl() { | 15 // TODO(simonjam): Run experiments with different values of this to see what |
16 // value is good at avoiding evictions without eating too much memory. Until | |
17 // then, this is just a bad guess. | |
18 static const int kNumHostsToRemember = 200; | |
mmenke
2011/12/06 15:50:38
nit: This should now be kDefaultNumHostsToRemembe
James Simonsen
2011/12/06 19:57:49
Done.
| |
19 | |
20 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | |
21 : pipeline_capability_map_(kNumHostsToRemember) { | |
15 } | 22 } |
16 | 23 |
17 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 24 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
18 } | 25 } |
19 | 26 |
20 void HttpServerPropertiesImpl::InitializeSpdyServers( | 27 void HttpServerPropertiesImpl::InitializeSpdyServers( |
21 std::vector<std::string>* spdy_servers, | 28 std::vector<std::string>* spdy_servers, |
22 bool support_spdy) { | 29 bool support_spdy) { |
23 DCHECK(CalledOnValidThread()); | 30 DCHECK(CalledOnValidThread()); |
24 spdy_servers_table_.clear(); | 31 spdy_servers_table_.clear(); |
(...skipping 16 matching lines...) Expand all Loading... | |
41 if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN) | 48 if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN) |
42 alternate_protocol_map_[it->first] = it->second; | 49 alternate_protocol_map_[it->first] = it->second; |
43 } | 50 } |
44 } | 51 } |
45 | 52 |
46 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 53 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
47 std::map<HostPortPair, spdy::SpdySettings>* spdy_settings_map) { | 54 std::map<HostPortPair, spdy::SpdySettings>* spdy_settings_map) { |
48 spdy_settings_map_.swap(*spdy_settings_map); | 55 spdy_settings_map_.swap(*spdy_settings_map); |
49 } | 56 } |
50 | 57 |
58 void HttpServerPropertiesImpl::InitializePipelineCapabilities( | |
59 const PipelineCapabilityMap* pipeline_capability_map) { | |
60 PipelineCapabilityMap::const_iterator it; | |
61 pipeline_capability_map_.Clear(); | |
62 for (it = pipeline_capability_map->begin(); | |
63 it != pipeline_capability_map->end(); ++it) { | |
64 pipeline_capability_map_.Put(it->first, it->second); | |
65 } | |
66 } | |
67 | |
68 void HttpServerPropertiesImpl::SetNumPipelinedHostsToRemember(int max_size) { | |
mmenke
2011/12/06 15:50:38
Just to make things simple, you could just require
James Simonsen
2011/12/06 19:57:49
Ok. Done.
| |
69 pipeline_capability_map_.SetMaxSize(max_size); | |
70 } | |
71 | |
51 void HttpServerPropertiesImpl::GetSpdyServerList( | 72 void HttpServerPropertiesImpl::GetSpdyServerList( |
52 base::ListValue* spdy_server_list) const { | 73 base::ListValue* spdy_server_list) const { |
53 DCHECK(CalledOnValidThread()); | 74 DCHECK(CalledOnValidThread()); |
54 DCHECK(spdy_server_list); | 75 DCHECK(spdy_server_list); |
55 spdy_server_list->Clear(); | 76 spdy_server_list->Clear(); |
56 // Get the list of servers (host/port) that support SPDY. | 77 // Get the list of servers (host/port) that support SPDY. |
57 for (SpdyServerHostPortTable::const_iterator it = spdy_servers_table_.begin(); | 78 for (SpdyServerHostPortTable::const_iterator it = spdy_servers_table_.begin(); |
58 it != spdy_servers_table_.end(); ++it) { | 79 it != spdy_servers_table_.end(); ++it) { |
59 const std::string spdy_server_host_port = it->first; | 80 const std::string spdy_server_host_port = it->first; |
60 if (it->second) | 81 if (it->second) |
(...skipping 26 matching lines...) Expand all Loading... | |
87 void HttpServerPropertiesImpl::DisableForcedAlternateProtocol() { | 108 void HttpServerPropertiesImpl::DisableForcedAlternateProtocol() { |
88 delete g_forced_alternate_protocol; | 109 delete g_forced_alternate_protocol; |
89 g_forced_alternate_protocol = NULL; | 110 g_forced_alternate_protocol = NULL; |
90 } | 111 } |
91 | 112 |
92 void HttpServerPropertiesImpl::Clear() { | 113 void HttpServerPropertiesImpl::Clear() { |
93 DCHECK(CalledOnValidThread()); | 114 DCHECK(CalledOnValidThread()); |
94 spdy_servers_table_.clear(); | 115 spdy_servers_table_.clear(); |
95 alternate_protocol_map_.clear(); | 116 alternate_protocol_map_.clear(); |
96 spdy_settings_map_.clear(); | 117 spdy_settings_map_.clear(); |
118 pipeline_capability_map_.Clear(); | |
97 } | 119 } |
98 | 120 |
99 bool HttpServerPropertiesImpl::SupportsSpdy( | 121 bool HttpServerPropertiesImpl::SupportsSpdy( |
100 const net::HostPortPair& host_port_pair) const { | 122 const net::HostPortPair& host_port_pair) const { |
101 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
102 if (host_port_pair.host().empty()) | 124 if (host_port_pair.host().empty()) |
103 return false; | 125 return false; |
104 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); | 126 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); |
105 | 127 |
106 SpdyServerHostPortTable::const_iterator spdy_host_port = | 128 SpdyServerHostPortTable::const_iterator spdy_host_port = |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 254 |
233 void HttpServerPropertiesImpl::ClearSpdySettings() { | 255 void HttpServerPropertiesImpl::ClearSpdySettings() { |
234 spdy_settings_map_.clear(); | 256 spdy_settings_map_.clear(); |
235 } | 257 } |
236 | 258 |
237 const SpdySettingsMap& | 259 const SpdySettingsMap& |
238 HttpServerPropertiesImpl::spdy_settings_map() const { | 260 HttpServerPropertiesImpl::spdy_settings_map() const { |
239 return spdy_settings_map_; | 261 return spdy_settings_map_; |
240 } | 262 } |
241 | 263 |
264 HttpPipelinedHostCapability HttpServerPropertiesImpl::GetPipelineCapability( | |
265 const HostPortPair& origin) { | |
266 HttpPipelinedHostCapability capability = PIPELINE_UNKNOWN; | |
267 CachedPipelineCapabilityMap::const_iterator it = | |
268 pipeline_capability_map_.Get(origin); | |
269 if (it != pipeline_capability_map_.end()) { | |
270 capability = it->second; | |
271 } | |
272 return capability; | |
273 } | |
274 | |
275 void HttpServerPropertiesImpl::SetPipelineCapability( | |
276 const HostPortPair& origin, | |
277 HttpPipelinedHostCapability capability) { | |
278 CachedPipelineCapabilityMap::iterator it = | |
279 pipeline_capability_map_.Peek(origin); | |
280 if (it == pipeline_capability_map_.end() || | |
281 it->second != PIPELINE_INCAPABLE) { | |
282 pipeline_capability_map_.Put(origin, capability); | |
283 } | |
284 } | |
285 | |
286 void HttpServerPropertiesImpl::ClearPipelineCapabilities() { | |
287 pipeline_capability_map_.Clear(); | |
288 } | |
289 | |
290 PipelineCapabilityMap | |
291 HttpServerPropertiesImpl::GetPipelineCapabilityMap() const { | |
292 PipelineCapabilityMap result; | |
293 CachedPipelineCapabilityMap::const_iterator it; | |
294 for (it = pipeline_capability_map_.begin(); | |
295 it != pipeline_capability_map_.end(); ++it) { | |
296 result[it->first] = it->second; | |
297 } | |
298 return result; | |
299 } | |
300 | |
242 } // namespace net | 301 } // namespace net |
OLD | NEW |