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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months 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_client.cc ('k') | net/dns/dns_session_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 <stdint.h> 7 #include <stdint.h>
8
9 #include <limits> 8 #include <limits>
9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/metrics/sample_vector.h" 15 #include "base/metrics/sample_vector.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "net/base/ip_endpoint.h" 19 #include "net/base/ip_endpoint.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 base::LazyInstance<DnsSession::RttBuckets>::Leaky DnsSession::rtt_buckets_ = 71 base::LazyInstance<DnsSession::RttBuckets>::Leaky DnsSession::rtt_buckets_ =
72 LAZY_INSTANCE_INITIALIZER; 72 LAZY_INSTANCE_INITIALIZER;
73 73
74 DnsSession::RttBuckets::RttBuckets() : base::BucketRanges(kRTTBucketCount + 1) { 74 DnsSession::RttBuckets::RttBuckets() : base::BucketRanges(kRTTBucketCount + 1) {
75 base::Histogram::InitializeBucketRanges(1, 5000, this); 75 base::Histogram::InitializeBucketRanges(1, 5000, this);
76 } 76 }
77 77
78 DnsSession::SocketLease::SocketLease(scoped_refptr<DnsSession> session, 78 DnsSession::SocketLease::SocketLease(scoped_refptr<DnsSession> session,
79 unsigned server_index, 79 unsigned server_index,
80 scoped_ptr<DatagramClientSocket> socket) 80 scoped_ptr<DatagramClientSocket> socket)
81 : session_(session), server_index_(server_index), socket_(socket.Pass()) {} 81 : session_(session),
82 server_index_(server_index),
83 socket_(std::move(socket)) {}
82 84
83 DnsSession::SocketLease::~SocketLease() { 85 DnsSession::SocketLease::~SocketLease() {
84 session_->FreeSocket(server_index_, socket_.Pass()); 86 session_->FreeSocket(server_index_, std::move(socket_));
85 } 87 }
86 88
87 DnsSession::DnsSession(const DnsConfig& config, 89 DnsSession::DnsSession(const DnsConfig& config,
88 scoped_ptr<DnsSocketPool> socket_pool, 90 scoped_ptr<DnsSocketPool> socket_pool,
89 const RandIntCallback& rand_int_callback, 91 const RandIntCallback& rand_int_callback,
90 NetLog* net_log) 92 NetLog* net_log)
91 : config_(config), 93 : config_(config),
92 socket_pool_(socket_pool.Pass()), 94 socket_pool_(std::move(socket_pool)),
93 rand_callback_(base::Bind(rand_int_callback, 95 rand_callback_(base::Bind(rand_int_callback,
94 0, 96 0,
95 std::numeric_limits<uint16_t>::max())), 97 std::numeric_limits<uint16_t>::max())),
96 net_log_(net_log), 98 net_log_(net_log),
97 server_index_(0) { 99 server_index_(0) {
98 socket_pool_->Initialize(&config_.nameservers, net_log); 100 socket_pool_->Initialize(&config_.nameservers, net_log);
99 UMA_HISTOGRAM_CUSTOM_COUNTS( 101 UMA_HISTOGRAM_CUSTOM_COUNTS(
100 "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 11); 102 "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 11);
101 for (size_t i = 0; i < config_.nameservers.size(); ++i) { 103 for (size_t i = 0; i < config_.nameservers.size(); ++i) {
102 server_stats_.push_back(make_scoped_ptr( 104 server_stats_.push_back(make_scoped_ptr(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 unsigned server_index, const NetLog::Source& source) { 234 unsigned server_index, const NetLog::Source& source) {
233 scoped_ptr<DatagramClientSocket> socket; 235 scoped_ptr<DatagramClientSocket> socket;
234 236
235 socket = socket_pool_->AllocateSocket(server_index); 237 socket = socket_pool_->AllocateSocket(server_index);
236 if (!socket.get()) 238 if (!socket.get())
237 return scoped_ptr<SocketLease>(); 239 return scoped_ptr<SocketLease>();
238 240
239 socket->NetLog().BeginEvent(NetLog::TYPE_SOCKET_IN_USE, 241 socket->NetLog().BeginEvent(NetLog::TYPE_SOCKET_IN_USE,
240 source.ToEventParametersCallback()); 242 source.ToEventParametersCallback());
241 243
242 SocketLease* lease = new SocketLease(this, server_index, socket.Pass()); 244 SocketLease* lease = new SocketLease(this, server_index, std::move(socket));
243 return scoped_ptr<SocketLease>(lease); 245 return scoped_ptr<SocketLease>(lease);
244 } 246 }
245 247
246 scoped_ptr<StreamSocket> DnsSession::CreateTCPSocket( 248 scoped_ptr<StreamSocket> DnsSession::CreateTCPSocket(
247 unsigned server_index, const NetLog::Source& source) { 249 unsigned server_index, const NetLog::Source& source) {
248 return socket_pool_->CreateTCPSocket(server_index, source); 250 return socket_pool_->CreateTCPSocket(server_index, source);
249 } 251 }
250 252
251 // Release a socket. 253 // Release a socket.
252 void DnsSession::FreeSocket(unsigned server_index, 254 void DnsSession::FreeSocket(unsigned server_index,
253 scoped_ptr<DatagramClientSocket> socket) { 255 scoped_ptr<DatagramClientSocket> socket) {
254 DCHECK(socket.get()); 256 DCHECK(socket.get());
255 257
256 socket->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE); 258 socket->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE);
257 259
258 socket_pool_->FreeSocket(server_index, socket.Pass()); 260 socket_pool_->FreeSocket(server_index, std::move(socket));
259 } 261 }
260 262
261 base::TimeDelta DnsSession::NextTimeoutFromJacobson(unsigned server_index, 263 base::TimeDelta DnsSession::NextTimeoutFromJacobson(unsigned server_index,
262 int attempt) { 264 int attempt) {
263 DCHECK_LT(server_index, server_stats_.size()); 265 DCHECK_LT(server_index, server_stats_.size());
264 266
265 base::TimeDelta timeout = server_stats_[server_index]->rtt_estimate + 267 base::TimeDelta timeout = server_stats_[server_index]->rtt_estimate +
266 4 * server_stats_[server_index]->rtt_deviation; 268 4 * server_stats_[server_index]->rtt_deviation;
267 269
268 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); 270 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs));
(...skipping 30 matching lines...) Expand all
299 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); 301 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs));
300 302
301 // The timeout still doubles every full round. 303 // The timeout still doubles every full round.
302 unsigned num_backoffs = attempt / config_.nameservers.size(); 304 unsigned num_backoffs = attempt / config_.nameservers.size();
303 305
304 return std::min(timeout * (1 << num_backoffs), 306 return std::min(timeout * (1 << num_backoffs),
305 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); 307 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs));
306 } 308 }
307 309
308 } // namespace net 310 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_client.cc ('k') | net/dns/dns_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698