| 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/dns/dns_session.h" | 5 #include "net/dns/dns_session.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 unsigned num_backoffs = attempt / config_.nameservers.size(); | 265 unsigned num_backoffs = attempt / config_.nameservers.size(); |
| 266 | 266 |
| 267 return std::min(timeout * (1 << num_backoffs), | 267 return std::min(timeout * (1 << num_backoffs), |
| 268 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); | 268 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 base::TimeDelta DnsSession::NextTimeoutFromHistogram(unsigned server_index, | 271 base::TimeDelta DnsSession::NextTimeoutFromHistogram(unsigned server_index, |
| 272 int attempt) { | 272 int attempt) { |
| 273 DCHECK_LT(server_index, server_stats_.size()); | 273 DCHECK_LT(server_index, server_stats_.size()); |
| 274 | 274 |
| 275 COMPILE_ASSERT(std::numeric_limits<base::HistogramBase::Count>::is_signed, | 275 static_assert(std::numeric_limits<base::HistogramBase::Count>::is_signed, |
| 276 histogram_base_count_assumed_to_be_signed); | 276 "histogram base count assumed to be signed"); |
| 277 | 277 |
| 278 // Use fixed percentile of observed samples. | 278 // Use fixed percentile of observed samples. |
| 279 const base::SampleVector& samples = | 279 const base::SampleVector& samples = |
| 280 *server_stats_[server_index]->rtt_histogram; | 280 *server_stats_[server_index]->rtt_histogram; |
| 281 | 281 |
| 282 base::HistogramBase::Count total = samples.TotalCount(); | 282 base::HistogramBase::Count total = samples.TotalCount(); |
| 283 base::HistogramBase::Count remaining_count = kRTOPercentile * total / 100; | 283 base::HistogramBase::Count remaining_count = kRTOPercentile * total / 100; |
| 284 size_t index = 0; | 284 size_t index = 0; |
| 285 while (remaining_count > 0 && index < rtt_buckets_.Get().size()) { | 285 while (remaining_count > 0 && index < rtt_buckets_.Get().size()) { |
| 286 remaining_count -= samples.GetCountAtIndex(index); | 286 remaining_count -= samples.GetCountAtIndex(index); |
| 287 ++index; | 287 ++index; |
| 288 } | 288 } |
| 289 | 289 |
| 290 base::TimeDelta timeout = | 290 base::TimeDelta timeout = |
| 291 base::TimeDelta::FromMilliseconds(rtt_buckets_.Get().range(index)); | 291 base::TimeDelta::FromMilliseconds(rtt_buckets_.Get().range(index)); |
| 292 | 292 |
| 293 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); | 293 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); |
| 294 | 294 |
| 295 // The timeout still doubles every full round. | 295 // The timeout still doubles every full round. |
| 296 unsigned num_backoffs = attempt / config_.nameservers.size(); | 296 unsigned num_backoffs = attempt / config_.nameservers.size(); |
| 297 | 297 |
| 298 return std::min(timeout * (1 << num_backoffs), | 298 return std::min(timeout * (1 << num_backoffs), |
| 299 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); | 299 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); |
| 300 } | 300 } |
| 301 | 301 |
| 302 } // namespace net | 302 } // namespace net |
| OLD | NEW |