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/log/net_log_event_type.h" |
| 29 #include "net/log/net_log_source.h" |
| 30 #include "net/log/net_log_with_source.h" |
29 #include "net/socket/stream_socket.h" | 31 #include "net/socket/stream_socket.h" |
30 #include "net/udp/datagram_client_socket.h" | 32 #include "net/udp/datagram_client_socket.h" |
31 | 33 |
32 namespace net { | 34 namespace net { |
33 | 35 |
34 namespace { | 36 namespace { |
35 | 37 |
36 // Set min timeout, in case we are talking to a local DNS proxy. | 38 // Set min timeout, in case we are talking to a local DNS proxy. |
37 const unsigned kMinTimeoutMs = 10; | 39 const unsigned kMinTimeoutMs = 10; |
38 | 40 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 base::TimeDelta DnsSession::NextTimeout(unsigned server_index, int attempt) { | 266 base::TimeDelta DnsSession::NextTimeout(unsigned server_index, int attempt) { |
265 // Respect initial timeout (from config or field trial) if it exceeds max. | 267 // Respect initial timeout (from config or field trial) if it exceeds max. |
266 if (initial_timeout_ > max_timeout_) | 268 if (initial_timeout_ > max_timeout_) |
267 return initial_timeout_; | 269 return initial_timeout_; |
268 return NextTimeoutFromHistogram(server_index, attempt); | 270 return NextTimeoutFromHistogram(server_index, attempt); |
269 } | 271 } |
270 | 272 |
271 // Allocate a socket, already connected to the server address. | 273 // Allocate a socket, already connected to the server address. |
272 std::unique_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket( | 274 std::unique_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket( |
273 unsigned server_index, | 275 unsigned server_index, |
274 const NetLog::Source& source) { | 276 const NetLogSource& source) { |
275 std::unique_ptr<DatagramClientSocket> socket; | 277 std::unique_ptr<DatagramClientSocket> socket; |
276 | 278 |
277 socket = socket_pool_->AllocateSocket(server_index); | 279 socket = socket_pool_->AllocateSocket(server_index); |
278 if (!socket.get()) | 280 if (!socket.get()) |
279 return std::unique_ptr<SocketLease>(); | 281 return std::unique_ptr<SocketLease>(); |
280 | 282 |
281 socket->NetLog().BeginEvent(NetLogEventType::SOCKET_IN_USE, | 283 socket->NetLog().BeginEvent(NetLogEventType::SOCKET_IN_USE, |
282 source.ToEventParametersCallback()); | 284 source.ToEventParametersCallback()); |
283 | 285 |
284 SocketLease* lease = new SocketLease(this, server_index, std::move(socket)); | 286 SocketLease* lease = new SocketLease(this, server_index, std::move(socket)); |
285 return std::unique_ptr<SocketLease>(lease); | 287 return std::unique_ptr<SocketLease>(lease); |
286 } | 288 } |
287 | 289 |
288 std::unique_ptr<StreamSocket> DnsSession::CreateTCPSocket( | 290 std::unique_ptr<StreamSocket> DnsSession::CreateTCPSocket( |
289 unsigned server_index, | 291 unsigned server_index, |
290 const NetLog::Source& source) { | 292 const NetLogSource& source) { |
291 return socket_pool_->CreateTCPSocket(server_index, source); | 293 return socket_pool_->CreateTCPSocket(server_index, source); |
292 } | 294 } |
293 | 295 |
294 void DnsSession::ApplyPersistentData(const base::Value& data) {} | 296 void DnsSession::ApplyPersistentData(const base::Value& data) {} |
295 | 297 |
296 std::unique_ptr<const base::Value> DnsSession::GetPersistentData() const { | 298 std::unique_ptr<const base::Value> DnsSession::GetPersistentData() const { |
297 return std::unique_ptr<const base::Value>(); | 299 return std::unique_ptr<const base::Value>(); |
298 } | 300 } |
299 | 301 |
300 // Release a socket. | 302 // Release a socket. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 348 |
347 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); | 349 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); |
348 | 350 |
349 // The timeout still doubles every full round. | 351 // The timeout still doubles every full round. |
350 unsigned num_backoffs = attempt / config_.nameservers.size(); | 352 unsigned num_backoffs = attempt / config_.nameservers.size(); |
351 | 353 |
352 return std::min(timeout * (1 << num_backoffs), max_timeout_); | 354 return std::min(timeout * (1 << num_backoffs), max_timeout_); |
353 } | 355 } |
354 | 356 |
355 } // namespace net | 357 } // namespace net |
OLD | NEW |