| 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 alternate_protocol_probability_threshold_(1), | 27 alternate_protocol_probability_threshold_(1), |
| 28 weak_ptr_factory_(this) { | 28 weak_ptr_factory_(this) { |
| 29 canoncial_suffixes_.push_back(".c.youtube.com"); | 29 canonical_suffixes_.push_back(".c.youtube.com"); |
| 30 canoncial_suffixes_.push_back(".googlevideo.com"); | 30 canonical_suffixes_.push_back(".googlevideo.com"); |
| 31 canoncial_suffixes_.push_back(".googleusercontent.com"); | 31 canonical_suffixes_.push_back(".googleusercontent.com"); |
| 32 } | 32 } |
| 33 | 33 |
| 34 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 34 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
| 35 } | 35 } |
| 36 | 36 |
| 37 void HttpServerPropertiesImpl::InitializeSpdyServers( | 37 void HttpServerPropertiesImpl::InitializeSpdyServers( |
| 38 std::vector<std::string>* spdy_servers, | 38 std::vector<std::string>* spdy_servers, |
| 39 bool support_spdy) { | 39 bool support_spdy) { |
| 40 DCHECK(CalledOnValidThread()); | 40 DCHECK(CalledOnValidThread()); |
| 41 if (!spdy_servers) | 41 if (!spdy_servers) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 62 | 62 |
| 63 // Add the entries from persisted data. | 63 // Add the entries from persisted data. |
| 64 for (AlternateProtocolMap::reverse_iterator it = | 64 for (AlternateProtocolMap::reverse_iterator it = |
| 65 alternate_protocol_map->rbegin(); | 65 alternate_protocol_map->rbegin(); |
| 66 it != alternate_protocol_map->rend(); ++it) { | 66 it != alternate_protocol_map->rend(); ++it) { |
| 67 alternate_protocol_map_.Put(it->first, it->second); | 67 alternate_protocol_map_.Put(it->first, it->second); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Attempt to find canonical servers. | 70 // Attempt to find canonical servers. |
| 71 int canonical_ports[] = { 80, 443 }; | 71 int canonical_ports[] = { 80, 443 }; |
| 72 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 72 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 73 std::string canonical_suffix = canoncial_suffixes_[i]; | 73 std::string canonical_suffix = canonical_suffixes_[i]; |
| 74 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { | 74 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { |
| 75 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); | 75 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); |
| 76 // If we already have a valid canonical server, we're done. | 76 // If we already have a valid canonical server, we're done. |
| 77 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && | 77 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && |
| 78 (alternate_protocol_map_.Peek(canonical_host_to_origin_map_[ | 78 (alternate_protocol_map_.Peek(canonical_host_to_origin_map_[ |
| 79 canonical_host]) != alternate_protocol_map_.end())) { | 79 canonical_host]) != alternate_protocol_map_.end())) { |
| 80 continue; | 80 continue; |
| 81 } | 81 } |
| 82 // Now attempt to find a server which matches this origin and set it as | 82 // Now attempt to find a server which matches this origin and set it as |
| 83 // canonical . | 83 // canonical . |
| 84 for (AlternateProtocolMap::const_iterator it = | 84 for (AlternateProtocolMap::const_iterator it = |
| 85 alternate_protocol_map_.begin(); | 85 alternate_protocol_map_.begin(); |
| 86 it != alternate_protocol_map_.end(); ++it) { | 86 it != alternate_protocol_map_.end(); ++it) { |
| 87 if (EndsWith(it->first.host(), canoncial_suffixes_[i], false)) { | 87 if (EndsWith(it->first.host(), canonical_suffixes_[i], false)) { |
| 88 canonical_host_to_origin_map_[canonical_host] = it->first; | 88 canonical_host_to_origin_map_[canonical_host] = it->first; |
| 89 break; | 89 break; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 96 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
| 97 SpdySettingsMap* spdy_settings_map) { | 97 SpdySettingsMap* spdy_settings_map) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 return true; | 210 return true; |
| 211 } | 211 } |
| 212 | 212 |
| 213 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end(); | 213 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( | 216 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( |
| 217 const HostPortPair& server) { | 217 const HostPortPair& server) { |
| 218 // If this host ends with a canonical suffix, then return the canonical | 218 // If this host ends with a canonical suffix, then return the canonical |
| 219 // suffix. | 219 // suffix. |
| 220 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 220 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 221 std::string canonical_suffix = canoncial_suffixes_[i]; | 221 std::string canonical_suffix = canonical_suffixes_[i]; |
| 222 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { | 222 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
| 223 return canonical_suffix; | 223 return canonical_suffix; |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 return std::string(); | 226 return std::string(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 AlternateProtocolInfo | 229 AlternateProtocolInfo |
| 230 HttpServerPropertiesImpl::GetAlternateProtocol( | 230 HttpServerPropertiesImpl::GetAlternateProtocol( |
| 231 const HostPortPair& server) { | 231 const HostPortPair& server) { |
| 232 DCHECK(HasAlternateProtocol(server)); | 232 DCHECK(HasAlternateProtocol(server)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // before the first completes. In this case, only one of the jobs | 286 // before the first completes. In this case, only one of the jobs |
| 287 // would reach this code, whereas all of them should should have. | 287 // would reach this code, whereas all of them should should have. |
| 288 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); | 288 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 alternate_protocol_map_.Put(server, alternate); | 292 alternate_protocol_map_.Put(server, alternate); |
| 293 | 293 |
| 294 // If this host ends with a canonical suffix, then set it as the | 294 // If this host ends with a canonical suffix, then set it as the |
| 295 // canonical host. | 295 // canonical host. |
| 296 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 296 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 297 std::string canonical_suffix = canoncial_suffixes_[i]; | 297 std::string canonical_suffix = canonical_suffixes_[i]; |
| 298 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { | 298 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
| 299 HostPortPair canonical_host(canonical_suffix, server.port()); | 299 HostPortPair canonical_host(canonical_suffix, server.port()); |
| 300 canonical_host_to_origin_map_[canonical_host] = server; | 300 canonical_host_to_origin_map_[canonical_host] = server; |
| 301 break; | 301 break; |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( | 306 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( |
| 307 const HostPortPair& server) { | 307 const HostPortPair& server) { |
| 308 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); | 308 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 return &it->second; | 445 return &it->second; |
| 446 } | 446 } |
| 447 | 447 |
| 448 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( | 448 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( |
| 449 double threshold) { | 449 double threshold) { |
| 450 alternate_protocol_probability_threshold_ = threshold; | 450 alternate_protocol_probability_threshold_ = threshold; |
| 451 } | 451 } |
| 452 | 452 |
| 453 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 453 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
| 454 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 454 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
| 455 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 455 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 456 std::string canonical_suffix = canoncial_suffixes_[i]; | 456 std::string canonical_suffix = canonical_suffixes_[i]; |
| 457 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { | 457 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
| 458 HostPortPair canonical_host(canonical_suffix, server.port()); | 458 HostPortPair canonical_host(canonical_suffix, server.port()); |
| 459 return canonical_host_to_origin_map_.find(canonical_host); | 459 return canonical_host_to_origin_map_.find(canonical_host); |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 return canonical_host_to_origin_map_.end(); | 463 return canonical_host_to_origin_map_.end(); |
| 464 } | 464 } |
| 465 | 465 |
| 466 void HttpServerPropertiesImpl::RemoveCanonicalHost( | 466 void HttpServerPropertiesImpl::RemoveCanonicalHost( |
| 467 const HostPortPair& server) { | 467 const HostPortPair& server) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 500 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 501 base::MessageLoop::current()->PostDelayedTask( | 501 base::MessageLoop::current()->PostDelayedTask( |
| 502 FROM_HERE, | 502 FROM_HERE, |
| 503 base::Bind( | 503 base::Bind( |
| 504 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 504 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 505 weak_ptr_factory_.GetWeakPtr()), | 505 weak_ptr_factory_.GetWeakPtr()), |
| 506 delay); | 506 delay); |
| 507 } | 507 } |
| 508 | 508 |
| 509 } // namespace net | 509 } // namespace net |
| OLD | NEW |