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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 base::TimeDelta delay = | 318 base::TimeDelta delay = |
319 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); | 319 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); |
320 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 320 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); |
321 auto result = broken_alternative_services_.insert( | 321 auto result = broken_alternative_services_.insert( |
322 std::make_pair(alternative_service, when)); | 322 std::make_pair(alternative_service, when)); |
323 // Return if alternative service is already in expiration queue. | 323 // Return if alternative service is already in expiration queue. |
324 if (!result.second) { | 324 if (!result.second) { |
325 return; | 325 return; |
326 } | 326 } |
327 | 327 |
328 // Do not leave this host as canonical so that we don't infer the other | |
329 // hosts are also broken without testing them first. | |
330 RemoveCanonicalHost(origin); | |
331 | |
332 // If this is the only entry in the list, schedule an expiration task. | 328 // If this is the only entry in the list, schedule an expiration task. |
333 // Otherwise it will be rescheduled automatically when the pending task runs. | 329 // Otherwise it will be rescheduled automatically when the pending task runs. |
334 if (broken_alternative_services_.size() == 1) { | 330 if (broken_alternative_services_.size() == 1) { |
335 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 331 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
336 } | 332 } |
337 } | 333 } |
338 | 334 |
339 void HttpServerPropertiesImpl::MarkAlternativeServiceRecentlyBroken( | 335 void HttpServerPropertiesImpl::MarkAlternativeServiceRecentlyBroken( |
340 const AlternativeService& alternative_service) { | 336 const AlternativeService& alternative_service) { |
341 if (!ContainsKey(recently_broken_alternative_services_, alternative_service)) | 337 if (!ContainsKey(recently_broken_alternative_services_, alternative_service)) |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( | 479 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( |
484 double threshold) { | 480 double threshold) { |
485 alternate_protocol_probability_threshold_ = threshold; | 481 alternate_protocol_probability_threshold_ = threshold; |
486 } | 482 } |
487 | 483 |
488 AlternateProtocolMap::const_iterator | 484 AlternateProtocolMap::const_iterator |
489 HttpServerPropertiesImpl::GetAlternateProtocolIterator( | 485 HttpServerPropertiesImpl::GetAlternateProtocolIterator( |
490 const HostPortPair& server) { | 486 const HostPortPair& server) { |
491 AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server); | 487 AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server); |
492 if (it != alternate_protocol_map_.end()) | 488 if (it != alternate_protocol_map_.end()) |
493 return it; | 489 return it; |
Ryan Hamilton
2015/03/18 22:44:36
Do you need to (possibly) do the removal here too?
Bence
2015/03/19 12:44:02
It's not necessary. Consider foo being the canoni
Ryan Hamilton
2015/03/19 20:05:18
Ah, I see. Ok, do we have a test which covers this
Bence
2015/03/19 21:43:09
Yes, AlternateProtocolServerPropertiesTest.Canonic
| |
494 | 490 |
495 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); | 491 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); |
496 if (canonical != canonical_host_to_origin_map_.end()) | 492 if (canonical == canonical_host_to_origin_map_.end()) { |
497 return alternate_protocol_map_.Get(canonical->second); | 493 return alternate_protocol_map_.end(); |
494 } | |
498 | 495 |
496 const HostPortPair canonical_host_port = canonical->second; | |
497 it = alternate_protocol_map_.Get(canonical_host_port); | |
498 if (it == alternate_protocol_map_.end()) { | |
499 return alternate_protocol_map_.end(); | |
500 } | |
501 | |
502 const AlternativeService alternative_service( | |
503 it->second.protocol, canonical_host_port.host(), it->second.port); | |
504 if (!IsAlternativeServiceBroken(alternative_service)) { | |
505 return it; | |
506 } | |
507 | |
508 RemoveCanonicalHost(canonical_host_port); | |
499 return alternate_protocol_map_.end(); | 509 return alternate_protocol_map_.end(); |
500 } | 510 } |
501 | 511 |
502 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 512 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
503 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 513 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
504 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 514 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
505 std::string canonical_suffix = canonical_suffixes_[i]; | 515 std::string canonical_suffix = canonical_suffixes_[i]; |
506 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { | 516 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
507 HostPortPair canonical_host(canonical_suffix, server.port()); | 517 HostPortPair canonical_host(canonical_suffix, server.port()); |
508 return canonical_host_to_origin_map_.find(canonical_host); | 518 return canonical_host_to_origin_map_.find(canonical_host); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 561 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
552 base::MessageLoop::current()->PostDelayedTask( | 562 base::MessageLoop::current()->PostDelayedTask( |
553 FROM_HERE, | 563 FROM_HERE, |
554 base::Bind( | 564 base::Bind( |
555 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 565 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
556 weak_ptr_factory_.GetWeakPtr()), | 566 weak_ptr_factory_.GetWeakPtr()), |
557 delay); | 567 delay); |
558 } | 568 } |
559 | 569 |
560 } // namespace net | 570 } // namespace net |
OLD | NEW |