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 #ifndef NET_DNS_HOST_RESOLVER_IMPL_H_ | 5 #ifndef NET_DNS_HOST_RESOLVER_IMPL_H_ |
6 #define NET_DNS_HOST_RESOLVER_IMPL_H_ | 6 #define NET_DNS_HOST_RESOLVER_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 // HostResolver methods: | 133 // HostResolver methods: |
134 int Resolve(const RequestInfo& info, | 134 int Resolve(const RequestInfo& info, |
135 RequestPriority priority, | 135 RequestPriority priority, |
136 AddressList* addresses, | 136 AddressList* addresses, |
137 const CompletionCallback& callback, | 137 const CompletionCallback& callback, |
138 RequestHandle* out_req, | 138 RequestHandle* out_req, |
139 const BoundNetLog& source_net_log) override; | 139 const BoundNetLog& source_net_log) override; |
140 int ResolveFromCache(const RequestInfo& info, | 140 int ResolveFromCache(const RequestInfo& info, |
141 AddressList* addresses, | 141 AddressList* addresses, |
142 const BoundNetLog& source_net_log) override; | 142 const BoundNetLog& source_net_log) override; |
143 int ResolveStaleFromCache(const RequestInfo& info, | |
144 AddressList* addresses, | |
145 HostCache::EntryStaleness* stale_info, | |
146 const BoundNetLog& source_net_log) override; | |
143 void CancelRequest(RequestHandle req) override; | 147 void CancelRequest(RequestHandle req) override; |
144 void SetDnsClientEnabled(bool enabled) override; | 148 void SetDnsClientEnabled(bool enabled) override; |
145 HostCache* GetHostCache() override; | 149 HostCache* GetHostCache() override; |
146 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; | 150 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; |
147 | 151 |
148 void set_proc_params_for_test(const ProcTaskParams& proc_params) { | 152 void set_proc_params_for_test(const ProcTaskParams& proc_params) { |
149 proc_params_ = proc_params; | 153 proc_params_ = proc_params; |
150 } | 154 } |
151 | 155 |
152 private: | 156 private: |
153 friend class HostResolverImplTest; | 157 friend class HostResolverImplTest; |
154 class Job; | 158 class Job; |
155 class ProcTask; | 159 class ProcTask; |
156 class LoopbackProbeJob; | 160 class LoopbackProbeJob; |
157 class DnsTask; | 161 class DnsTask; |
158 class Request; | 162 class Request; |
159 typedef HostCache::Key Key; | 163 typedef HostCache::Key Key; |
160 typedef std::map<Key, Job*> JobMap; | 164 typedef std::map<Key, Job*> JobMap; |
161 | 165 |
162 // Number of consecutive failures of DnsTask (with successful fallback to | 166 // Number of consecutive failures of DnsTask (with successful fallback to |
163 // ProcTask) before the DnsClient is disabled until the next DNS change. | 167 // ProcTask) before the DnsClient is disabled until the next DNS change. |
164 static const unsigned kMaximumDnsFailures; | 168 static const unsigned kMaximumDnsFailures; |
165 | 169 |
166 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP | 170 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP |
167 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, | 171 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, |
168 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is | 172 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is |
169 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and | 173 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and |
170 // HOSTS and is not localhost. | 174 // HOSTS and is not localhost. |
Randy Smith (Not in Mondays)
2016/05/04 19:46:59
nit: Update with comment about extra argument?
(E
Julia Tuttle
2016/05/05 15:42:54
Done.
| |
171 int ResolveHelper(const Key& key, | 175 int ResolveHelper(const Key& key, |
172 const RequestInfo& info, | 176 const RequestInfo& info, |
173 const IPAddress* ip_address, | 177 const IPAddress* ip_address, |
174 AddressList* addresses, | 178 AddressList* addresses, |
179 HostCache::EntryStaleness* stale_info, | |
175 const BoundNetLog& request_net_log); | 180 const BoundNetLog& request_net_log); |
176 | 181 |
177 // Tries to resolve |key| as an IP, returns true and sets |net_error| if | 182 // Tries to resolve |key| as an IP, returns true and sets |net_error| if |
178 // succeeds, returns false otherwise. | 183 // succeeds, returns false otherwise. |
179 bool ResolveAsIP(const Key& key, | 184 bool ResolveAsIP(const Key& key, |
180 const RequestInfo& info, | 185 const RequestInfo& info, |
181 const IPAddress* ip_address, | 186 const IPAddress* ip_address, |
182 int* net_error, | 187 int* net_error, |
183 AddressList* addresses); | 188 AddressList* addresses); |
184 | 189 |
185 // If |key| is not found in cache returns false, otherwise returns | 190 // If |key| is not found in cache returns false, otherwise returns |
186 // true, sets |net_error| to the cached error code and fills |addresses| | 191 // true, sets |net_error| to the cached error code and fills |addresses| |
187 // if it is a positive entry. | 192 // if it is a positive entry. |
Randy Smith (Not in Mondays)
2016/05/04 19:46:59
Ditto comment about extra argument?
Julia Tuttle
2016/05/05 15:42:54
Done.
| |
188 bool ServeFromCache(const Key& key, | 193 bool ServeFromCache(const Key& key, |
189 const RequestInfo& info, | 194 const RequestInfo& info, |
190 int* net_error, | 195 int* net_error, |
191 AddressList* addresses); | 196 AddressList* addresses, |
197 HostCache::EntryStaleness* stale_info); | |
192 | 198 |
193 // If we have a DnsClient with a valid DnsConfig, and |key| is found in the | 199 // If we have a DnsClient with a valid DnsConfig, and |key| is found in the |
194 // HOSTS file, returns true and fills |addresses|. Otherwise returns false. | 200 // HOSTS file, returns true and fills |addresses|. Otherwise returns false. |
195 bool ServeFromHosts(const Key& key, | 201 bool ServeFromHosts(const Key& key, |
196 const RequestInfo& info, | 202 const RequestInfo& info, |
197 AddressList* addresses); | 203 AddressList* addresses); |
198 | 204 |
199 // If |key| is for a localhost name (RFC 6761), returns true and fills | 205 // If |key| is for a localhost name (RFC 6761), returns true and fills |
200 // |addresses| with the loopback IP. Otherwise returns false. | 206 // |addresses| with the loopback IP. Otherwise returns false. |
201 bool ServeLocalhost(const Key& key, | 207 bool ServeLocalhost(const Key& key, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 // This function is only exposed so it can be unit-tested. | 330 // This function is only exposed so it can be unit-tested. |
325 // TODO(tfarina): It would be better to change the tests so this function | 331 // TODO(tfarina): It would be better to change the tests so this function |
326 // gets exercised indirectly through HostResolverImpl. | 332 // gets exercised indirectly through HostResolverImpl. |
327 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, | 333 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, |
328 uint16_t port, | 334 uint16_t port, |
329 AddressList* address_list); | 335 AddressList* address_list); |
330 | 336 |
331 } // namespace net | 337 } // namespace net |
332 | 338 |
333 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ | 339 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ |
OLD | NEW |