| 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 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 17 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/timer/timer.h" |
| 19 #include "net/base/net_export.h" | 20 #include "net/base/net_export.h" |
| 20 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
| 21 #include "net/dns/host_cache.h" | 22 #include "net/dns/host_cache.h" |
| 22 #include "net/dns/host_resolver.h" | 23 #include "net/dns/host_resolver.h" |
| 23 #include "net/dns/host_resolver_proc.h" | 24 #include "net/dns/host_resolver_proc.h" |
| 24 | 25 |
| 25 namespace net { | 26 namespace net { |
| 26 | 27 |
| 27 class AddressList; | 28 class AddressList; |
| 28 class BoundNetLog; | 29 class BoundNetLog; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; | 147 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; |
| 147 | 148 |
| 148 // Like |ResolveFromCache()|, but can return a stale result if the | 149 // Like |ResolveFromCache()|, but can return a stale result if the |
| 149 // implementation supports it. Fills in |*stale_info| if a response is | 150 // implementation supports it. Fills in |*stale_info| if a response is |
| 150 // returned to indicate how stale (or not) it is. | 151 // returned to indicate how stale (or not) it is. |
| 151 int ResolveStaleFromCache(const RequestInfo& info, | 152 int ResolveStaleFromCache(const RequestInfo& info, |
| 152 AddressList* addresses, | 153 AddressList* addresses, |
| 153 HostCache::EntryStaleness* stale_info, | 154 HostCache::EntryStaleness* stale_info, |
| 154 const BoundNetLog& source_net_log); | 155 const BoundNetLog& source_net_log); |
| 155 | 156 |
| 157 void InitializePersistence( |
| 158 const PersistCallback& persist_callback, |
| 159 std::unique_ptr<const base::Value> old_data) override; |
| 160 |
| 156 void set_proc_params_for_test(const ProcTaskParams& proc_params) { | 161 void set_proc_params_for_test(const ProcTaskParams& proc_params) { |
| 157 proc_params_ = proc_params; | 162 proc_params_ = proc_params; |
| 158 } | 163 } |
| 159 | 164 |
| 160 protected: | 165 protected: |
| 161 // Just like the public constructor, but allows the task runner used for | 166 // Just like the public constructor, but allows the task runner used for |
| 162 // blocking tasks to be specified. Intended for testing only. | 167 // blocking tasks to be specified. Intended for testing only. |
| 163 HostResolverImpl(const Options& options, | 168 HostResolverImpl(const Options& options, |
| 164 NetLog* net_log, | 169 NetLog* net_log, |
| 165 scoped_refptr<base::TaskRunner> worker_task_runner); | 170 scoped_refptr<base::TaskRunner> worker_task_runner); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 292 |
| 288 void UpdateDNSConfig(bool config_changed); | 293 void UpdateDNSConfig(bool config_changed); |
| 289 | 294 |
| 290 // True if have a DnsClient with a valid DnsConfig. | 295 // True if have a DnsClient with a valid DnsConfig. |
| 291 bool HaveDnsConfig() const; | 296 bool HaveDnsConfig() const; |
| 292 | 297 |
| 293 // Called when a host name is successfully resolved and DnsTask was run on it | 298 // Called when a host name is successfully resolved and DnsTask was run on it |
| 294 // and resulted in |net_error|. | 299 // and resulted in |net_error|. |
| 295 void OnDnsTaskResolve(int net_error); | 300 void OnDnsTaskResolve(int net_error); |
| 296 | 301 |
| 302 void SchedulePersist(); |
| 303 void DoPersist(); |
| 304 |
| 305 void ApplyPersistentData(std::unique_ptr<const base::Value>); |
| 306 std::unique_ptr<const base::Value> GetPersistentData(); |
| 307 |
| 297 // Allows the tests to catch slots leaking out of the dispatcher. One | 308 // Allows the tests to catch slots leaking out of the dispatcher. One |
| 298 // HostResolverImpl::Job could occupy multiple PrioritizedDispatcher job | 309 // HostResolverImpl::Job could occupy multiple PrioritizedDispatcher job |
| 299 // slots. | 310 // slots. |
| 300 size_t num_running_dispatcher_jobs_for_tests() const { | 311 size_t num_running_dispatcher_jobs_for_tests() const { |
| 301 return dispatcher_->num_running_jobs(); | 312 return dispatcher_->num_running_jobs(); |
| 302 } | 313 } |
| 303 | 314 |
| 304 // Cache of host resolution results. | 315 // Cache of host resolution results. |
| 305 std::unique_ptr<HostCache> cache_; | 316 std::unique_ptr<HostCache> cache_; |
| 306 | 317 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 HostResolverFlags additional_resolver_flags_; | 354 HostResolverFlags additional_resolver_flags_; |
| 344 | 355 |
| 345 // Allow fallback to ProcTask if DnsTask fails. | 356 // Allow fallback to ProcTask if DnsTask fails. |
| 346 bool fallback_to_proctask_; | 357 bool fallback_to_proctask_; |
| 347 | 358 |
| 348 // Task runner used for DNS lookups using the platform resolver, and other | 359 // Task runner used for DNS lookups using the platform resolver, and other |
| 349 // blocking operations. Usually just the WorkerPool's task runner for slow | 360 // blocking operations. Usually just the WorkerPool's task runner for slow |
| 350 // tasks, but can be overridden for tests. | 361 // tasks, but can be overridden for tests. |
| 351 scoped_refptr<base::TaskRunner> worker_task_runner_; | 362 scoped_refptr<base::TaskRunner> worker_task_runner_; |
| 352 | 363 |
| 364 bool persist_initialized_; |
| 365 PersistCallback persist_callback_; |
| 366 base::OneShotTimer persist_timer_; |
| 367 |
| 353 base::WeakPtrFactory<HostResolverImpl> weak_ptr_factory_; | 368 base::WeakPtrFactory<HostResolverImpl> weak_ptr_factory_; |
| 354 | 369 |
| 355 base::WeakPtrFactory<HostResolverImpl> probe_weak_ptr_factory_; | 370 base::WeakPtrFactory<HostResolverImpl> probe_weak_ptr_factory_; |
| 356 | 371 |
| 357 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); | 372 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); |
| 358 }; | 373 }; |
| 359 | 374 |
| 360 // Resolves a local hostname (such as "localhost" or "localhost6") into | 375 // Resolves a local hostname (such as "localhost" or "localhost6") into |
| 361 // IP endpoints with the given port. Returns true if |host| is a local | 376 // IP endpoints with the given port. Returns true if |host| is a local |
| 362 // hostname and false otherwise. Special IPv6 names (e.g. "localhost6") | 377 // hostname and false otherwise. Special IPv6 names (e.g. "localhost6") |
| 363 // will resolve to an IPv6 address only, whereas other names will | 378 // will resolve to an IPv6 address only, whereas other names will |
| 364 // resolve to both IPv4 and IPv6. | 379 // resolve to both IPv4 and IPv6. |
| 365 // This function is only exposed so it can be unit-tested. | 380 // This function is only exposed so it can be unit-tested. |
| 366 // TODO(tfarina): It would be better to change the tests so this function | 381 // TODO(tfarina): It would be better to change the tests so this function |
| 367 // gets exercised indirectly through HostResolverImpl. | 382 // gets exercised indirectly through HostResolverImpl. |
| 368 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, | 383 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, |
| 369 uint16_t port, | 384 uint16_t port, |
| 370 AddressList* address_list); | 385 AddressList* address_list); |
| 371 | 386 |
| 372 } // namespace net | 387 } // namespace net |
| 373 | 388 |
| 374 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ | 389 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ |
| OLD | NEW |