host_resolver_manager.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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
  3. // found in the LICENSE file.
  4. #ifndef NET_DNS_HOST_RESOLVER_MANAGER_H_
  5. #define NET_DNS_HOST_RESOLVER_MANAGER_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <deque>
  9. #include <map>
  10. #include <memory>
  11. #include <set>
  12. #include <string>
  13. #include <vector>
  14. #include "base/callback.h"
  15. #include "base/callback_helpers.h"
  16. #include "base/memory/raw_ptr.h"
  17. #include "base/memory/scoped_refptr.h"
  18. #include "base/memory/weak_ptr.h"
  19. #include "base/observer_list.h"
  20. #include "base/strings/string_piece.h"
  21. #include "base/time/time.h"
  22. #include "base/timer/timer.h"
  23. #include "net/base/completion_once_callback.h"
  24. #include "net/base/host_port_pair.h"
  25. #include "net/base/network_change_notifier.h"
  26. #include "net/base/network_handle.h"
  27. #include "net/base/network_isolation_key.h"
  28. #include "net/base/prioritized_dispatcher.h"
  29. #include "net/dns/dns_config.h"
  30. #include "net/dns/host_cache.h"
  31. #include "net/dns/host_resolver.h"
  32. #include "net/dns/host_resolver_proc.h"
  33. #include "net/dns/httpssvc_metrics.h"
  34. #include "net/dns/public/dns_config_overrides.h"
  35. #include "net/dns/public/dns_query_type.h"
  36. #include "net/dns/public/secure_dns_mode.h"
  37. #include "net/dns/public/secure_dns_policy.h"
  38. #include "net/dns/resolve_context.h"
  39. #include "net/dns/system_dns_config_change_notifier.h"
  40. #include "net/log/net_log_with_source.h"
  41. #include "third_party/abseil-cpp/absl/types/optional.h"
  42. #include "third_party/abseil-cpp/absl/types/variant.h"
  43. #include "url/gurl.h"
  44. #include "url/scheme_host_port.h"
  45. namespace base {
  46. class TickClock;
  47. } // namespace base
  48. namespace net {
  49. class DnsClient;
  50. class DnsProbeRunner;
  51. class IPAddress;
  52. class MDnsClient;
  53. class MDnsSocketFactory;
  54. class NetLog;
  55. // Scheduler and controller of host resolution requests. Because of the global
  56. // nature of host resolutions, this class is generally expected to be singleton
  57. // within the browser and only be interacted with through per-context
  58. // ContextHostResolver objects (which are themselves generally interacted with
  59. // though the HostResolver interface).
  60. //
  61. // For each hostname that is requested, HostResolver creates a
  62. // HostResolverManager::Job. When this job gets dispatched it creates a task
  63. // (ProcTask for the system resolver or DnsTask for the async resolver) which
  64. // resolves the hostname. If requests for that same host are made during the
  65. // job's lifetime, they are attached to the existing job rather than creating a
  66. // new one. This avoids doing parallel resolves for the same host.
  67. //
  68. // The way these classes fit together is illustrated by:
  69. //
  70. //
  71. // +----------- HostResolverManager ----------+
  72. // | | |
  73. // Job Job Job
  74. // (for host1, fam1) (for host2, fam2) (for hostx, famx)
  75. // / | | / | | / | |
  76. // Request ... Request Request ... Request Request ... Request
  77. // (port1) (port2) (port3) (port4) (port5) (portX)
  78. //
  79. // When a HostResolverManager::Job finishes, the callbacks of each waiting
  80. // request are run on the origin thread.
  81. //
  82. // Thread safety: This class is not threadsafe, and must only be called
  83. // from one thread!
  84. //
  85. // The HostResolverManager enforces limits on the maximum number of concurrent
  86. // threads using PrioritizedDispatcher::Limits.
  87. //
  88. // Jobs are ordered in the queue based on their priority and order of arrival.
  89. class NET_EXPORT HostResolverManager
  90. : public NetworkChangeNotifier::IPAddressObserver,
  91. public NetworkChangeNotifier::ConnectionTypeObserver,
  92. public SystemDnsConfigChangeNotifier::Observer {
  93. public:
  94. using MdnsListener = HostResolver::MdnsListener;
  95. using ResolveHostParameters = HostResolver::ResolveHostParameters;
  96. using PassKey = base::PassKey<HostResolverManager>;
  97. // Creates a HostResolver as specified by |options|. Blocking tasks are run in
  98. // ThreadPool.
  99. //
  100. // If Options.enable_caching is true, a cache is created using
  101. // HostCache::CreateDefaultCache(). Otherwise no cache is used.
  102. //
  103. // Options.GetDispatcherLimits() determines the maximum number of jobs that
  104. // the resolver will run at once. This upper-bounds the total number of
  105. // outstanding DNS transactions (not counting retransmissions and retries).
  106. //
  107. // |net_log| and |system_dns_config_notifier|, if non-null, must remain valid
  108. // for the life of the HostResolverManager.
  109. HostResolverManager(const HostResolver::ManagerOptions& options,
  110. SystemDnsConfigChangeNotifier* system_dns_config_notifier,
  111. NetLog* net_log);
  112. HostResolverManager(const HostResolverManager&) = delete;
  113. HostResolverManager& operator=(const HostResolverManager&) = delete;
  114. // If any completion callbacks are pending when the resolver is destroyed,
  115. // the host resolutions are cancelled, and the completion callbacks will not
  116. // be called.
  117. ~HostResolverManager() override;
  118. // Same as constructor above, but binds the HostResolverManager to
  119. // `target_network`: all DNS requests will be performed for `target_network`
  120. // only, requests will fail if `target_network` disconnects. Only
  121. // HostResolvers bound to the same network will be able to use this.
  122. // Only implemented for Android.
  123. static std::unique_ptr<HostResolverManager>
  124. CreateNetworkBoundHostResolverManager(
  125. const HostResolver::ManagerOptions& options,
  126. handles::NetworkHandle target_network,
  127. NetLog* net_log);
  128. // |resolve_context| must have already been added (via
  129. // RegisterResolveContext()). If |optional_parameters| specifies any cache
  130. // usage other than LOCAL_ONLY, there must be a 1:1 correspondence between
  131. // |resolve_context| and |host_cache|, and both should come from the same
  132. // ContextHostResolver.
  133. //
  134. // TODO(crbug.com/1022059): Use the HostCache out of the ResolveContext
  135. // instead of passing it separately.
  136. std::unique_ptr<HostResolver::ResolveHostRequest> CreateRequest(
  137. HostResolver::Host host,
  138. NetworkIsolationKey network_isolation_key,
  139. NetLogWithSource net_log,
  140. absl::optional<ResolveHostParameters> optional_parameters,
  141. ResolveContext* resolve_context,
  142. HostCache* host_cache);
  143. // |resolve_context| is the context to use for the probes, and it is expected
  144. // to be the context of the calling ContextHostResolver.
  145. std::unique_ptr<HostResolver::ProbeRequest> CreateDohProbeRequest(
  146. ResolveContext* resolve_context);
  147. std::unique_ptr<MdnsListener> CreateMdnsListener(const HostPortPair& host,
  148. DnsQueryType query_type);
  149. // Enables or disables the built-in asynchronous DnsClient. If enabled, by
  150. // default (when no |ResolveHostParameters::source| is specified), the
  151. // DnsClient will be used for resolves and, in case of failure, resolution
  152. // will fallback to the system resolver (HostResolverProc from
  153. // ProcTaskParams). If the DnsClient is not pre-configured with a valid
  154. // DnsConfig, a new config is fetched from NetworkChangeNotifier.
  155. //
  156. // Setting to |true| has no effect if |ENABLE_BUILT_IN_DNS| not defined.
  157. virtual void SetInsecureDnsClientEnabled(bool enabled,
  158. bool additional_dns_types_enabled);
  159. base::Value GetDnsConfigAsValue() const;
  160. // Sets overriding configuration that will replace or add to configuration
  161. // read from the system for DnsClient resolution.
  162. void SetDnsConfigOverrides(DnsConfigOverrides overrides);
  163. // Support for invalidating cached per-context data on changes to network or
  164. // DNS configuration. ContextHostResolvers should register/deregister
  165. // themselves here rather than attempting to listen for relevant network
  166. // change signals themselves because HostResolverManager needs to coordinate
  167. // invalidations with in-progress resolves and because some invalidations are
  168. // triggered by changes to manager properties/configuration rather than pure
  169. // network changes.
  170. //
  171. // Note: Invalidation handling must not call back into HostResolverManager as
  172. // the invalidation is expected to be handled atomically with other clearing
  173. // and aborting actions.
  174. void RegisterResolveContext(ResolveContext* context);
  175. void DeregisterResolveContext(const ResolveContext* context);
  176. void set_proc_params_for_test(const ProcTaskParams& proc_params) {
  177. proc_params_ = proc_params;
  178. }
  179. void InvalidateCachesForTesting() { InvalidateCaches(); }
  180. void SetTickClockForTesting(const base::TickClock* tick_clock);
  181. // Configures maximum number of Jobs in the queue. Exposed for testing.
  182. // Only allowed when the queue is empty.
  183. void SetMaxQueuedJobsForTesting(size_t value);
  184. void SetMdnsSocketFactoryForTesting(
  185. std::unique_ptr<MDnsSocketFactory> socket_factory);
  186. void SetMdnsClientForTesting(std::unique_ptr<MDnsClient> client);
  187. // To simulate modifications it would have received if |dns_client| had been
  188. // in place before calling this, DnsConfig will be set with the configuration
  189. // from the previous DnsClient being replaced (including system config if
  190. // |dns_client| does not already contain a system config). This means tests do
  191. // not normally need to worry about ordering between setting a test client and
  192. // setting DnsConfig.
  193. void SetDnsClientForTesting(std::unique_ptr<DnsClient> dns_client);
  194. // Explicitly disable the system resolver even if tests have set a catch-all
  195. // DNS block. See `ForceSystemResolverDueToTestOverride`.
  196. void DisableSystemResolverForTesting() {
  197. system_resolver_disabled_for_testing_ = true;
  198. }
  199. // Sets the last IPv6 probe result for testing. Uses the standard timeout
  200. // duration, so it's up to the test fixture to ensure it doesn't expire by
  201. // mocking time, if expiration would pose a problem.
  202. void SetLastIPv6ProbeResultForTesting(bool last_ipv6_probe_result);
  203. // Allows the tests to catch slots leaking out of the dispatcher. One
  204. // HostResolverManager::Job could occupy multiple PrioritizedDispatcher job
  205. // slots.
  206. size_t num_running_dispatcher_jobs_for_tests() const {
  207. return dispatcher_->num_running_jobs();
  208. }
  209. size_t num_jobs_for_testing() const { return jobs_.size(); }
  210. bool check_ipv6_on_wifi_for_testing() const { return check_ipv6_on_wifi_; }
  211. handles::NetworkHandle target_network_for_testing() const {
  212. return target_network_;
  213. }
  214. const HostResolver::HttpsSvcbOptions& https_svcb_options_for_testing() const {
  215. return https_svcb_options_;
  216. }
  217. // Public to be called from std::make_unique. Not to be called directly.
  218. HostResolverManager(base::PassKey<HostResolverManager>,
  219. const HostResolver::ManagerOptions& options,
  220. SystemDnsConfigChangeNotifier* system_dns_config_notifier,
  221. handles::NetworkHandle target_network,
  222. NetLog* net_log);
  223. protected:
  224. // Callback from HaveOnlyLoopbackAddresses probe.
  225. void SetHaveOnlyLoopbackAddresses(bool result);
  226. // Sets the task runner used for HostResolverProc tasks.
  227. void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner);
  228. private:
  229. friend class HostResolverManagerTest;
  230. friend class HostResolverManagerDnsTest;
  231. class Job;
  232. struct JobKey;
  233. class ProcTask;
  234. class LoopbackProbeJob;
  235. class DnsTask;
  236. class RequestImpl;
  237. class ProbeRequestImpl;
  238. using JobMap = std::map<JobKey, std::unique_ptr<Job>>;
  239. // Task types that a Job might run.
  240. enum class TaskType {
  241. PROC,
  242. DNS,
  243. SECURE_DNS,
  244. MDNS,
  245. CACHE_LOOKUP,
  246. INSECURE_CACHE_LOOKUP,
  247. SECURE_CACHE_LOOKUP,
  248. CONFIG_PRESET,
  249. };
  250. // Returns true if the task is local, synchronous, and instantaneous.
  251. static bool IsLocalTask(TaskType task);
  252. // Attempts host resolution for |request|. Generally only expected to be
  253. // called from RequestImpl::Start().
  254. int Resolve(RequestImpl* request);
  255. // Attempts host resolution using fast local sources: IP literal resolution,
  256. // cache lookup, HOSTS lookup (if enabled), and localhost. Returns results
  257. // with error() OK if successful, ERR_NAME_NOT_RESOLVED if input is invalid,
  258. // or ERR_DNS_CACHE_MISS if the host could not be resolved using local
  259. // sources.
  260. //
  261. // On ERR_DNS_CACHE_MISS and OK, |out_tasks| contains the tentative
  262. // sequence of tasks that a future job should run.
  263. //
  264. // If results are returned from the host cache, |out_stale_info| will be
  265. // filled in with information on how stale or fresh the result is. Otherwise,
  266. // |out_stale_info| will be set to |absl::nullopt|.
  267. //
  268. // If |cache_usage == ResolveHostParameters::CacheUsage::STALE_ALLOWED|, then
  269. // stale cache entries can be returned.
  270. HostCache::Entry ResolveLocally(
  271. const JobKey& job_key,
  272. const IPAddress& ip_address,
  273. ResolveHostParameters::CacheUsage cache_usage,
  274. SecureDnsPolicy secure_dns_policy,
  275. const NetLogWithSource& request_net_log,
  276. HostCache* cache,
  277. std::deque<TaskType>* out_tasks,
  278. absl::optional<HostCache::EntryStaleness>* out_stale_info);
  279. // Creates and starts a Job to asynchronously attempt to resolve
  280. // |request|.
  281. void CreateAndStartJob(JobKey key,
  282. std::deque<TaskType> tasks,
  283. RequestImpl* request);
  284. HostResolverManager::Job* AddJobWithoutRequest(
  285. JobKey key,
  286. ResolveHostParameters::CacheUsage cache_usage,
  287. HostCache* host_cache,
  288. std::deque<TaskType> tasks,
  289. RequestPriority priority,
  290. const NetLogWithSource& source_net_log);
  291. // Resolves the IP literal hostname represented by `ip_address`.
  292. HostCache::Entry ResolveAsIP(DnsQueryTypeSet query_types,
  293. bool resolve_canonname,
  294. const IPAddress& ip_address);
  295. // Returns the result iff |cache_usage| permits cache lookups and a positive
  296. // match is found for |key| in |cache|. |out_stale_info| must be non-null, and
  297. // will be filled in with details of the entry's staleness if an entry is
  298. // returned, otherwise it will be set to |absl::nullopt|.
  299. absl::optional<HostCache::Entry> MaybeServeFromCache(
  300. HostCache* cache,
  301. const HostCache::Key& key,
  302. ResolveHostParameters::CacheUsage cache_usage,
  303. bool ignore_secure,
  304. const NetLogWithSource& source_net_log,
  305. absl::optional<HostCache::EntryStaleness>* out_stale_info);
  306. // Returns any preset resolution result from the active DoH configuration that
  307. // matches |key.host|.
  308. absl::optional<HostCache::Entry> MaybeReadFromConfig(const JobKey& key);
  309. // Populates the secure cache with an optimal entry that supersedes the
  310. // bootstrap result.
  311. void StartBootstrapFollowup(JobKey key,
  312. HostCache* host_cache,
  313. const NetLogWithSource& source_net_log);
  314. // Iff we have a DnsClient with a valid DnsConfig and we're not about to
  315. // attempt a system lookup, then try to resolve the query using the HOSTS
  316. // file.
  317. absl::optional<HostCache::Entry> ServeFromHosts(
  318. base::StringPiece hostname,
  319. DnsQueryTypeSet query_types,
  320. bool default_family_due_to_no_ipv6,
  321. const std::deque<TaskType>& tasks);
  322. // Iff |key| is for a localhost name (RFC 6761) and address DNS query type,
  323. // returns a results entry with the loopback IP.
  324. absl::optional<HostCache::Entry> ServeLocalhost(
  325. base::StringPiece hostname,
  326. DnsQueryTypeSet query_types,
  327. bool default_family_due_to_no_ipv6);
  328. // Returns the secure dns mode to use for a job, taking into account the
  329. // global DnsConfig mode and any per-request policy.
  330. SecureDnsMode GetEffectiveSecureDnsMode(SecureDnsPolicy secure_dns_policy);
  331. // Returns true when a catch-all DNS block has been set for tests, unless
  332. // `SetDisableSystemResolverForTesting` has been called to explicitly disable
  333. // that safety net. DnsTasks should never be issued when this returns true.
  334. bool ShouldForceSystemResolverDueToTestOverride() const;
  335. // Helper method to add DnsTasks and related tasks based on the SecureDnsMode
  336. // and fallback parameters. If |prioritize_local_lookups| is true, then we
  337. // may push an insecure cache lookup ahead of a secure DnsTask.
  338. void PushDnsTasks(bool proc_task_allowed,
  339. SecureDnsMode secure_dns_mode,
  340. bool insecure_tasks_allowed,
  341. bool allow_cache,
  342. bool prioritize_local_lookups,
  343. ResolveContext* resolve_context,
  344. std::deque<TaskType>* out_tasks);
  345. // Initialized the sequence of tasks to run to resolve a request. The sequence
  346. // may be adjusted later and not all tasks need to be run.
  347. void CreateTaskSequence(const JobKey& job_key,
  348. ResolveHostParameters::CacheUsage cache_usage,
  349. SecureDnsPolicy secure_dns_policy,
  350. std::deque<TaskType>* out_tasks);
  351. // Determines "effective" request parameters using manager properties and IPv6
  352. // reachability.
  353. void GetEffectiveParametersForRequest(
  354. const absl::variant<url::SchemeHostPort, std::string>& host,
  355. DnsQueryType dns_query_type,
  356. HostResolverFlags flags,
  357. SecureDnsPolicy secure_dns_policy,
  358. bool is_ip,
  359. const NetLogWithSource& net_log,
  360. DnsQueryTypeSet* out_effective_types,
  361. HostResolverFlags* out_effective_flags,
  362. SecureDnsMode* out_effective_secure_dns_mode);
  363. // Probes IPv6 support and returns true if IPv6 support is enabled.
  364. // Results are cached, i.e. when called repeatedly this method returns result
  365. // from the first probe for some time before probing again.
  366. bool IsIPv6Reachable(const NetLogWithSource& net_log);
  367. // Sets |last_ipv6_probe_result_| and updates |last_ipv6_probe_time_|.
  368. void SetLastIPv6ProbeResult(bool last_ipv6_probe_result);
  369. // Attempts to connect a UDP socket to |dest|:53. Virtual for testing.
  370. virtual bool IsGloballyReachable(const IPAddress& dest,
  371. const NetLogWithSource& net_log);
  372. // Asynchronously checks if only loopback IPs are available.
  373. virtual void RunLoopbackProbeJob();
  374. // Records the result in cache if cache is present.
  375. void CacheResult(HostCache* cache,
  376. const HostCache::Key& key,
  377. const HostCache::Entry& entry,
  378. base::TimeDelta ttl);
  379. // Removes |job_it| from |jobs_| and return.
  380. std::unique_ptr<Job> RemoveJob(JobMap::iterator job_it);
  381. // Removes Jobs for this context.
  382. void RemoveAllJobs(const ResolveContext* context);
  383. // Aborts all jobs (both scheduled and running) which are not targeting a
  384. // specific network with ERR_NETWORK_CHANGED and notifies their requests.
  385. // Aborts only running jobs if `in_progress_only` is true. Might start new
  386. // jobs.
  387. void AbortJobsWithoutTargetNetwork(bool in_progress_only);
  388. // Aborts all in progress insecure DnsTasks. In-progress jobs will fall back
  389. // to ProcTasks if able and otherwise abort with |error|. Might start new
  390. // jobs, if any jobs were taking up two dispatcher slots.
  391. //
  392. // If |fallback_only|, insecure DnsTasks will only abort if they can fallback
  393. // to ProcTask.
  394. void AbortInsecureDnsTasks(int error, bool fallback_only);
  395. // Attempts to serve each Job in |jobs_| from the HOSTS file if we have
  396. // a DnsClient with a valid DnsConfig.
  397. void TryServingAllJobsFromHosts();
  398. // NetworkChangeNotifier::IPAddressObserver:
  399. void OnIPAddressChanged() override;
  400. // NetworkChangeNotifier::ConnectionTypeObserver:
  401. void OnConnectionTypeChanged(
  402. NetworkChangeNotifier::ConnectionType type) override;
  403. // SystemDnsConfigChangeNotifier::Observer:
  404. void OnSystemDnsConfigChanged(absl::optional<DnsConfig> config) override;
  405. void UpdateJobsForChangedConfig();
  406. // Called on successful resolve after falling back to ProcTask after a failed
  407. // DnsTask resolve.
  408. void OnFallbackResolve(int dns_task_error);
  409. int GetOrCreateMdnsClient(MDnsClient** out_client);
  410. // |network_change| indicates whether or not the invalidation was triggered
  411. // by a network connection change.
  412. void InvalidateCaches(bool network_change = false);
  413. void UpdateConnectionType(NetworkChangeNotifier::ConnectionType type);
  414. bool IsBoundToNetwork() const {
  415. return target_network_ != handles::kInvalidNetworkHandle;
  416. }
  417. // Returns |nullptr| if DoH probes are currently not allowed (due to
  418. // configuration or current connection state).
  419. std::unique_ptr<DnsProbeRunner> CreateDohProbeRunner(
  420. ResolveContext* resolve_context);
  421. // Used for multicast DNS tasks. Created on first use using
  422. // GetOrCreateMndsClient().
  423. std::unique_ptr<MDnsSocketFactory> mdns_socket_factory_;
  424. std::unique_ptr<MDnsClient> mdns_client_;
  425. // Map from HostCache::Key to a Job.
  426. JobMap jobs_;
  427. // Starts Jobs according to their priority and the configured limits.
  428. std::unique_ptr<PrioritizedDispatcher> dispatcher_;
  429. // Limit on the maximum number of jobs queued in |dispatcher_|.
  430. size_t max_queued_jobs_ = 0;
  431. // Parameters for ProcTask.
  432. ProcTaskParams proc_params_;
  433. raw_ptr<NetLog> net_log_;
  434. // If present, used by DnsTask and ServeFromHosts to resolve requests.
  435. std::unique_ptr<DnsClient> dns_client_;
  436. raw_ptr<SystemDnsConfigChangeNotifier> system_dns_config_notifier_;
  437. handles::NetworkHandle target_network_;
  438. // False if IPv6 should not be attempted and assumed unreachable when on a
  439. // WiFi connection. See https://crbug.com/696569 for further context.
  440. bool check_ipv6_on_wifi_;
  441. base::TimeTicks last_ipv6_probe_time_;
  442. bool last_ipv6_probe_result_ = true;
  443. // Any resolver flags that should be added to a request by default.
  444. HostResolverFlags additional_resolver_flags_ = 0;
  445. // Allow fallback to ProcTask if DnsTask fails.
  446. bool allow_fallback_to_proctask_ = true;
  447. // Task runner used for DNS lookups using the system resolver. Normally a
  448. // ThreadPool task runner, but can be overridden for tests.
  449. scoped_refptr<base::TaskRunner> proc_task_runner_;
  450. // Shared tick clock, overridden for testing.
  451. raw_ptr<const base::TickClock> tick_clock_;
  452. // When true, ignore the catch-all DNS block if it exists.
  453. bool system_resolver_disabled_for_testing_ = false;
  454. // For per-context cache invalidation notifications.
  455. base::ObserverList<ResolveContext,
  456. true /* check_empty */,
  457. false /* allow_reentrancy */>
  458. registered_contexts_;
  459. bool invalidation_in_progress_ = false;
  460. // Helper for metrics associated with `features::kDnsHttpssvc`.
  461. HttpssvcExperimentDomainCache httpssvc_domain_cache_;
  462. // An experimental flag for features::kUseDnsHttpsSvcb.
  463. HostResolver::HttpsSvcbOptions https_svcb_options_;
  464. THREAD_CHECKER(thread_checker_);
  465. base::WeakPtrFactory<HostResolverManager> weak_ptr_factory_{this};
  466. base::WeakPtrFactory<HostResolverManager> probe_weak_ptr_factory_{this};
  467. };
  468. // Resolves a local hostname (such as "localhost" or "vhost.localhost") into
  469. // IP endpoints (with port 0). Returns true if |host| is a local
  470. // hostname and false otherwise. Names will resolve to both IPv4 and IPv6.
  471. // This function is only exposed so it can be unit-tested.
  472. // TODO(tfarina): It would be better to change the tests so this function
  473. // gets exercised indirectly through HostResolverManager.
  474. NET_EXPORT_PRIVATE bool ResolveLocalHostname(
  475. base::StringPiece host,
  476. std::vector<IPEndPoint>* address_list);
  477. } // namespace net
  478. #endif // NET_DNS_HOST_RESOLVER_MANAGER_H_