| 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" | |
| 12 | 11 |
| 13 namespace net { | 12 namespace net { |
| 14 | 13 |
| 15 // TODO(simonjam): Run experiments with different values of this to see what | 14 HttpServerPropertiesImpl::HttpServerPropertiesImpl() { |
| 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)) { | |
| 23 } | 15 } |
| 24 | 16 |
| 25 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 17 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
| 26 } | 18 } |
| 27 | 19 |
| 28 void HttpServerPropertiesImpl::InitializeSpdyServers( | 20 void HttpServerPropertiesImpl::InitializeSpdyServers( |
| 29 std::vector<std::string>* spdy_servers, | 21 std::vector<std::string>* spdy_servers, |
| 30 bool support_spdy) { | 22 bool support_spdy) { |
| 31 DCHECK(CalledOnValidThread()); | 23 DCHECK(CalledOnValidThread()); |
| 32 spdy_servers_table_.clear(); | 24 spdy_servers_table_.clear(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 49 if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN) | 41 if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN) |
| 50 alternate_protocol_map_[it->first] = it->second; | 42 alternate_protocol_map_[it->first] = it->second; |
| 51 } | 43 } |
| 52 } | 44 } |
| 53 | 45 |
| 54 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 46 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
| 55 std::map<HostPortPair, spdy::SpdySettings>* spdy_settings_map) { | 47 std::map<HostPortPair, spdy::SpdySettings>* spdy_settings_map) { |
| 56 spdy_settings_map_.swap(*spdy_settings_map); | 48 spdy_settings_map_.swap(*spdy_settings_map); |
| 57 } | 49 } |
| 58 | 50 |
| 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 | |
| 74 void HttpServerPropertiesImpl::GetSpdyServerList( | 51 void HttpServerPropertiesImpl::GetSpdyServerList( |
| 75 base::ListValue* spdy_server_list) const { | 52 base::ListValue* spdy_server_list) const { |
| 76 DCHECK(CalledOnValidThread()); | 53 DCHECK(CalledOnValidThread()); |
| 77 DCHECK(spdy_server_list); | 54 DCHECK(spdy_server_list); |
| 78 spdy_server_list->Clear(); | 55 spdy_server_list->Clear(); |
| 79 // Get the list of servers (host/port) that support SPDY. | 56 // Get the list of servers (host/port) that support SPDY. |
| 80 for (SpdyServerHostPortTable::const_iterator it = spdy_servers_table_.begin(); | 57 for (SpdyServerHostPortTable::const_iterator it = spdy_servers_table_.begin(); |
| 81 it != spdy_servers_table_.end(); ++it) { | 58 it != spdy_servers_table_.end(); ++it) { |
| 82 const std::string spdy_server_host_port = it->first; | 59 const std::string spdy_server_host_port = it->first; |
| 83 if (it->second) | 60 if (it->second) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 110 void HttpServerPropertiesImpl::DisableForcedAlternateProtocol() { | 87 void HttpServerPropertiesImpl::DisableForcedAlternateProtocol() { |
| 111 delete g_forced_alternate_protocol; | 88 delete g_forced_alternate_protocol; |
| 112 g_forced_alternate_protocol = NULL; | 89 g_forced_alternate_protocol = NULL; |
| 113 } | 90 } |
| 114 | 91 |
| 115 void HttpServerPropertiesImpl::Clear() { | 92 void HttpServerPropertiesImpl::Clear() { |
| 116 DCHECK(CalledOnValidThread()); | 93 DCHECK(CalledOnValidThread()); |
| 117 spdy_servers_table_.clear(); | 94 spdy_servers_table_.clear(); |
| 118 alternate_protocol_map_.clear(); | 95 alternate_protocol_map_.clear(); |
| 119 spdy_settings_map_.clear(); | 96 spdy_settings_map_.clear(); |
| 120 pipeline_capability_map_->Clear(); | |
| 121 } | 97 } |
| 122 | 98 |
| 123 bool HttpServerPropertiesImpl::SupportsSpdy( | 99 bool HttpServerPropertiesImpl::SupportsSpdy( |
| 124 const net::HostPortPair& host_port_pair) const { | 100 const net::HostPortPair& host_port_pair) const { |
| 125 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
| 126 if (host_port_pair.host().empty()) | 102 if (host_port_pair.host().empty()) |
| 127 return false; | 103 return false; |
| 128 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); | 104 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); |
| 129 | 105 |
| 130 SpdyServerHostPortTable::const_iterator spdy_host_port = | 106 SpdyServerHostPortTable::const_iterator spdy_host_port = |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 232 |
| 257 void HttpServerPropertiesImpl::ClearSpdySettings() { | 233 void HttpServerPropertiesImpl::ClearSpdySettings() { |
| 258 spdy_settings_map_.clear(); | 234 spdy_settings_map_.clear(); |
| 259 } | 235 } |
| 260 | 236 |
| 261 const SpdySettingsMap& | 237 const SpdySettingsMap& |
| 262 HttpServerPropertiesImpl::spdy_settings_map() const { | 238 HttpServerPropertiesImpl::spdy_settings_map() const { |
| 263 return spdy_settings_map_; | 239 return spdy_settings_map_; |
| 264 } | 240 } |
| 265 | 241 |
| 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 | |
| 303 } // namespace net | 242 } // namespace net |
| OLD | NEW |