OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 const uint64 kBrokenAlternateProtocolDelaySecs = 300; | 19 const uint64 kBrokenAlternateProtocolDelaySecs = 300; |
20 | 20 |
21 } // namespace | 21 } // namespace |
22 | 22 |
23 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 23 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
24 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), | 24 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), |
25 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), | 25 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), |
26 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), | 26 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), |
| 27 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), |
27 alternate_protocol_probability_threshold_(1), | 28 alternate_protocol_probability_threshold_(1), |
28 weak_ptr_factory_(this) { | 29 weak_ptr_factory_(this) { |
29 canonical_suffixes_.push_back(".c.youtube.com"); | 30 canonical_suffixes_.push_back(".c.youtube.com"); |
30 canonical_suffixes_.push_back(".googlevideo.com"); | 31 canonical_suffixes_.push_back(".googlevideo.com"); |
31 canonical_suffixes_.push_back(".googleusercontent.com"); | 32 canonical_suffixes_.push_back(".googleusercontent.com"); |
32 } | 33 } |
33 | 34 |
34 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 35 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
35 } | 36 } |
36 | 37 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 103 |
103 void HttpServerPropertiesImpl::InitializeSupportsQuic( | 104 void HttpServerPropertiesImpl::InitializeSupportsQuic( |
104 SupportsQuicMap* supports_quic_map) { | 105 SupportsQuicMap* supports_quic_map) { |
105 for (SupportsQuicMap::reverse_iterator it = supports_quic_map->rbegin(); | 106 for (SupportsQuicMap::reverse_iterator it = supports_quic_map->rbegin(); |
106 it != supports_quic_map->rend(); | 107 it != supports_quic_map->rend(); |
107 ++it) { | 108 ++it) { |
108 supports_quic_map_.insert(std::make_pair(it->first, it->second)); | 109 supports_quic_map_.insert(std::make_pair(it->first, it->second)); |
109 } | 110 } |
110 } | 111 } |
111 | 112 |
| 113 void HttpServerPropertiesImpl::InitializeServerNetworkStats( |
| 114 ServerNetworkStatsMap* server_network_stats_map) { |
| 115 for (ServerNetworkStatsMap::reverse_iterator it = |
| 116 server_network_stats_map->rbegin(); |
| 117 it != server_network_stats_map->rend(); ++it) { |
| 118 server_network_stats_map_.Put(it->first, it->second); |
| 119 } |
| 120 } |
| 121 |
112 void HttpServerPropertiesImpl::GetSpdyServerList( | 122 void HttpServerPropertiesImpl::GetSpdyServerList( |
113 base::ListValue* spdy_server_list, | 123 base::ListValue* spdy_server_list, |
114 size_t max_size) const { | 124 size_t max_size) const { |
115 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
116 DCHECK(spdy_server_list); | 126 DCHECK(spdy_server_list); |
117 spdy_server_list->Clear(); | 127 spdy_server_list->Clear(); |
118 size_t count = 0; | 128 size_t count = 0; |
119 // Get the list of servers (host/port) that support SPDY. | 129 // Get the list of servers (host/port) that support SPDY. |
120 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); | 130 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); |
121 it != spdy_servers_map_.end() && count < max_size; ++it) { | 131 it != spdy_servers_map_.end() && count < max_size; ++it) { |
(...skipping 26 matching lines...) Expand all Loading... |
148 return weak_ptr_factory_.GetWeakPtr(); | 158 return weak_ptr_factory_.GetWeakPtr(); |
149 } | 159 } |
150 | 160 |
151 void HttpServerPropertiesImpl::Clear() { | 161 void HttpServerPropertiesImpl::Clear() { |
152 DCHECK(CalledOnValidThread()); | 162 DCHECK(CalledOnValidThread()); |
153 spdy_servers_map_.Clear(); | 163 spdy_servers_map_.Clear(); |
154 alternate_protocol_map_.Clear(); | 164 alternate_protocol_map_.Clear(); |
155 canonical_host_to_origin_map_.clear(); | 165 canonical_host_to_origin_map_.clear(); |
156 spdy_settings_map_.Clear(); | 166 spdy_settings_map_.Clear(); |
157 supports_quic_map_.clear(); | 167 supports_quic_map_.clear(); |
| 168 server_network_stats_map_.Clear(); |
158 } | 169 } |
159 | 170 |
160 bool HttpServerPropertiesImpl::SupportsSpdy( | 171 bool HttpServerPropertiesImpl::SupportsSpdy( |
161 const net::HostPortPair& host_port_pair) { | 172 const HostPortPair& host_port_pair) { |
162 DCHECK(CalledOnValidThread()); | 173 DCHECK(CalledOnValidThread()); |
163 if (host_port_pair.host().empty()) | 174 if (host_port_pair.host().empty()) |
164 return false; | 175 return false; |
165 | 176 |
166 SpdyServerHostPortMap::iterator spdy_host_port = | 177 SpdyServerHostPortMap::iterator spdy_host_port = |
167 spdy_servers_map_.Get(host_port_pair.ToString()); | 178 spdy_servers_map_.Get(host_port_pair.ToString()); |
168 if (spdy_host_port != spdy_servers_map_.end()) | 179 if (spdy_host_port != spdy_servers_map_.end()) |
169 return spdy_host_port->second; | 180 return spdy_host_port->second; |
170 return false; | 181 return false; |
171 } | 182 } |
172 | 183 |
173 void HttpServerPropertiesImpl::SetSupportsSpdy( | 184 void HttpServerPropertiesImpl::SetSupportsSpdy( |
174 const net::HostPortPair& host_port_pair, | 185 const HostPortPair& host_port_pair, |
175 bool support_spdy) { | 186 bool support_spdy) { |
176 DCHECK(CalledOnValidThread()); | 187 DCHECK(CalledOnValidThread()); |
177 if (host_port_pair.host().empty()) | 188 if (host_port_pair.host().empty()) |
178 return; | 189 return; |
179 | 190 |
180 SpdyServerHostPortMap::iterator spdy_host_port = | 191 SpdyServerHostPortMap::iterator spdy_host_port = |
181 spdy_servers_map_.Get(host_port_pair.ToString()); | 192 spdy_servers_map_.Get(host_port_pair.ToString()); |
182 if ((spdy_host_port != spdy_servers_map_.end()) && | 193 if ((spdy_host_port != spdy_servers_map_.end()) && |
183 (spdy_host_port->second == support_spdy)) { | 194 (spdy_host_port->second == support_spdy)) { |
184 return; | 195 return; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 416 } |
406 | 417 |
407 void HttpServerPropertiesImpl::SetSupportsQuic( | 418 void HttpServerPropertiesImpl::SetSupportsQuic( |
408 const HostPortPair& host_port_pair, | 419 const HostPortPair& host_port_pair, |
409 bool used_quic, | 420 bool used_quic, |
410 const std::string& address) { | 421 const std::string& address) { |
411 SupportsQuic supports_quic(used_quic, address); | 422 SupportsQuic supports_quic(used_quic, address); |
412 supports_quic_map_.insert(std::make_pair(host_port_pair, supports_quic)); | 423 supports_quic_map_.insert(std::make_pair(host_port_pair, supports_quic)); |
413 } | 424 } |
414 | 425 |
415 const SupportsQuicMap& | 426 const SupportsQuicMap& HttpServerPropertiesImpl::supports_quic_map() const { |
416 HttpServerPropertiesImpl::supports_quic_map() const { | |
417 return supports_quic_map_; | 427 return supports_quic_map_; |
418 } | 428 } |
419 | 429 |
420 void HttpServerPropertiesImpl::SetServerNetworkStats( | 430 void HttpServerPropertiesImpl::SetServerNetworkStats( |
421 const HostPortPair& host_port_pair, | 431 const HostPortPair& host_port_pair, |
422 NetworkStats stats) { | 432 ServerNetworkStats stats) { |
423 server_network_stats_map_[host_port_pair] = stats; | 433 server_network_stats_map_.Put(host_port_pair, stats); |
424 } | 434 } |
425 | 435 |
426 const HttpServerProperties::NetworkStats* | 436 const ServerNetworkStats* HttpServerPropertiesImpl::GetServerNetworkStats( |
427 HttpServerPropertiesImpl::GetServerNetworkStats( | 437 const HostPortPair& host_port_pair) { |
428 const HostPortPair& host_port_pair) const { | 438 ServerNetworkStatsMap::iterator it = |
429 ServerNetworkStatsMap::const_iterator it = | 439 server_network_stats_map_.Get(host_port_pair); |
430 server_network_stats_map_.find(host_port_pair); | |
431 if (it == server_network_stats_map_.end()) { | 440 if (it == server_network_stats_map_.end()) { |
432 return NULL; | 441 return NULL; |
433 } | 442 } |
434 return &it->second; | 443 return &it->second; |
435 } | 444 } |
436 | 445 |
| 446 const ServerNetworkStatsMap& |
| 447 HttpServerPropertiesImpl::server_network_stats_map() const { |
| 448 return server_network_stats_map_; |
| 449 } |
| 450 |
437 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( | 451 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( |
438 double threshold) { | 452 double threshold) { |
439 alternate_protocol_probability_threshold_ = threshold; | 453 alternate_protocol_probability_threshold_ = threshold; |
440 } | 454 } |
441 | 455 |
442 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 456 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
443 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 457 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
444 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 458 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
445 std::string canonical_suffix = canonical_suffixes_[i]; | 459 std::string canonical_suffix = canonical_suffixes_[i]; |
446 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { | 460 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 503 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
490 base::MessageLoop::current()->PostDelayedTask( | 504 base::MessageLoop::current()->PostDelayedTask( |
491 FROM_HERE, | 505 FROM_HERE, |
492 base::Bind( | 506 base::Bind( |
493 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 507 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
494 weak_ptr_factory_.GetWeakPtr()), | 508 weak_ptr_factory_.GetWeakPtr()), |
495 delay); | 509 delay); |
496 } | 510 } |
497 | 511 |
498 } // namespace net | 512 } // namespace net |
OLD | NEW |