| 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 11 matching lines...) Expand all Loading... |
| 22 // then, this is just a bad guess. | 22 // then, this is just a bad guess. |
| 23 const int kDefaultNumHostsToRemember = 200; | 23 const int kDefaultNumHostsToRemember = 200; |
| 24 | 24 |
| 25 const uint64 kBrokenAlternateProtocolDelaySecs = 300; | 25 const uint64 kBrokenAlternateProtocolDelaySecs = 300; |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 29 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
| 30 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), | 30 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), |
| 31 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), | 31 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), |
| 32 alternate_protocol_experiment_( |
| 33 ALTERNATE_PROTOCOL_NOT_PART_OF_EXPERIMENT), |
| 32 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), | 34 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), |
| 33 pipeline_capability_map_( | 35 pipeline_capability_map_( |
| 34 new CachedPipelineCapabilityMap(kDefaultNumHostsToRemember)), | 36 new CachedPipelineCapabilityMap(kDefaultNumHostsToRemember)), |
| 35 weak_ptr_factory_(this) { | 37 weak_ptr_factory_(this) { |
| 36 canoncial_suffixes_.push_back(".c.youtube.com"); | 38 canoncial_suffixes_.push_back(".c.youtube.com"); |
| 37 canoncial_suffixes_.push_back(".googlevideo.com"); | 39 canoncial_suffixes_.push_back(".googlevideo.com"); |
| 38 } | 40 } |
| 39 | 41 |
| 40 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 42 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
| 41 } | 43 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 215 |
| 214 bool HttpServerPropertiesImpl::HasAlternateProtocol( | 216 bool HttpServerPropertiesImpl::HasAlternateProtocol( |
| 215 const HostPortPair& server) { | 217 const HostPortPair& server) { |
| 216 if (alternate_protocol_map_.Get(server) != alternate_protocol_map_.end() || | 218 if (alternate_protocol_map_.Get(server) != alternate_protocol_map_.end() || |
| 217 g_forced_alternate_protocol) | 219 g_forced_alternate_protocol) |
| 218 return true; | 220 return true; |
| 219 | 221 |
| 220 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end(); | 222 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end(); |
| 221 } | 223 } |
| 222 | 224 |
| 225 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( |
| 226 const HostPortPair& server) { |
| 227 // If this host ends with a canonical suffix, then return the canonical |
| 228 // suffix. |
| 229 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { |
| 230 std::string canonical_suffix = canoncial_suffixes_[i]; |
| 231 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { |
| 232 return canonical_suffix; |
| 233 } |
| 234 } |
| 235 return std::string(); |
| 236 } |
| 237 |
| 223 PortAlternateProtocolPair | 238 PortAlternateProtocolPair |
| 224 HttpServerPropertiesImpl::GetAlternateProtocol( | 239 HttpServerPropertiesImpl::GetAlternateProtocol( |
| 225 const HostPortPair& server) { | 240 const HostPortPair& server) { |
| 226 DCHECK(HasAlternateProtocol(server)); | 241 DCHECK(HasAlternateProtocol(server)); |
| 227 | 242 |
| 228 // First check the map. | 243 // First check the map. |
| 229 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); | 244 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); |
| 230 if (it != alternate_protocol_map_.end()) | 245 if (it != alternate_protocol_map_.end()) |
| 231 return it->second; | 246 return it->second; |
| 232 | 247 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 << " from [Port: " << existing_alternate.port | 283 << " from [Port: " << existing_alternate.port |
| 269 << ", Protocol: " << existing_alternate.protocol | 284 << ", Protocol: " << existing_alternate.protocol |
| 270 << "] to [Port: " << alternate_port | 285 << "] to [Port: " << alternate_port |
| 271 << ", Protocol: " << alternate_protocol | 286 << ", Protocol: " << alternate_protocol |
| 272 << "]."; | 287 << "]."; |
| 273 } | 288 } |
| 274 } else { | 289 } else { |
| 275 // TODO(rch): Consider the case where multiple requests are started | 290 // TODO(rch): Consider the case where multiple requests are started |
| 276 // before the first completes. In this case, only one of the jobs | 291 // before the first completes. In this case, only one of the jobs |
| 277 // would reach this code, whereas all of them should should have. | 292 // would reach this code, whereas all of them should should have. |
| 278 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); | 293 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING, |
| 294 alternate_protocol_experiment_); |
| 279 } | 295 } |
| 280 | 296 |
| 281 alternate_protocol_map_.Put(server, alternate); | 297 alternate_protocol_map_.Put(server, alternate); |
| 282 | 298 |
| 283 // If this host ends with a canonical suffix, then set it as the | 299 // If this host ends with a canonical suffix, then set it as the |
| 284 // canonical host. | 300 // canonical host. |
| 285 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 301 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { |
| 286 std::string canonical_suffix = canoncial_suffixes_[i]; | 302 std::string canonical_suffix = canoncial_suffixes_[i]; |
| 287 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { | 303 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { |
| 288 HostPortPair canonical_host(canonical_suffix, server.port()); | 304 HostPortPair canonical_host(canonical_suffix, server.port()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); | 349 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); |
| 334 if (it != alternate_protocol_map_.end()) | 350 if (it != alternate_protocol_map_.end()) |
| 335 alternate_protocol_map_.Erase(it); | 351 alternate_protocol_map_.Erase(it); |
| 336 } | 352 } |
| 337 | 353 |
| 338 const AlternateProtocolMap& | 354 const AlternateProtocolMap& |
| 339 HttpServerPropertiesImpl::alternate_protocol_map() const { | 355 HttpServerPropertiesImpl::alternate_protocol_map() const { |
| 340 return alternate_protocol_map_; | 356 return alternate_protocol_map_; |
| 341 } | 357 } |
| 342 | 358 |
| 359 void HttpServerPropertiesImpl::SetAlternateProtocolExperiment( |
| 360 AlternateProtocolExperiment experiment) { |
| 361 alternate_protocol_experiment_ = experiment; |
| 362 } |
| 363 |
| 364 AlternateProtocolExperiment |
| 365 HttpServerPropertiesImpl::GetAlternateProtocolExperiment() const { |
| 366 return alternate_protocol_experiment_; |
| 367 } |
| 368 |
| 343 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( | 369 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |
| 344 const HostPortPair& host_port_pair) { | 370 const HostPortPair& host_port_pair) { |
| 345 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 371 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); |
| 346 if (it == spdy_settings_map_.end()) { | 372 if (it == spdy_settings_map_.end()) { |
| 347 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); | 373 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); |
| 348 return kEmptySettingsMap; | 374 return kEmptySettingsMap; |
| 349 } | 375 } |
| 350 return it->second; | 376 return it->second; |
| 351 } | 377 } |
| 352 | 378 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 505 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 480 base::MessageLoop::current()->PostDelayedTask( | 506 base::MessageLoop::current()->PostDelayedTask( |
| 481 FROM_HERE, | 507 FROM_HERE, |
| 482 base::Bind( | 508 base::Bind( |
| 483 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 509 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 484 weak_ptr_factory_.GetWeakPtr()), | 510 weak_ptr_factory_.GetWeakPtr()), |
| 485 delay); | 511 delay); |
| 486 } | 512 } |
| 487 | 513 |
| 488 } // namespace net | 514 } // namespace net |
| OLD | NEW |