#include "net/dns/host_resolver_system_task.h"
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/dcheck_is_on.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ref.h"
#include "base/metrics/field_trial_params.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/sequence_checker.h"
#include "base/sequence_checker_impl.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/time/time.h"
#include "base/types/pass_key.h"
#include "dns_reloader.h"
#include "net/base/address_family.h"
#include "net/base/address_list.h"
#include "net/base/features.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/network_interfaces.h"
#include "net/base/sys_addrinfo.h"
#include "net/base/trace_constants.h"
#include "net/base/tracing.h"
#include "net/dns/address_info.h"
#include "net/dns/dns_names_util.h"
#include "net/dns/host_resolver_cache.h"
#include "net/dns/host_resolver_internal_result.h"
#include "net/dns/public/host_resolver_source.h"
#if BUILDFLAG(IS_WIN)
#include "net/base/winsock_init.h"
#endif
namespace net {
namespace {
constexpr base::TimeDelta kTtl = …;
scoped_refptr<base::TaskRunner>& GetSystemDnsResolutionTaskRunnerOverride() { … }
void PostSystemDnsResolutionTaskAndReply(
base::OnceCallback<int(AddressList* addrlist, int* os_error)>
system_dns_resolution_callback,
SystemDnsResultsCallback results_cb) { … }
int ResolveOnWorkerThread(scoped_refptr<HostResolverProc> resolver_proc,
std::optional<std::string> hostname,
AddressFamily address_family,
HostResolverFlags flags,
handles::NetworkHandle network,
AddressList* addrlist,
int* os_error) { … }
base::Value::Dict NetLogHostResolverSystemTaskFailedParams(
uint32_t attempt_number,
int net_error,
int os_error) { … }
SystemDnsResolverOverrideCallback;
SystemDnsResolverOverrideCallback& GetSystemDnsResolverOverride() { … }
}
void SetSystemDnsResolverOverride(
SystemDnsResolverOverrideCallback dns_override) { … }
HostResolverSystemTask::Params::Params(
scoped_refptr<HostResolverProc> resolver_proc,
size_t in_max_retry_attempts)
: … { … }
HostResolverSystemTask::Params::Params(const Params& other) = default;
HostResolverSystemTask::Params::~Params() = default;
HostResolverSystemTask::CacheParams::CacheParams(
HostResolverCache& cache,
NetworkAnonymizationKey network_anonymization_key)
: … { … }
HostResolverSystemTask::CacheParams::CacheParams(const CacheParams&) = default;
HostResolverSystemTask::CacheParams::CacheParams(CacheParams&&) = default;
HostResolverSystemTask::CacheParams::~CacheParams() = default;
std::unique_ptr<HostResolverSystemTask> HostResolverSystemTask::Create(
std::string hostname,
AddressFamily address_family,
HostResolverFlags flags,
const Params& params,
const NetLogWithSource& job_net_log,
handles::NetworkHandle network,
std::optional<CacheParams> cache_params) { … }
std::unique_ptr<HostResolverSystemTask>
HostResolverSystemTask::CreateForOwnHostname(
AddressFamily address_family,
HostResolverFlags flags,
const Params& params,
const NetLogWithSource& job_net_log,
handles::NetworkHandle network) { … }
HostResolverSystemTask::HostResolverSystemTask(
std::optional<std::string> hostname,
AddressFamily address_family,
HostResolverFlags flags,
const Params& params,
const NetLogWithSource& job_net_log,
handles::NetworkHandle network,
std::optional<CacheParams> cache_params)
: … { … }
HostResolverSystemTask::~HostResolverSystemTask() { … }
void HostResolverSystemTask::Start(SystemDnsResultsCallback results_cb) { … }
void HostResolverSystemTask::StartLookupAttempt() { … }
void HostResolverSystemTask::OnLookupComplete(const uint32_t attempt_number,
const AddressList& results,
const int os_error,
int error) { … }
void HostResolverSystemTask::MaybeCacheResults(
const AddressList& address_list) { … }
void HostResolverSystemTask::CacheEndpoints(std::string domain_name,
std::vector<IPEndPoint> endpoints,
DnsQueryType query_type) { … }
void HostResolverSystemTask::CacheAlias(std::string domain_name,
DnsQueryType query_type,
std::string target_name) { … }
void EnsureSystemHostResolverCallReady() { … }
namespace {
int AddressFamilyToAF(AddressFamily address_family) { … }
}
int SystemHostResolverCall(const std::string& host,
AddressFamily address_family,
HostResolverFlags host_resolver_flags,
AddressList* addrlist,
int* os_error_opt,
handles::NetworkHandle network) { … }
void SetSystemDnsResolutionTaskRunnerForTesting(
scoped_refptr<base::TaskRunner> task_runner) { … }
}