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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // kBrokenAlternativeProtocolDelaySecs << (kBrokenDelayMaxShift - 1) ~ 2 days. | |
| 26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; | 27 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; |
| 28 const int kBrokenDelayMaxShift = 10; | |
| 27 | 29 |
| 28 } // namespace | 30 } // namespace |
| 29 | 31 |
| 30 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 32 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
| 31 : spdy_servers_map_(SpdyServersMap::NO_AUTO_EVICT), | 33 : spdy_servers_map_(SpdyServersMap::NO_AUTO_EVICT), |
| 32 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), | 34 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), |
| 33 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), | 35 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), |
| 34 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), | 36 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), |
| 35 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT), | 37 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT), |
| 36 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist), | 38 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist), |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 } | 467 } |
| 466 | 468 |
| 467 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( | 469 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( |
| 468 const AlternativeService& alternative_service) { | 470 const AlternativeService& alternative_service) { |
| 469 // Empty host means use host of origin, callers are supposed to substitute. | 471 // Empty host means use host of origin, callers are supposed to substitute. |
| 470 DCHECK(!alternative_service.host.empty()); | 472 DCHECK(!alternative_service.host.empty()); |
| 471 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 473 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 472 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 474 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
| 473 return; | 475 return; |
| 474 } | 476 } |
| 475 int count = ++recently_broken_alternative_services_[alternative_service]; | 477 int& count = recently_broken_alternative_services_[alternative_service]; |
| 478 if (count < kBrokenDelayMaxShift) | |
| 479 ++count; | |
|
Zhongyi Shi
2016/11/02 20:17:58
What if the count >= kBrokenDelayMaxShift? I think
Bence
2016/11/07 20:17:24
Done.
| |
| 476 base::TimeDelta delay = | 480 base::TimeDelta delay = |
| 477 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); | 481 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); |
| 478 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 482 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); |
| 479 auto result = broken_alternative_services_.insert( | 483 auto result = broken_alternative_services_.insert( |
| 480 std::make_pair(alternative_service, when)); | 484 std::make_pair(alternative_service, when)); |
| 481 // Return if alternative service is already in expiration queue. | 485 // Return if alternative service is already in expiration queue. |
| 482 if (!result.second) { | 486 if (!result.second) { |
| 483 return; | 487 return; |
| 484 } | 488 } |
| 485 | 489 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 803 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 800 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 804 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 801 FROM_HERE, | 805 FROM_HERE, |
| 802 base::Bind( | 806 base::Bind( |
| 803 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 807 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 804 weak_ptr_factory_.GetWeakPtr()), | 808 weak_ptr_factory_.GetWeakPtr()), |
| 805 delay); | 809 delay); |
| 806 } | 810 } |
| 807 | 811 |
| 808 } // namespace net | 812 } // namespace net |
| OLD | NEW |