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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // NetworkChangeNotifier. | 131 // NetworkChangeNotifier. |
132 void SetDnsClient(std::unique_ptr<DnsClient> dns_client); | 132 void SetDnsClient(std::unique_ptr<DnsClient> dns_client); |
133 | 133 |
134 // HostResolver methods: | 134 // HostResolver methods: |
135 int Resolve(const RequestInfo& info, | 135 int Resolve(const RequestInfo& info, |
136 RequestPriority priority, | 136 RequestPriority priority, |
137 AddressList* addresses, | 137 AddressList* addresses, |
138 const CompletionCallback& callback, | 138 const CompletionCallback& callback, |
139 RequestHandle* out_req, | 139 RequestHandle* out_req, |
140 const BoundNetLog& source_net_log) override; | 140 const BoundNetLog& source_net_log) override; |
| 141 void ChangeRequestPriority(RequestHandle req, |
| 142 RequestPriority priority) override; |
| 143 void CancelRequest(RequestHandle req) override; |
141 int ResolveFromCache(const RequestInfo& info, | 144 int ResolveFromCache(const RequestInfo& info, |
142 AddressList* addresses, | 145 AddressList* addresses, |
143 const BoundNetLog& source_net_log) override; | 146 const BoundNetLog& source_net_log) override; |
144 void ChangeRequestPriority(RequestHandle req, | |
145 RequestPriority priority) override; | |
146 void CancelRequest(RequestHandle req) override; | |
147 void SetDnsClientEnabled(bool enabled) override; | 147 void SetDnsClientEnabled(bool enabled) override; |
148 HostCache* GetHostCache() override; | 148 HostCache* GetHostCache() override; |
149 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; | 149 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; |
150 | 150 |
| 151 // Like |ResolveFromCache()|, but can return a stale result if the |
| 152 // implementation supports it. Fills in |*stale_info| if a response is |
| 153 // returned to indicate how stale (or not) it is. |
| 154 int ResolveStaleFromCache(const RequestInfo& info, |
| 155 AddressList* addresses, |
| 156 HostCache::EntryStaleness* stale_info, |
| 157 const BoundNetLog& source_net_log); |
| 158 |
151 void set_proc_params_for_test(const ProcTaskParams& proc_params) { | 159 void set_proc_params_for_test(const ProcTaskParams& proc_params) { |
152 proc_params_ = proc_params; | 160 proc_params_ = proc_params; |
153 } | 161 } |
154 | 162 |
155 protected: | 163 protected: |
156 // Just like the public constructor, but allows the task runner used for | 164 // Just like the public constructor, but allows the task runner used for |
157 // blocking tasks to be specified. Intended for testing only. | 165 // blocking tasks to be specified. Intended for testing only. |
158 HostResolverImpl(const Options& options, | 166 HostResolverImpl(const Options& options, |
159 NetLog* net_log, | 167 NetLog* net_log, |
160 scoped_refptr<base::TaskRunner> worker_task_runner); | 168 scoped_refptr<base::TaskRunner> worker_task_runner); |
(...skipping 13 matching lines...) Expand all Loading... |
174 | 182 |
175 // Number of consecutive failures of DnsTask (with successful fallback to | 183 // Number of consecutive failures of DnsTask (with successful fallback to |
176 // ProcTask) before the DnsClient is disabled until the next DNS change. | 184 // ProcTask) before the DnsClient is disabled until the next DNS change. |
177 static const unsigned kMaximumDnsFailures; | 185 static const unsigned kMaximumDnsFailures; |
178 | 186 |
179 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP | 187 // Helper used by |Resolve()| and |ResolveFromCache()|. Performs IP |
180 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, | 188 // literal, cache and HOSTS lookup (if enabled), returns OK if successful, |
181 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is | 189 // ERR_NAME_NOT_RESOLVED if either hostname is invalid or IP literal is |
182 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and | 190 // incompatible, ERR_DNS_CACHE_MISS if entry was not found in cache and |
183 // HOSTS and is not localhost. | 191 // HOSTS and is not localhost. |
| 192 // |
| 193 // If |allow_stale| is true, then stale cache entries can be returned. |
| 194 // |stale_info| must be non-null, and will be filled in with details of the |
| 195 // entry's staleness (if an entry is returned). |
| 196 // |
| 197 // If |allow_stale| is false, then stale cache entries will not be returned, |
| 198 // and |stale_info| must be null. |
184 int ResolveHelper(const Key& key, | 199 int ResolveHelper(const Key& key, |
185 const RequestInfo& info, | 200 const RequestInfo& info, |
186 const IPAddress* ip_address, | 201 const IPAddress* ip_address, |
187 AddressList* addresses, | 202 AddressList* addresses, |
| 203 bool allow_stale, |
| 204 HostCache::EntryStaleness* stale_info, |
188 const BoundNetLog& request_net_log); | 205 const BoundNetLog& request_net_log); |
189 | 206 |
190 // Tries to resolve |key| as an IP, returns true and sets |net_error| if | 207 // Tries to resolve |key| as an IP, returns true and sets |net_error| if |
191 // succeeds, returns false otherwise. | 208 // succeeds, returns false otherwise. |
192 bool ResolveAsIP(const Key& key, | 209 bool ResolveAsIP(const Key& key, |
193 const RequestInfo& info, | 210 const RequestInfo& info, |
194 const IPAddress* ip_address, | 211 const IPAddress* ip_address, |
195 int* net_error, | 212 int* net_error, |
196 AddressList* addresses); | 213 AddressList* addresses); |
197 | 214 |
198 // If |key| is not found in cache returns false, otherwise returns | 215 // If |key| is not found in cache returns false, otherwise returns |
199 // true, sets |net_error| to the cached error code and fills |addresses| | 216 // true, sets |net_error| to the cached error code and fills |addresses| |
200 // if it is a positive entry. | 217 // if it is a positive entry. |
| 218 // |
| 219 // If |allow_stale| is true, then stale cache entries can be returned. |
| 220 // |stale_info| must be non-null, and will be filled in with details of the |
| 221 // entry's staleness (if an entry is returned). |
| 222 // |
| 223 // If |allow_stale| is false, then stale cache entries will not be returned, |
| 224 // and |stale_info| must be null. |
201 bool ServeFromCache(const Key& key, | 225 bool ServeFromCache(const Key& key, |
202 const RequestInfo& info, | 226 const RequestInfo& info, |
203 int* net_error, | 227 int* net_error, |
204 AddressList* addresses); | 228 AddressList* addresses, |
| 229 bool allow_stale, |
| 230 HostCache::EntryStaleness* stale_info); |
205 | 231 |
206 // If we have a DnsClient with a valid DnsConfig, and |key| is found in the | 232 // If we have a DnsClient with a valid DnsConfig, and |key| is found in the |
207 // HOSTS file, returns true and fills |addresses|. Otherwise returns false. | 233 // HOSTS file, returns true and fills |addresses|. Otherwise returns false. |
208 bool ServeFromHosts(const Key& key, | 234 bool ServeFromHosts(const Key& key, |
209 const RequestInfo& info, | 235 const RequestInfo& info, |
210 AddressList* addresses); | 236 AddressList* addresses); |
211 | 237 |
212 // If |key| is for a localhost name (RFC 6761), returns true and fills | 238 // If |key| is for a localhost name (RFC 6761), returns true and fills |
213 // |addresses| with the loopback IP. Otherwise returns false. | 239 // |addresses| with the loopback IP. Otherwise returns false. |
214 bool ServeLocalhost(const Key& key, | 240 bool ServeLocalhost(const Key& key, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // This function is only exposed so it can be unit-tested. | 368 // This function is only exposed so it can be unit-tested. |
343 // TODO(tfarina): It would be better to change the tests so this function | 369 // TODO(tfarina): It would be better to change the tests so this function |
344 // gets exercised indirectly through HostResolverImpl. | 370 // gets exercised indirectly through HostResolverImpl. |
345 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, | 371 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, |
346 uint16_t port, | 372 uint16_t port, |
347 AddressList* address_list); | 373 AddressList* address_list); |
348 | 374 |
349 } // namespace net | 375 } // namespace net |
350 | 376 |
351 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ | 377 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ |
OLD | NEW |