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 <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; | 26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; |
27 // Subsequent failures result in exponential (base 2) backoff. | 27 // Subsequent failures result in exponential (base 2) backoff. |
28 // Limit binary shift to limit delay to approximately 2 days. | 28 // Limit binary shift to limit delay to approximately 2 days. |
29 const int kBrokenDelayMaxShift = 9; | 29 const int kBrokenDelayMaxShift = 9; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 33 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
34 : spdy_servers_map_(SpdyServersMap::NO_AUTO_EVICT), | 34 : spdy_servers_map_(SpdyServersMap::NO_AUTO_EVICT), |
35 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), | 35 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), |
| 36 recently_broken_alternative_services_( |
| 37 RecentlyBrokenAlternativeServices::NO_AUTO_EVICT), |
36 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), | 38 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), |
37 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT), | 39 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT), |
38 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist), | 40 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist), |
39 weak_ptr_factory_(this) { | 41 weak_ptr_factory_(this) { |
40 canonical_suffixes_.push_back(".ggpht.com"); | 42 canonical_suffixes_.push_back(".ggpht.com"); |
41 canonical_suffixes_.push_back(".c.youtube.com"); | 43 canonical_suffixes_.push_back(".c.youtube.com"); |
42 canonical_suffixes_.push_back(".googlevideo.com"); | 44 canonical_suffixes_.push_back(".googlevideo.com"); |
43 canonical_suffixes_.push_back(".googleusercontent.com"); | 45 canonical_suffixes_.push_back(".googleusercontent.com"); |
44 } | 46 } |
45 | 47 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } | 449 } |
448 | 450 |
449 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( | 451 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( |
450 const AlternativeService& alternative_service) { | 452 const AlternativeService& alternative_service) { |
451 // Empty host means use host of origin, callers are supposed to substitute. | 453 // Empty host means use host of origin, callers are supposed to substitute. |
452 DCHECK(!alternative_service.host.empty()); | 454 DCHECK(!alternative_service.host.empty()); |
453 if (alternative_service.protocol == kProtoUnknown) { | 455 if (alternative_service.protocol == kProtoUnknown) { |
454 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 456 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
455 return; | 457 return; |
456 } | 458 } |
457 ++recently_broken_alternative_services_[alternative_service]; | 459 auto it = recently_broken_alternative_services_.Get(alternative_service); |
458 int shift = recently_broken_alternative_services_[alternative_service] - 1; | 460 int shift = 0; |
| 461 if (it == recently_broken_alternative_services_.end()) { |
| 462 recently_broken_alternative_services_.Put(alternative_service, 1); |
| 463 } else { |
| 464 shift = it->second++; |
| 465 } |
459 if (shift > kBrokenDelayMaxShift) | 466 if (shift > kBrokenDelayMaxShift) |
460 shift = kBrokenDelayMaxShift; | 467 shift = kBrokenDelayMaxShift; |
461 base::TimeDelta delay = | 468 base::TimeDelta delay = |
462 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); | 469 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); |
463 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << shift); | 470 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << shift); |
464 auto result = broken_alternative_services_.insert( | 471 auto result = broken_alternative_services_.insert( |
465 std::make_pair(alternative_service, when)); | 472 std::make_pair(alternative_service, when)); |
466 // Return if alternative service is already in expiration queue. | 473 // Return if alternative service is already in expiration queue. |
467 if (!result.second) { | 474 if (!result.second) { |
468 return; | 475 return; |
469 } | 476 } |
470 | 477 |
471 // If this is the only entry in the list, schedule an expiration task. | 478 // If this is the only entry in the list, schedule an expiration task. |
472 // Otherwise it will be rescheduled automatically when the pending task runs. | 479 // Otherwise it will be rescheduled automatically when the pending task runs. |
473 if (broken_alternative_services_.size() == 1) { | 480 if (broken_alternative_services_.size() == 1) { |
474 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 481 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
475 } | 482 } |
476 } | 483 } |
477 | 484 |
478 void HttpServerPropertiesImpl::MarkAlternativeServiceRecentlyBroken( | 485 void HttpServerPropertiesImpl::MarkAlternativeServiceRecentlyBroken( |
479 const AlternativeService& alternative_service) { | 486 const AlternativeService& alternative_service) { |
480 if (!base::ContainsKey(recently_broken_alternative_services_, | 487 if (recently_broken_alternative_services_.Get(alternative_service) == |
481 alternative_service)) | 488 recently_broken_alternative_services_.end()) { |
482 recently_broken_alternative_services_[alternative_service] = 1; | 489 recently_broken_alternative_services_.Put(alternative_service, 1); |
| 490 } |
483 } | 491 } |
484 | 492 |
485 bool HttpServerPropertiesImpl::IsAlternativeServiceBroken( | 493 bool HttpServerPropertiesImpl::IsAlternativeServiceBroken( |
486 const AlternativeService& alternative_service) const { | 494 const AlternativeService& alternative_service) const { |
487 // Empty host means use host of origin, callers are supposed to substitute. | 495 // Empty host means use host of origin, callers are supposed to substitute. |
488 DCHECK(!alternative_service.host.empty()); | 496 DCHECK(!alternative_service.host.empty()); |
489 return base::ContainsKey(broken_alternative_services_, alternative_service); | 497 return base::ContainsKey(broken_alternative_services_, alternative_service); |
490 } | 498 } |
491 | 499 |
492 bool HttpServerPropertiesImpl::WasAlternativeServiceRecentlyBroken( | 500 bool HttpServerPropertiesImpl::WasAlternativeServiceRecentlyBroken( |
493 const AlternativeService& alternative_service) { | 501 const AlternativeService& alternative_service) { |
494 if (alternative_service.protocol == kProtoUnknown) | 502 if (alternative_service.protocol == kProtoUnknown) |
495 return false; | 503 return false; |
496 return base::ContainsKey(recently_broken_alternative_services_, | 504 |
497 alternative_service); | 505 return recently_broken_alternative_services_.Get(alternative_service) != |
| 506 recently_broken_alternative_services_.end(); |
498 } | 507 } |
499 | 508 |
500 void HttpServerPropertiesImpl::ConfirmAlternativeService( | 509 void HttpServerPropertiesImpl::ConfirmAlternativeService( |
501 const AlternativeService& alternative_service) { | 510 const AlternativeService& alternative_service) { |
502 if (alternative_service.protocol == kProtoUnknown) | 511 if (alternative_service.protocol == kProtoUnknown) |
503 return; | 512 return; |
504 broken_alternative_services_.erase(alternative_service); | 513 broken_alternative_services_.erase(alternative_service); |
505 recently_broken_alternative_services_.erase(alternative_service); | 514 auto it = recently_broken_alternative_services_.Get(alternative_service); |
| 515 if (it != recently_broken_alternative_services_.end()) { |
| 516 recently_broken_alternative_services_.Erase(it); |
| 517 } |
506 } | 518 } |
507 | 519 |
508 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() | 520 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() |
509 const { | 521 const { |
510 return alternative_service_map_; | 522 return alternative_service_map_; |
511 } | 523 } |
512 | 524 |
513 std::unique_ptr<base::Value> | 525 std::unique_ptr<base::Value> |
514 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() const { | 526 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() const { |
515 std::unique_ptr<base::ListValue> dict_list(new base::ListValue); | 527 std::unique_ptr<base::ListValue> dict_list(new base::ListValue); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 763 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
752 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 764 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
753 FROM_HERE, | 765 FROM_HERE, |
754 base::Bind( | 766 base::Bind( |
755 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 767 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
756 weak_ptr_factory_.GetWeakPtr()), | 768 weak_ptr_factory_.GetWeakPtr()), |
757 delay); | 769 delay); |
758 } | 770 } |
759 | 771 |
760 } // namespace net | 772 } // namespace net |
OLD | NEW |