Chromium Code Reviews| 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 it->second++; | |
|
Ryan Hamilton
2017/04/05 03:34:34
Can you say:
shift = it->second++;
Zhongyi Shi
2017/04/06 21:37:14
Done.
| |
| 466 } | |
| 459 if (shift > kBrokenDelayMaxShift) | 467 if (shift > kBrokenDelayMaxShift) |
| 460 shift = kBrokenDelayMaxShift; | 468 shift = kBrokenDelayMaxShift; |
| 461 base::TimeDelta delay = | 469 base::TimeDelta delay = |
| 462 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); | 470 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); |
| 463 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << shift); | 471 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << shift); |
| 464 auto result = broken_alternative_services_.insert( | 472 auto result = broken_alternative_services_.insert( |
| 465 std::make_pair(alternative_service, when)); | 473 std::make_pair(alternative_service, when)); |
| 466 // Return if alternative service is already in expiration queue. | 474 // Return if alternative service is already in expiration queue. |
| 467 if (!result.second) { | 475 if (!result.second) { |
| 468 return; | 476 return; |
| 469 } | 477 } |
| 470 | 478 |
| 471 // If this is the only entry in the list, schedule an expiration task. | 479 // 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. | 480 // Otherwise it will be rescheduled automatically when the pending task runs. |
| 473 if (broken_alternative_services_.size() == 1) { | 481 if (broken_alternative_services_.size() == 1) { |
| 474 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 482 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
| 475 } | 483 } |
| 476 } | 484 } |
| 477 | 485 |
| 478 void HttpServerPropertiesImpl::MarkAlternativeServiceRecentlyBroken( | 486 void HttpServerPropertiesImpl::MarkAlternativeServiceRecentlyBroken( |
| 479 const AlternativeService& alternative_service) { | 487 const AlternativeService& alternative_service) { |
| 480 if (!base::ContainsKey(recently_broken_alternative_services_, | 488 if (recently_broken_alternative_services_.Get(alternative_service) == |
| 481 alternative_service)) | 489 recently_broken_alternative_services_.end()) { |
| 482 recently_broken_alternative_services_[alternative_service] = 1; | 490 recently_broken_alternative_services_.Put(alternative_service, 1); |
| 491 } | |
| 483 } | 492 } |
| 484 | 493 |
| 485 bool HttpServerPropertiesImpl::IsAlternativeServiceBroken( | 494 bool HttpServerPropertiesImpl::IsAlternativeServiceBroken( |
| 486 const AlternativeService& alternative_service) const { | 495 const AlternativeService& alternative_service) const { |
| 487 // Empty host means use host of origin, callers are supposed to substitute. | 496 // Empty host means use host of origin, callers are supposed to substitute. |
| 488 DCHECK(!alternative_service.host.empty()); | 497 DCHECK(!alternative_service.host.empty()); |
| 489 return base::ContainsKey(broken_alternative_services_, alternative_service); | 498 return base::ContainsKey(broken_alternative_services_, alternative_service); |
| 490 } | 499 } |
| 491 | 500 |
| 492 bool HttpServerPropertiesImpl::WasAlternativeServiceRecentlyBroken( | 501 bool HttpServerPropertiesImpl::WasAlternativeServiceRecentlyBroken( |
| 493 const AlternativeService& alternative_service) { | 502 const AlternativeService& alternative_service) { |
| 494 if (alternative_service.protocol == kProtoUnknown) | 503 if (alternative_service.protocol == kProtoUnknown) |
| 495 return false; | 504 return false; |
| 496 return base::ContainsKey(recently_broken_alternative_services_, | 505 auto it = recently_broken_alternative_services_.Get(alternative_service); |
| 497 alternative_service); | 506 |
| 507 return !(it == recently_broken_alternative_services_.end()); | |
|
Ryan Hamilton
2017/04/05 03:34:34
can you simplify this by:
return foo.Get() != foo
Zhongyi Shi
2017/04/06 21:37:13
Done.
| |
| 498 } | 508 } |
| 499 | 509 |
| 500 void HttpServerPropertiesImpl::ConfirmAlternativeService( | 510 void HttpServerPropertiesImpl::ConfirmAlternativeService( |
| 501 const AlternativeService& alternative_service) { | 511 const AlternativeService& alternative_service) { |
| 502 if (alternative_service.protocol == kProtoUnknown) | 512 if (alternative_service.protocol == kProtoUnknown) |
| 503 return; | 513 return; |
| 504 broken_alternative_services_.erase(alternative_service); | 514 broken_alternative_services_.erase(alternative_service); |
| 505 recently_broken_alternative_services_.erase(alternative_service); | 515 auto it = recently_broken_alternative_services_.Get(alternative_service); |
| 516 if (it != recently_broken_alternative_services_.end()) { | |
| 517 recently_broken_alternative_services_.Erase(it); | |
| 518 } | |
| 506 } | 519 } |
| 507 | 520 |
| 508 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() | 521 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() |
| 509 const { | 522 const { |
| 510 return alternative_service_map_; | 523 return alternative_service_map_; |
| 511 } | 524 } |
| 512 | 525 |
| 513 std::unique_ptr<base::Value> | 526 std::unique_ptr<base::Value> |
| 514 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() const { | 527 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() const { |
| 515 std::unique_ptr<base::ListValue> dict_list(new base::ListValue); | 528 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(); | 764 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 752 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 765 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 753 FROM_HERE, | 766 FROM_HERE, |
| 754 base::Bind( | 767 base::Bind( |
| 755 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 768 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 756 weak_ptr_factory_.GetWeakPtr()), | 769 weak_ptr_factory_.GetWeakPtr()), |
| 757 delay); | 770 delay); |
| 758 } | 771 } |
| 759 | 772 |
| 760 } // namespace net | 773 } // namespace net |
| OLD | NEW |