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 kDefaultNumHostsToRemember = 200; |
| 19 |
| 20 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
| 21 : pipeline_capability_map_( |
| 22 new CachedPipelineCapabilityMap(kDefaultNumHostsToRemember)) { |
15 } | 23 } |
16 | 24 |
17 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 25 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
18 } | 26 } |
19 | 27 |
20 void HttpServerPropertiesImpl::InitializeSpdyServers( | 28 void HttpServerPropertiesImpl::InitializeSpdyServers( |
21 std::vector<std::string>* spdy_servers, | 29 std::vector<std::string>* spdy_servers, |
22 bool support_spdy) { | 30 bool support_spdy) { |
23 DCHECK(CalledOnValidThread()); | 31 DCHECK(CalledOnValidThread()); |
24 spdy_servers_table_.clear(); | 32 spdy_servers_table_.clear(); |
(...skipping 16 matching lines...) Expand all Loading... |
41 if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN) | 49 if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN) |
42 alternate_protocol_map_[it->first] = it->second; | 50 alternate_protocol_map_[it->first] = it->second; |
43 } | 51 } |
44 } | 52 } |
45 | 53 |
46 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 54 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
47 std::map<HostPortPair, spdy::SpdySettings>* spdy_settings_map) { | 55 std::map<HostPortPair, spdy::SpdySettings>* spdy_settings_map) { |
48 spdy_settings_map_.swap(*spdy_settings_map); | 56 spdy_settings_map_.swap(*spdy_settings_map); |
49 } | 57 } |
50 | 58 |
| 59 void HttpServerPropertiesImpl::InitializePipelineCapabilities( |
| 60 const PipelineCapabilityMap* pipeline_capability_map) { |
| 61 PipelineCapabilityMap::const_iterator it; |
| 62 pipeline_capability_map_->Clear(); |
| 63 for (it = pipeline_capability_map->begin(); |
| 64 it != pipeline_capability_map->end(); ++it) { |
| 65 pipeline_capability_map_->Put(it->first, it->second); |
| 66 } |
| 67 } |
| 68 |
| 69 void HttpServerPropertiesImpl::SetNumPipelinedHostsToRemember(int max_size) { |
| 70 DCHECK(pipeline_capability_map_->empty()); |
| 71 pipeline_capability_map_.reset(new CachedPipelineCapabilityMap(max_size)); |
| 72 } |
| 73 |
51 void HttpServerPropertiesImpl::GetSpdyServerList( | 74 void HttpServerPropertiesImpl::GetSpdyServerList( |
52 base::ListValue* spdy_server_list) const { | 75 base::ListValue* spdy_server_list) const { |
53 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
54 DCHECK(spdy_server_list); | 77 DCHECK(spdy_server_list); |
55 spdy_server_list->Clear(); | 78 spdy_server_list->Clear(); |
56 // Get the list of servers (host/port) that support SPDY. | 79 // Get the list of servers (host/port) that support SPDY. |
57 for (SpdyServerHostPortTable::const_iterator it = spdy_servers_table_.begin(); | 80 for (SpdyServerHostPortTable::const_iterator it = spdy_servers_table_.begin(); |
58 it != spdy_servers_table_.end(); ++it) { | 81 it != spdy_servers_table_.end(); ++it) { |
59 const std::string spdy_server_host_port = it->first; | 82 const std::string spdy_server_host_port = it->first; |
60 if (it->second) | 83 if (it->second) |
(...skipping 26 matching lines...) Expand all Loading... |
87 void HttpServerPropertiesImpl::DisableForcedAlternateProtocol() { | 110 void HttpServerPropertiesImpl::DisableForcedAlternateProtocol() { |
88 delete g_forced_alternate_protocol; | 111 delete g_forced_alternate_protocol; |
89 g_forced_alternate_protocol = NULL; | 112 g_forced_alternate_protocol = NULL; |
90 } | 113 } |
91 | 114 |
92 void HttpServerPropertiesImpl::Clear() { | 115 void HttpServerPropertiesImpl::Clear() { |
93 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
94 spdy_servers_table_.clear(); | 117 spdy_servers_table_.clear(); |
95 alternate_protocol_map_.clear(); | 118 alternate_protocol_map_.clear(); |
96 spdy_settings_map_.clear(); | 119 spdy_settings_map_.clear(); |
| 120 pipeline_capability_map_->Clear(); |
97 } | 121 } |
98 | 122 |
99 bool HttpServerPropertiesImpl::SupportsSpdy( | 123 bool HttpServerPropertiesImpl::SupportsSpdy( |
100 const net::HostPortPair& host_port_pair) const { | 124 const net::HostPortPair& host_port_pair) const { |
101 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
102 if (host_port_pair.host().empty()) | 126 if (host_port_pair.host().empty()) |
103 return false; | 127 return false; |
104 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); | 128 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); |
105 | 129 |
106 SpdyServerHostPortTable::const_iterator spdy_host_port = | 130 SpdyServerHostPortTable::const_iterator spdy_host_port = |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 256 |
233 void HttpServerPropertiesImpl::ClearSpdySettings() { | 257 void HttpServerPropertiesImpl::ClearSpdySettings() { |
234 spdy_settings_map_.clear(); | 258 spdy_settings_map_.clear(); |
235 } | 259 } |
236 | 260 |
237 const SpdySettingsMap& | 261 const SpdySettingsMap& |
238 HttpServerPropertiesImpl::spdy_settings_map() const { | 262 HttpServerPropertiesImpl::spdy_settings_map() const { |
239 return spdy_settings_map_; | 263 return spdy_settings_map_; |
240 } | 264 } |
241 | 265 |
| 266 HttpPipelinedHostCapability HttpServerPropertiesImpl::GetPipelineCapability( |
| 267 const HostPortPair& origin) { |
| 268 HttpPipelinedHostCapability capability = PIPELINE_UNKNOWN; |
| 269 CachedPipelineCapabilityMap::const_iterator it = |
| 270 pipeline_capability_map_->Get(origin); |
| 271 if (it != pipeline_capability_map_->end()) { |
| 272 capability = it->second; |
| 273 } |
| 274 return capability; |
| 275 } |
| 276 |
| 277 void HttpServerPropertiesImpl::SetPipelineCapability( |
| 278 const HostPortPair& origin, |
| 279 HttpPipelinedHostCapability capability) { |
| 280 CachedPipelineCapabilityMap::iterator it = |
| 281 pipeline_capability_map_->Peek(origin); |
| 282 if (it == pipeline_capability_map_->end() || |
| 283 it->second != PIPELINE_INCAPABLE) { |
| 284 pipeline_capability_map_->Put(origin, capability); |
| 285 } |
| 286 } |
| 287 |
| 288 void HttpServerPropertiesImpl::ClearPipelineCapabilities() { |
| 289 pipeline_capability_map_->Clear(); |
| 290 } |
| 291 |
| 292 PipelineCapabilityMap |
| 293 HttpServerPropertiesImpl::GetPipelineCapabilityMap() const { |
| 294 PipelineCapabilityMap result; |
| 295 CachedPipelineCapabilityMap::const_iterator it; |
| 296 for (it = pipeline_capability_map_->begin(); |
| 297 it != pipeline_capability_map_->end(); ++it) { |
| 298 result[it->first] = it->second; |
| 299 } |
| 300 return result; |
| 301 } |
| 302 |
242 } // namespace net | 303 } // namespace net |
OLD | NEW |