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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
18 #include "base/metrics/sample_vector.h" | 18 #include "base/metrics/sample_vector.h" |
19 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/dns/dns_config_service.h" | 25 #include "net/dns/dns_config_service.h" |
26 #include "net/dns/dns_socket_pool.h" | 26 #include "net/dns/dns_socket_pool.h" |
27 #include "net/dns/dns_util.h" | 27 #include "net/dns/dns_util.h" |
| 28 #include "net/log/net_log_event_type.h" |
28 #include "net/socket/stream_socket.h" | 29 #include "net/socket/stream_socket.h" |
29 #include "net/udp/datagram_client_socket.h" | 30 #include "net/udp/datagram_client_socket.h" |
30 | 31 |
31 namespace net { | 32 namespace net { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 // Set min timeout, in case we are talking to a local DNS proxy. | 36 // Set min timeout, in case we are talking to a local DNS proxy. |
36 const unsigned kMinTimeoutMs = 10; | 37 const unsigned kMinTimeoutMs = 10; |
37 | 38 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Allocate a socket, already connected to the server address. | 271 // Allocate a socket, already connected to the server address. |
271 std::unique_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket( | 272 std::unique_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket( |
272 unsigned server_index, | 273 unsigned server_index, |
273 const NetLog::Source& source) { | 274 const NetLog::Source& source) { |
274 std::unique_ptr<DatagramClientSocket> socket; | 275 std::unique_ptr<DatagramClientSocket> socket; |
275 | 276 |
276 socket = socket_pool_->AllocateSocket(server_index); | 277 socket = socket_pool_->AllocateSocket(server_index); |
277 if (!socket.get()) | 278 if (!socket.get()) |
278 return std::unique_ptr<SocketLease>(); | 279 return std::unique_ptr<SocketLease>(); |
279 | 280 |
280 socket->NetLog().BeginEvent(NetLog::TYPE_SOCKET_IN_USE, | 281 socket->NetLog().BeginEvent(NetLogEventType::SOCKET_IN_USE, |
281 source.ToEventParametersCallback()); | 282 source.ToEventParametersCallback()); |
282 | 283 |
283 SocketLease* lease = new SocketLease(this, server_index, std::move(socket)); | 284 SocketLease* lease = new SocketLease(this, server_index, std::move(socket)); |
284 return std::unique_ptr<SocketLease>(lease); | 285 return std::unique_ptr<SocketLease>(lease); |
285 } | 286 } |
286 | 287 |
287 std::unique_ptr<StreamSocket> DnsSession::CreateTCPSocket( | 288 std::unique_ptr<StreamSocket> DnsSession::CreateTCPSocket( |
288 unsigned server_index, | 289 unsigned server_index, |
289 const NetLog::Source& source) { | 290 const NetLog::Source& source) { |
290 return socket_pool_->CreateTCPSocket(server_index, source); | 291 return socket_pool_->CreateTCPSocket(server_index, source); |
291 } | 292 } |
292 | 293 |
293 void DnsSession::ApplyPersistentData(const base::Value& data) {} | 294 void DnsSession::ApplyPersistentData(const base::Value& data) {} |
294 | 295 |
295 std::unique_ptr<const base::Value> DnsSession::GetPersistentData() const { | 296 std::unique_ptr<const base::Value> DnsSession::GetPersistentData() const { |
296 return std::unique_ptr<const base::Value>(); | 297 return std::unique_ptr<const base::Value>(); |
297 } | 298 } |
298 | 299 |
299 // Release a socket. | 300 // Release a socket. |
300 void DnsSession::FreeSocket(unsigned server_index, | 301 void DnsSession::FreeSocket(unsigned server_index, |
301 std::unique_ptr<DatagramClientSocket> socket) { | 302 std::unique_ptr<DatagramClientSocket> socket) { |
302 DCHECK(socket.get()); | 303 DCHECK(socket.get()); |
303 | 304 |
304 socket->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE); | 305 socket->NetLog().EndEvent(NetLogEventType::SOCKET_IN_USE); |
305 | 306 |
306 socket_pool_->FreeSocket(server_index, std::move(socket)); | 307 socket_pool_->FreeSocket(server_index, std::move(socket)); |
307 } | 308 } |
308 | 309 |
309 base::TimeDelta DnsSession::NextTimeoutFromJacobson(unsigned server_index, | 310 base::TimeDelta DnsSession::NextTimeoutFromJacobson(unsigned server_index, |
310 int attempt) { | 311 int attempt) { |
311 DCHECK_LT(server_index, server_stats_.size()); | 312 DCHECK_LT(server_index, server_stats_.size()); |
312 | 313 |
313 base::TimeDelta timeout = server_stats_[server_index]->rtt_estimate + | 314 base::TimeDelta timeout = server_stats_[server_index]->rtt_estimate + |
314 4 * server_stats_[server_index]->rtt_deviation; | 315 4 * server_stats_[server_index]->rtt_deviation; |
(...skipping 30 matching lines...) Expand all Loading... |
345 | 346 |
346 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); | 347 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); |
347 | 348 |
348 // The timeout still doubles every full round. | 349 // The timeout still doubles every full round. |
349 unsigned num_backoffs = attempt / config_.nameservers.size(); | 350 unsigned num_backoffs = attempt / config_.nameservers.size(); |
350 | 351 |
351 return std::min(timeout * (1 << num_backoffs), max_timeout_); | 352 return std::min(timeout * (1 << num_backoffs), max_timeout_); |
352 } | 353 } |
353 | 354 |
354 } // namespace net | 355 } // namespace net |
OLD | NEW |