Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: net/dns/dns_session.cc

Issue 1475803002: Remove kuint16max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint2
Patch Set: cloud print Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/dns_session.h ('k') | net/dns/dns_transaction_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h>
8
9 #include <limits>
10
8 #include "base/bind.h" 11 #include "base/bind.h"
9 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
10 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
11 #include "base/metrics/sample_vector.h" 14 #include "base/metrics/sample_vector.h"
12 #include "base/rand_util.h" 15 #include "base/rand_util.h"
13 #include "base/stl_util.h" 16 #include "base/stl_util.h"
14 #include "base/time/time.h" 17 #include "base/time/time.h"
15 #include "net/base/ip_endpoint.h" 18 #include "net/base/ip_endpoint.h"
16 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
17 #include "net/dns/dns_config_service.h" 20 #include "net/dns/dns_config_service.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 DnsSession::SocketLease::~SocketLease() { 82 DnsSession::SocketLease::~SocketLease() {
80 session_->FreeSocket(server_index_, socket_.Pass()); 83 session_->FreeSocket(server_index_, socket_.Pass());
81 } 84 }
82 85
83 DnsSession::DnsSession(const DnsConfig& config, 86 DnsSession::DnsSession(const DnsConfig& config,
84 scoped_ptr<DnsSocketPool> socket_pool, 87 scoped_ptr<DnsSocketPool> socket_pool,
85 const RandIntCallback& rand_int_callback, 88 const RandIntCallback& rand_int_callback,
86 NetLog* net_log) 89 NetLog* net_log)
87 : config_(config), 90 : config_(config),
88 socket_pool_(socket_pool.Pass()), 91 socket_pool_(socket_pool.Pass()),
89 rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)), 92 rand_callback_(base::Bind(rand_int_callback,
93 0,
94 std::numeric_limits<uint16_t>::max())),
90 net_log_(net_log), 95 net_log_(net_log),
91 server_index_(0) { 96 server_index_(0) {
92 socket_pool_->Initialize(&config_.nameservers, net_log); 97 socket_pool_->Initialize(&config_.nameservers, net_log);
93 UMA_HISTOGRAM_CUSTOM_COUNTS( 98 UMA_HISTOGRAM_CUSTOM_COUNTS(
94 "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 11); 99 "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 11);
95 for (size_t i = 0; i < config_.nameservers.size(); ++i) { 100 for (size_t i = 0; i < config_.nameservers.size(); ++i) {
96 server_stats_.push_back(make_scoped_ptr( 101 server_stats_.push_back(make_scoped_ptr(
97 new ServerStats(config_.timeout, rtt_buckets_.Pointer()))); 102 new ServerStats(config_.timeout, rtt_buckets_.Pointer())));
98 } 103 }
99 } 104 }
100 105
101 DnsSession::~DnsSession() { 106 DnsSession::~DnsSession() {
102 RecordServerStats(); 107 RecordServerStats();
103 } 108 }
104 109
105 uint16 DnsSession::NextQueryId() const { 110 uint16_t DnsSession::NextQueryId() const {
106 return static_cast<uint16>(rand_callback_.Run()); 111 return static_cast<uint16_t>(rand_callback_.Run());
107 } 112 }
108 113
109 unsigned DnsSession::NextFirstServerIndex() { 114 unsigned DnsSession::NextFirstServerIndex() {
110 unsigned index = NextGoodServerIndex(server_index_); 115 unsigned index = NextGoodServerIndex(server_index_);
111 if (config_.rotate) 116 if (config_.rotate)
112 server_index_ = (server_index_ + 1) % config_.nameservers.size(); 117 server_index_ = (server_index_ + 1) % config_.nameservers.size();
113 return index; 118 return index;
114 } 119 }
115 120
116 unsigned DnsSession::NextGoodServerIndex(unsigned server_index) { 121 unsigned DnsSession::NextGoodServerIndex(unsigned server_index) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); 298 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs));
294 299
295 // The timeout still doubles every full round. 300 // The timeout still doubles every full round.
296 unsigned num_backoffs = attempt / config_.nameservers.size(); 301 unsigned num_backoffs = attempt / config_.nameservers.size();
297 302
298 return std::min(timeout * (1 << num_backoffs), 303 return std::min(timeout * (1 << num_backoffs),
299 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); 304 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs));
300 } 305 }
301 306
302 } // namespace net 307 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_session.h ('k') | net/dns/dns_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698