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 ~ 2 days. | |
|
Ryan Hamilton
2016/11/03 16:16:22
nit: I'm not sure what this comment means? Perhaps
Bence
2016/11/07 20:17:24
Done.
| |
| 26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; | 27 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; |
| 28 const int kBrokenDelayMaxShift = 9; | |
| 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 ++recently_broken_alternative_services_[alternative_service]; |
| 478 int shift = recently_broken_alternative_services_[alternative_service] - 1; | |
|
Zhongyi Shi
2016/11/03 15:59:37
typo here?
Since you're directly retrieving shift
Bence
2016/11/07 20:17:24
Indeed prefix increment returns new value. And |c
| |
| 479 if (shift > kBrokenDelayMaxShift) | |
| 480 shift = kBrokenDelayMaxShift; | |
| 476 base::TimeDelta delay = | 481 base::TimeDelta delay = |
| 477 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); | 482 base::TimeDelta::FromSeconds(kBrokenAlternativeProtocolDelaySecs); |
| 478 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 483 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << shift); |
| 479 auto result = broken_alternative_services_.insert( | 484 auto result = broken_alternative_services_.insert( |
| 480 std::make_pair(alternative_service, when)); | 485 std::make_pair(alternative_service, when)); |
| 481 // Return if alternative service is already in expiration queue. | 486 // Return if alternative service is already in expiration queue. |
| 482 if (!result.second) { | 487 if (!result.second) { |
| 483 return; | 488 return; |
| 484 } | 489 } |
| 485 | 490 |
| 486 // If this is the only entry in the list, schedule an expiration task. | 491 // If this is the only entry in the list, schedule an expiration task. |
| 487 // Otherwise it will be rescheduled automatically when the pending task runs. | 492 // Otherwise it will be rescheduled automatically when the pending task runs. |
| 488 if (broken_alternative_services_.size() == 1) { | 493 if (broken_alternative_services_.size() == 1) { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 804 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 800 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 805 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 801 FROM_HERE, | 806 FROM_HERE, |
| 802 base::Bind( | 807 base::Bind( |
| 803 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 808 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 804 weak_ptr_factory_.GetWeakPtr()), | 809 weak_ptr_factory_.GetWeakPtr()), |
| 805 delay); | 810 delay); |
| 806 } | 811 } |
| 807 | 812 |
| 808 } // namespace net | 813 } // namespace net |
| OLD | NEW |