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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 scoped_ptr<DnsSocketPool> socket_pool, | 82 scoped_ptr<DnsSocketPool> socket_pool, |
83 const RandIntCallback& rand_int_callback, | 83 const RandIntCallback& rand_int_callback, |
84 NetLog* net_log) | 84 NetLog* net_log) |
85 : config_(config), | 85 : config_(config), |
86 socket_pool_(socket_pool.Pass()), | 86 socket_pool_(socket_pool.Pass()), |
87 rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)), | 87 rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)), |
88 net_log_(net_log), | 88 net_log_(net_log), |
89 server_index_(0) { | 89 server_index_(0) { |
90 socket_pool_->Initialize(&config_.nameservers, net_log); | 90 socket_pool_->Initialize(&config_.nameservers, net_log); |
91 UMA_HISTOGRAM_CUSTOM_COUNTS( | 91 UMA_HISTOGRAM_CUSTOM_COUNTS( |
92 "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 10); | 92 "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 11); |
93 for (size_t i = 0; i < config_.nameservers.size(); ++i) { | 93 for (size_t i = 0; i < config_.nameservers.size(); ++i) { |
94 server_stats_.push_back(new ServerStats(config_.timeout, | 94 server_stats_.push_back(new ServerStats(config_.timeout, |
95 rtt_buckets_.Pointer())); | 95 rtt_buckets_.Pointer())); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 DnsSession::~DnsSession() { | 99 DnsSession::~DnsSession() { |
100 RecordServerStats(); | 100 RecordServerStats(); |
101 } | 101 } |
102 | 102 |
(...skipping 29 matching lines...) Expand all Loading... |
132 index = (index + 1) % config_.nameservers.size(); | 132 index = (index + 1) % config_.nameservers.size(); |
133 } while (index != server_index); | 133 } while (index != server_index); |
134 | 134 |
135 // If we are here it means that there are no successful servers, so we have | 135 // If we are here it means that there are no successful servers, so we have |
136 // to use one that has failed oldest. | 136 // to use one that has failed oldest. |
137 return oldest_server_failure_index; | 137 return oldest_server_failure_index; |
138 } | 138 } |
139 | 139 |
140 void DnsSession::RecordServerFailure(unsigned server_index) { | 140 void DnsSession::RecordServerFailure(unsigned server_index) { |
141 UMA_HISTOGRAM_CUSTOM_COUNTS( | 141 UMA_HISTOGRAM_CUSTOM_COUNTS( |
142 "AsyncDNS.ServerFailureIndex", server_index, 0, 10, 10); | 142 "AsyncDNS.ServerFailureIndex", server_index, 0, 10, 11); |
143 ++(server_stats_[server_index]->last_failure_count); | 143 ++(server_stats_[server_index]->last_failure_count); |
144 server_stats_[server_index]->last_failure = base::Time::Now(); | 144 server_stats_[server_index]->last_failure = base::Time::Now(); |
145 } | 145 } |
146 | 146 |
147 void DnsSession::RecordServerSuccess(unsigned server_index) { | 147 void DnsSession::RecordServerSuccess(unsigned server_index) { |
148 if (server_stats_[server_index]->last_success.is_null()) { | 148 if (server_stats_[server_index]->last_success.is_null()) { |
149 UMA_HISTOGRAM_COUNTS_100("AsyncDNS.ServerFailuresAfterNetworkChange", | 149 UMA_HISTOGRAM_COUNTS_100("AsyncDNS.ServerFailuresAfterNetworkChange", |
150 server_stats_[server_index]->last_failure_count); | 150 server_stats_[server_index]->last_failure_count); |
151 } else { | 151 } else { |
152 UMA_HISTOGRAM_COUNTS_100("AsyncDNS.ServerFailuresBeforeSuccess", | 152 UMA_HISTOGRAM_COUNTS_100("AsyncDNS.ServerFailuresBeforeSuccess", |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); | 289 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); |
290 | 290 |
291 // The timeout still doubles every full round. | 291 // The timeout still doubles every full round. |
292 unsigned num_backoffs = attempt / config_.nameservers.size(); | 292 unsigned num_backoffs = attempt / config_.nameservers.size(); |
293 | 293 |
294 return std::min(timeout * (1 << num_backoffs), | 294 return std::min(timeout * (1 << num_backoffs), |
295 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); | 295 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); |
296 } | 296 } |
297 | 297 |
298 } // namespace net | 298 } // namespace net |
OLD | NEW |