| 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" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 96 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
| 97 SpdySettingsMap* spdy_settings_map) { | 97 SpdySettingsMap* spdy_settings_map) { |
| 98 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); | 98 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); |
| 99 it != spdy_settings_map->rend(); ++it) { | 99 it != spdy_settings_map->rend(); ++it) { |
| 100 spdy_settings_map_.Put(it->first, it->second); | 100 spdy_settings_map_.Put(it->first, it->second); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 void HttpServerPropertiesImpl::InitializeSupportsQuic( | 104 void HttpServerPropertiesImpl::InitializeSupportsQuic( |
| 105 SupportsQuicMap* supports_quic_map) { | 105 IPAddressNumber* last_address) { |
| 106 for (SupportsQuicMap::reverse_iterator it = supports_quic_map->rbegin(); | 106 if (last_address) |
| 107 it != supports_quic_map->rend(); | 107 last_quic_address_ = *last_address; |
| 108 ++it) { | |
| 109 supports_quic_map_.insert(std::make_pair(it->first, it->second)); | |
| 110 } | |
| 111 } | 108 } |
| 112 | 109 |
| 113 void HttpServerPropertiesImpl::InitializeServerNetworkStats( | 110 void HttpServerPropertiesImpl::InitializeServerNetworkStats( |
| 114 ServerNetworkStatsMap* server_network_stats_map) { | 111 ServerNetworkStatsMap* server_network_stats_map) { |
| 115 for (ServerNetworkStatsMap::reverse_iterator it = | 112 for (ServerNetworkStatsMap::reverse_iterator it = |
| 116 server_network_stats_map->rbegin(); | 113 server_network_stats_map->rbegin(); |
| 117 it != server_network_stats_map->rend(); ++it) { | 114 it != server_network_stats_map->rend(); ++it) { |
| 118 server_network_stats_map_.Put(it->first, it->second); | 115 server_network_stats_map_.Put(it->first, it->second); |
| 119 } | 116 } |
| 120 } | 117 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { | 154 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { |
| 158 return weak_ptr_factory_.GetWeakPtr(); | 155 return weak_ptr_factory_.GetWeakPtr(); |
| 159 } | 156 } |
| 160 | 157 |
| 161 void HttpServerPropertiesImpl::Clear() { | 158 void HttpServerPropertiesImpl::Clear() { |
| 162 DCHECK(CalledOnValidThread()); | 159 DCHECK(CalledOnValidThread()); |
| 163 spdy_servers_map_.Clear(); | 160 spdy_servers_map_.Clear(); |
| 164 alternate_protocol_map_.Clear(); | 161 alternate_protocol_map_.Clear(); |
| 165 canonical_host_to_origin_map_.clear(); | 162 canonical_host_to_origin_map_.clear(); |
| 166 spdy_settings_map_.Clear(); | 163 spdy_settings_map_.Clear(); |
| 167 supports_quic_map_.clear(); | 164 last_quic_address_.clear(); |
| 168 server_network_stats_map_.Clear(); | 165 server_network_stats_map_.Clear(); |
| 169 } | 166 } |
| 170 | 167 |
| 171 bool HttpServerPropertiesImpl::SupportsRequestPriority( | 168 bool HttpServerPropertiesImpl::SupportsRequestPriority( |
| 172 const HostPortPair& host_port_pair) { | 169 const HostPortPair& host_port_pair) { |
| 173 DCHECK(CalledOnValidThread()); | 170 DCHECK(CalledOnValidThread()); |
| 174 if (host_port_pair.host().empty()) | 171 if (host_port_pair.host().empty()) |
| 175 return false; | 172 return false; |
| 176 | 173 |
| 177 SpdyServerHostPortMap::iterator spdy_host_port = | 174 SpdyServerHostPortMap::iterator spdy_host_port = |
| 178 spdy_servers_map_.Get(host_port_pair.ToString()); | 175 spdy_servers_map_.Get(host_port_pair.ToString()); |
| 179 if (spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second) | 176 if (spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second) |
| 180 return true; | 177 return true; |
| 181 | 178 |
| 182 if (!HasAlternateProtocol(host_port_pair)) | 179 const AlternateProtocolInfo info = GetAlternateProtocol(host_port_pair); |
| 183 return false; | |
| 184 | |
| 185 AlternateProtocolInfo info = GetAlternateProtocol(host_port_pair); | |
| 186 return info.protocol == QUIC; | 180 return info.protocol == QUIC; |
| 187 } | 181 } |
| 188 | 182 |
| 189 void HttpServerPropertiesImpl::SetSupportsSpdy( | 183 void HttpServerPropertiesImpl::SetSupportsSpdy( |
| 190 const HostPortPair& host_port_pair, | 184 const HostPortPair& host_port_pair, |
| 191 bool support_spdy) { | 185 bool support_spdy) { |
| 192 DCHECK(CalledOnValidThread()); | 186 DCHECK(CalledOnValidThread()); |
| 193 if (host_port_pair.host().empty()) | 187 if (host_port_pair.host().empty()) |
| 194 return; | 188 return; |
| 195 | 189 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 221 http11_servers_.insert(host_port_pair); | 215 http11_servers_.insert(host_port_pair); |
| 222 } | 216 } |
| 223 | 217 |
| 224 void HttpServerPropertiesImpl::MaybeForceHTTP11(const HostPortPair& server, | 218 void HttpServerPropertiesImpl::MaybeForceHTTP11(const HostPortPair& server, |
| 225 SSLConfig* ssl_config) { | 219 SSLConfig* ssl_config) { |
| 226 if (RequiresHTTP11(server)) { | 220 if (RequiresHTTP11(server)) { |
| 227 ForceHTTP11(ssl_config); | 221 ForceHTTP11(ssl_config); |
| 228 } | 222 } |
| 229 } | 223 } |
| 230 | 224 |
| 231 bool HttpServerPropertiesImpl::HasAlternateProtocol( | |
| 232 const HostPortPair& server) { | |
| 233 if (g_forced_alternate_protocol) | |
| 234 return true; | |
| 235 AlternateProtocolMap::const_iterator it = | |
| 236 GetAlternateProtocolIterator(server); | |
| 237 return it != alternate_protocol_map_.end() && | |
| 238 it->second.probability >= alternate_protocol_probability_threshold_; | |
| 239 } | |
| 240 | |
| 241 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( | 225 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( |
| 242 const std::string& host) { | 226 const std::string& host) { |
| 243 // If this host ends with a canonical suffix, then return the canonical | 227 // If this host ends with a canonical suffix, then return the canonical |
| 244 // suffix. | 228 // suffix. |
| 245 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 229 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 246 std::string canonical_suffix = canonical_suffixes_[i]; | 230 std::string canonical_suffix = canonical_suffixes_[i]; |
| 247 if (EndsWith(host, canonical_suffixes_[i], false)) { | 231 if (EndsWith(host, canonical_suffixes_[i], false)) { |
| 248 return canonical_suffix; | 232 return canonical_suffix; |
| 249 } | 233 } |
| 250 } | 234 } |
| 251 return std::string(); | 235 return std::string(); |
| 252 } | 236 } |
| 253 | 237 |
| 254 AlternateProtocolInfo | 238 AlternateProtocolInfo HttpServerPropertiesImpl::GetAlternateProtocol( |
| 255 HttpServerPropertiesImpl::GetAlternateProtocol( | |
| 256 const HostPortPair& server) { | 239 const HostPortPair& server) { |
| 257 DCHECK(HasAlternateProtocol(server)); | |
| 258 | |
| 259 AlternateProtocolMap::const_iterator it = | 240 AlternateProtocolMap::const_iterator it = |
| 260 GetAlternateProtocolIterator(server); | 241 GetAlternateProtocolIterator(server); |
| 261 if (it != alternate_protocol_map_.end()) | 242 if (it != alternate_protocol_map_.end() && |
| 243 it->second.probability >= alternate_protocol_probability_threshold_) |
| 262 return it->second; | 244 return it->second; |
| 263 | 245 |
| 264 // We must be forcing an alternate. | 246 if (g_forced_alternate_protocol) |
| 265 DCHECK(g_forced_alternate_protocol); | 247 return *g_forced_alternate_protocol; |
| 266 return *g_forced_alternate_protocol; | 248 |
| 249 AlternateProtocolInfo uninitialized_alternate_protocol; |
| 250 return uninitialized_alternate_protocol; |
| 267 } | 251 } |
| 268 | 252 |
| 269 void HttpServerPropertiesImpl::SetAlternateProtocol( | 253 void HttpServerPropertiesImpl::SetAlternateProtocol( |
| 270 const HostPortPair& server, | 254 const HostPortPair& server, |
| 271 uint16 alternate_port, | 255 uint16 alternate_port, |
| 272 AlternateProtocol alternate_protocol, | 256 AlternateProtocol alternate_protocol, |
| 273 double alternate_probability) { | 257 double alternate_probability) { |
| 274 | 258 |
| 275 AlternateProtocolInfo alternate(alternate_port, | 259 AlternateProtocolInfo alternate(alternate_port, |
| 276 alternate_protocol, | 260 alternate_protocol, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 HostPortPair canonical_host(canonical_suffix, server.port()); | 299 HostPortPair canonical_host(canonical_suffix, server.port()); |
| 316 canonical_host_to_origin_map_[canonical_host] = server; | 300 canonical_host_to_origin_map_[canonical_host] = server; |
| 317 break; | 301 break; |
| 318 } | 302 } |
| 319 } | 303 } |
| 320 } | 304 } |
| 321 | 305 |
| 322 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( | 306 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( |
| 323 const HostPortPair& server) { | 307 const HostPortPair& server) { |
| 324 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); | 308 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); |
| 309 const AlternateProtocolInfo alternate = GetAlternateProtocol(server); |
| 325 if (it == alternate_protocol_map_.end()) { | 310 if (it == alternate_protocol_map_.end()) { |
| 326 if (!HasAlternateProtocol(server)) { | 311 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 327 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 312 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
| 328 return; | 313 return; |
| 329 } | 314 } |
| 330 // This server's alternate protocol information is coming from a canonical | 315 // This server's alternate protocol information is coming from a canonical |
| 331 // server. Add an entry in the map for this server explicitly so that | 316 // server. Add an entry in the map for this server explicitly so that |
| 332 // it can be marked as broken. | 317 // it can be marked as broken. |
| 333 it = alternate_protocol_map_.Put(server, GetAlternateProtocol(server)); | 318 it = alternate_protocol_map_.Put(server, alternate); |
| 334 } | 319 } |
| 335 it->second.is_broken = true; | 320 it->second.is_broken = true; |
| 336 int count = ++broken_alternate_protocol_map_[server]; | 321 const BrokenAlternateProtocolEntry entry(server, alternate.port, |
| 322 alternate.protocol); |
| 323 int count = ++broken_alternate_protocol_map_[entry]; |
| 337 base::TimeDelta delay = | 324 base::TimeDelta delay = |
| 338 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); | 325 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); |
| 339 BrokenAlternateProtocolEntry entry; | 326 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); |
| 340 entry.server = server; | 327 broken_alternate_protocol_list_.push_back( |
| 341 entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 328 BrokenAlternateProtocolEntryWithTime(entry, when)); |
| 342 broken_alternate_protocol_list_.push_back(entry); | |
| 343 | 329 |
| 344 // Do not leave this host as canonical so that we don't infer the other | 330 // Do not leave this host as canonical so that we don't infer the other |
| 345 // hosts are also broken without testing them first. | 331 // hosts are also broken without testing them first. |
| 346 RemoveCanonicalHost(server); | 332 RemoveCanonicalHost(server); |
| 347 | 333 |
| 348 // If this is the only entry in the list, schedule an expiration task. | 334 // If this is the only entry in the list, schedule an expiration task. |
| 349 // Otherwise it will be rescheduled automatically when the pending task runs. | 335 // Otherwise it will be rescheduled automatically when the pending task runs. |
| 350 if (broken_alternate_protocol_list_.size() == 1) { | 336 if (broken_alternate_protocol_list_.size() == 1) { |
| 351 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 337 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
| 352 } | 338 } |
| 353 } | 339 } |
| 354 | 340 |
| 355 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken( | 341 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken( |
| 356 const HostPortPair& server) { | 342 const HostPortPair& server) { |
| 357 return ContainsKey(broken_alternate_protocol_map_, server); | 343 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); |
| 344 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 345 return false; |
| 346 const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port, |
| 347 alternate_protocol.protocol); |
| 348 return ContainsKey(broken_alternate_protocol_map_, entry); |
| 358 } | 349 } |
| 359 | 350 |
| 360 void HttpServerPropertiesImpl::ConfirmAlternateProtocol( | 351 void HttpServerPropertiesImpl::ConfirmAlternateProtocol( |
| 361 const HostPortPair& server) { | 352 const HostPortPair& server) { |
| 362 broken_alternate_protocol_map_.erase(server); | 353 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); |
| 354 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 355 return; |
| 356 const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port, |
| 357 alternate_protocol.protocol); |
| 358 broken_alternate_protocol_map_.erase(entry); |
| 363 } | 359 } |
| 364 | 360 |
| 365 void HttpServerPropertiesImpl::ClearAlternateProtocol( | 361 void HttpServerPropertiesImpl::ClearAlternateProtocol( |
| 366 const HostPortPair& server) { | 362 const HostPortPair& server) { |
| 367 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); | 363 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); |
| 368 if (it != alternate_protocol_map_.end()) | 364 if (it != alternate_protocol_map_.end()) |
| 369 alternate_protocol_map_.Erase(it); | 365 alternate_protocol_map_.Erase(it); |
| 370 | 366 |
| 371 RemoveCanonicalHost(server); | 367 RemoveCanonicalHost(server); |
| 372 } | 368 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 412 |
| 417 void HttpServerPropertiesImpl::ClearAllSpdySettings() { | 413 void HttpServerPropertiesImpl::ClearAllSpdySettings() { |
| 418 spdy_settings_map_.Clear(); | 414 spdy_settings_map_.Clear(); |
| 419 } | 415 } |
| 420 | 416 |
| 421 const SpdySettingsMap& | 417 const SpdySettingsMap& |
| 422 HttpServerPropertiesImpl::spdy_settings_map() const { | 418 HttpServerPropertiesImpl::spdy_settings_map() const { |
| 423 return spdy_settings_map_; | 419 return spdy_settings_map_; |
| 424 } | 420 } |
| 425 | 421 |
| 426 SupportsQuic HttpServerPropertiesImpl::GetSupportsQuic( | 422 bool HttpServerPropertiesImpl::GetSupportsQuic( |
| 427 const HostPortPair& host_port_pair) const { | 423 IPAddressNumber* last_address) const { |
| 428 SupportsQuicMap::const_iterator it = supports_quic_map_.find(host_port_pair); | 424 if (last_quic_address_.empty()) |
| 429 if (it == supports_quic_map_.end()) { | 425 return false; |
| 430 CR_DEFINE_STATIC_LOCAL(SupportsQuic, kEmptySupportsQuic, ()); | 426 |
| 431 return kEmptySupportsQuic; | 427 *last_address = last_quic_address_; |
| 432 } | 428 return true; |
| 433 return it->second; | |
| 434 } | 429 } |
| 435 | 430 |
| 436 void HttpServerPropertiesImpl::SetSupportsQuic( | 431 void HttpServerPropertiesImpl::SetSupportsQuic(bool used_quic, |
| 437 const HostPortPair& host_port_pair, | 432 const IPAddressNumber& address) { |
| 438 bool used_quic, | 433 if (!used_quic) { |
| 439 const std::string& address) { | 434 last_quic_address_.clear(); |
| 440 SupportsQuic supports_quic(used_quic, address); | 435 } else { |
| 441 supports_quic_map_.insert(std::make_pair(host_port_pair, supports_quic)); | 436 last_quic_address_ = address; |
| 442 } | 437 } |
| 443 | |
| 444 const SupportsQuicMap& HttpServerPropertiesImpl::supports_quic_map() const { | |
| 445 return supports_quic_map_; | |
| 446 } | 438 } |
| 447 | 439 |
| 448 void HttpServerPropertiesImpl::SetServerNetworkStats( | 440 void HttpServerPropertiesImpl::SetServerNetworkStats( |
| 449 const HostPortPair& host_port_pair, | 441 const HostPortPair& host_port_pair, |
| 450 ServerNetworkStats stats) { | 442 ServerNetworkStats stats) { |
| 451 server_network_stats_map_.Put(host_port_pair, stats); | 443 server_network_stats_map_.Put(host_port_pair, stats); |
| 452 } | 444 } |
| 453 | 445 |
| 454 const ServerNetworkStats* HttpServerPropertiesImpl::GetServerNetworkStats( | 446 const ServerNetworkStats* HttpServerPropertiesImpl::GetServerNetworkStats( |
| 455 const HostPortPair& host_port_pair) { | 447 const HostPortPair& host_port_pair) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 498 |
| 507 if (!canonical->second.Equals(server)) | 499 if (!canonical->second.Equals(server)) |
| 508 return; | 500 return; |
| 509 | 501 |
| 510 canonical_host_to_origin_map_.erase(canonical->first); | 502 canonical_host_to_origin_map_.erase(canonical->first); |
| 511 } | 503 } |
| 512 | 504 |
| 513 void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() { | 505 void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() { |
| 514 base::TimeTicks now = base::TimeTicks::Now(); | 506 base::TimeTicks now = base::TimeTicks::Now(); |
| 515 while (!broken_alternate_protocol_list_.empty()) { | 507 while (!broken_alternate_protocol_list_.empty()) { |
| 516 BrokenAlternateProtocolEntry entry = | 508 BrokenAlternateProtocolEntryWithTime entry_with_time = |
| 517 broken_alternate_protocol_list_.front(); | 509 broken_alternate_protocol_list_.front(); |
| 518 if (now < entry.when) { | 510 if (now < entry_with_time.when) { |
| 519 break; | 511 break; |
| 520 } | 512 } |
| 521 | 513 |
| 514 const BrokenAlternateProtocolEntry& entry = |
| 515 entry_with_time.broken_alternate_protocol_entry; |
| 522 ClearAlternateProtocol(entry.server); | 516 ClearAlternateProtocol(entry.server); |
| 523 broken_alternate_protocol_list_.pop_front(); | 517 broken_alternate_protocol_list_.pop_front(); |
| 524 } | 518 } |
| 525 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 519 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
| 526 } | 520 } |
| 527 | 521 |
| 528 void | 522 void |
| 529 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { | 523 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { |
| 530 if (broken_alternate_protocol_list_.empty()) { | 524 if (broken_alternate_protocol_list_.empty()) { |
| 531 return; | 525 return; |
| 532 } | 526 } |
| 533 base::TimeTicks now = base::TimeTicks::Now(); | 527 base::TimeTicks now = base::TimeTicks::Now(); |
| 534 base::TimeTicks when = broken_alternate_protocol_list_.front().when; | 528 base::TimeTicks when = broken_alternate_protocol_list_.front().when; |
| 535 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 529 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 536 base::MessageLoop::current()->PostDelayedTask( | 530 base::MessageLoop::current()->PostDelayedTask( |
| 537 FROM_HERE, | 531 FROM_HERE, |
| 538 base::Bind( | 532 base::Bind( |
| 539 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 533 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 540 weak_ptr_factory_.GetWeakPtr()), | 534 weak_ptr_factory_.GetWeakPtr()), |
| 541 delay); | 535 delay); |
| 542 } | 536 } |
| 543 | 537 |
| 544 } // namespace net | 538 } // namespace net |
| OLD | NEW |