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

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

Issue 1778933002: DNS: Per-network-type and Finch-variable timeouts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove change to gdig. Created 4 years, 9 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_config_service_posix.cc ('k') | net/dns/dns_session.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 #ifndef NET_DNS_DNS_SESSION_H_ 5 #ifndef NET_DNS_DNS_SESSION_H_
6 #define NET_DNS_DNS_SESSION_H_ 6 #define NET_DNS_DNS_SESSION_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
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/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/metrics/bucket_ranges.h" 16 #include "base/metrics/bucket_ranges.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "net/base/net_export.h" 18 #include "net/base/net_export.h"
19 #include "net/base/network_change_notifier.h"
19 #include "net/base/rand_callback.h" 20 #include "net/base/rand_callback.h"
20 #include "net/dns/dns_config_service.h" 21 #include "net/dns/dns_config_service.h"
21 #include "net/dns/dns_socket_pool.h" 22 #include "net/dns/dns_socket_pool.h"
22 23
23 namespace base { 24 namespace base {
24 class BucketRanges; 25 class BucketRanges;
25 class SampleVector; 26 class SampleVector;
26 } 27 }
27 28
28 namespace net { 29 namespace net {
29 30
30 class ClientSocketFactory; 31 class ClientSocketFactory;
31 class DatagramClientSocket; 32 class DatagramClientSocket;
32 class NetLog; 33 class NetLog;
33 class StreamSocket; 34 class StreamSocket;
34 35
35 // Session parameters and state shared between DNS transactions. 36 // Session parameters and state shared between DNS transactions.
36 // Ref-counted so that DnsClient::Request can keep working in absence of 37 // Ref-counted so that DnsClient::Request can keep working in absence of
37 // DnsClient. A DnsSession must be recreated when DnsConfig changes. 38 // DnsClient. A DnsSession must be recreated when DnsConfig changes.
38 class NET_EXPORT_PRIVATE DnsSession 39 class NET_EXPORT_PRIVATE DnsSession
39 : NON_EXPORTED_BASE(public base::RefCounted<DnsSession>) { 40 : NON_EXPORTED_BASE(public base::RefCounted<DnsSession>),
41 public NetworkChangeNotifier::ConnectionTypeObserver {
40 public: 42 public:
41 typedef base::Callback<int()> RandCallback; 43 typedef base::Callback<int()> RandCallback;
42 44
43 class NET_EXPORT_PRIVATE SocketLease { 45 class NET_EXPORT_PRIVATE SocketLease {
44 public: 46 public:
45 SocketLease(scoped_refptr<DnsSession> session, 47 SocketLease(scoped_refptr<DnsSession> session,
46 unsigned server_index, 48 unsigned server_index,
47 scoped_ptr<DatagramClientSocket> socket); 49 scoped_ptr<DatagramClientSocket> socket);
48 ~SocketLease(); 50 ~SocketLease();
49 51
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 scoped_ptr<SocketLease> AllocateSocket(unsigned server_index, 105 scoped_ptr<SocketLease> AllocateSocket(unsigned server_index,
104 const NetLog::Source& source); 106 const NetLog::Source& source);
105 107
106 // Creates a StreamSocket from the factory for a transaction over TCP. These 108 // Creates a StreamSocket from the factory for a transaction over TCP. These
107 // sockets are not pooled. 109 // sockets are not pooled.
108 scoped_ptr<StreamSocket> CreateTCPSocket(unsigned server_index, 110 scoped_ptr<StreamSocket> CreateTCPSocket(unsigned server_index,
109 const NetLog::Source& source); 111 const NetLog::Source& source);
110 112
111 private: 113 private:
112 friend class base::RefCounted<DnsSession>; 114 friend class base::RefCounted<DnsSession>;
113 ~DnsSession(); 115 ~DnsSession() override;
116
117 void UpdateTimeouts(NetworkChangeNotifier::ConnectionType type);
118 void InitializeServerStats();
114 119
115 // Release a socket. 120 // Release a socket.
116 void FreeSocket(unsigned server_index, 121 void FreeSocket(unsigned server_index,
117 scoped_ptr<DatagramClientSocket> socket); 122 scoped_ptr<DatagramClientSocket> socket);
118 123
119 // Return the timeout using the TCP timeout method. 124 // Return the timeout using the TCP timeout method.
120 base::TimeDelta NextTimeoutFromJacobson(unsigned server_index, int attempt); 125 base::TimeDelta NextTimeoutFromJacobson(unsigned server_index, int attempt);
121 126
122 // Compute the timeout using the histogram method. 127 // Compute the timeout using the histogram method.
123 base::TimeDelta NextTimeoutFromHistogram(unsigned server_index, int attempt); 128 base::TimeDelta NextTimeoutFromHistogram(unsigned server_index, int attempt);
124 129
130 // NetworkChangeNotifier::ConnectionTypeObserver:
131 void OnConnectionTypeChanged(
132 NetworkChangeNotifier::ConnectionType type) override;
133
125 const DnsConfig config_; 134 const DnsConfig config_;
126 scoped_ptr<DnsSocketPool> socket_pool_; 135 scoped_ptr<DnsSocketPool> socket_pool_;
127 RandCallback rand_callback_; 136 RandCallback rand_callback_;
128 NetLog* net_log_; 137 NetLog* net_log_;
129 138
130 // Current index into |config_.nameservers| to begin resolution with. 139 // Current index into |config_.nameservers| to begin resolution with.
131 int server_index_; 140 int server_index_;
132 141
142 base::TimeDelta initial_timeout_;
143 base::TimeDelta max_timeout_;
144
133 struct ServerStats; 145 struct ServerStats;
134 146
135 // Track runtime statistics of each DNS server. 147 // Track runtime statistics of each DNS server.
136 std::vector<scoped_ptr<ServerStats>> server_stats_; 148 std::vector<scoped_ptr<ServerStats>> server_stats_;
137 149
138 // Buckets shared for all |ServerStats::rtt_histogram|. 150 // Buckets shared for all |ServerStats::rtt_histogram|.
139 struct RttBuckets : public base::BucketRanges { 151 struct RttBuckets : public base::BucketRanges {
140 RttBuckets(); 152 RttBuckets();
141 }; 153 };
142 static base::LazyInstance<RttBuckets>::Leaky rtt_buckets_; 154 static base::LazyInstance<RttBuckets>::Leaky rtt_buckets_;
143 155
144 DISALLOW_COPY_AND_ASSIGN(DnsSession); 156 DISALLOW_COPY_AND_ASSIGN(DnsSession);
145 }; 157 };
146 158
147 } // namespace net 159 } // namespace net
148 160
149 #endif // NET_DNS_DNS_SESSION_H_ 161 #endif // NET_DNS_DNS_SESSION_H_
OLDNEW
« no previous file with comments | « net/dns/dns_config_service_posix.cc ('k') | net/dns/dns_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698