#include "net/dns/host_resolver.h"
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time_delta_from_string.h"
#include "base/values.h"
#include "net/base/address_list.h"
#include "net/base/features.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_errors.h"
#include "net/base/network_change_notifier.h"
#include "net/dns/context_host_resolver.h"
#include "net/dns/dns_client.h"
#include "net/dns/dns_util.h"
#include "net/dns/host_cache.h"
#include "net/dns/host_resolver_manager.h"
#include "net/dns/mapped_host_resolver.h"
#include "net/dns/public/host_resolver_results.h"
#include "net/dns/resolve_context.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "url/scheme_host_port.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#include "net/android/network_library.h"
#endif
namespace net {
namespace {
const char kUseDnsHttpsSvcbEnable[] = …;
const char kUseDnsHttpsSvcbInsecureExtraTimeMax[] = …;
const char kUseDnsHttpsSvcbInsecureExtraTimePercent[] = …;
const char kUseDnsHttpsSvcbInsecureExtraTimeMin[] = …;
const char kUseDnsHttpsSvcbSecureExtraTimeMax[] = …;
const char kUseDnsHttpsSvcbSecureExtraTimePercent[] = …;
const char kUseDnsHttpsSvcbSecureExtraTimeMin[] = …;
class FailingRequestImpl : public HostResolver::ResolveHostRequest,
public HostResolver::ProbeRequest { … };
bool EndpointResultIsNonProtocol(const HostResolverEndpointResult& result) { … }
void GetTimeDeltaFromDictString(const base::Value::Dict& args,
std::string_view key,
base::TimeDelta* out) { … }
}
HostResolver::Host::Host(absl::variant<url::SchemeHostPort, HostPortPair> host)
: … { … }
HostResolver::Host::~Host() = default;
HostResolver::Host::Host(const Host&) = default;
HostResolver::Host& HostResolver::Host::operator=(const Host&) = default;
HostResolver::Host::Host(Host&&) = default;
HostResolver::Host& HostResolver::Host::operator=(Host&&) = default;
bool HostResolver::Host::HasScheme() const { … }
const std::string& HostResolver::Host::GetScheme() const { … }
std::string HostResolver::Host::GetHostname() const { … }
std::string_view HostResolver::Host::GetHostnameWithoutBrackets() const { … }
uint16_t HostResolver::Host::GetPort() const { … }
std::string HostResolver::Host::ToString() const { … }
const url::SchemeHostPort& HostResolver::Host::AsSchemeHostPort() const { … }
HostResolver::HttpsSvcbOptions::HttpsSvcbOptions() = default;
HostResolver::HttpsSvcbOptions::HttpsSvcbOptions(
const HttpsSvcbOptions& other) = default;
HostResolver::HttpsSvcbOptions::HttpsSvcbOptions(HttpsSvcbOptions&& other) =
default;
HostResolver::HttpsSvcbOptions::~HttpsSvcbOptions() = default;
HostResolver::HttpsSvcbOptions HostResolver::HttpsSvcbOptions::FromDict(
const base::Value::Dict& dict) { … }
HostResolver::HttpsSvcbOptions HostResolver::HttpsSvcbOptions::FromFeatures() { … }
HostResolver::ManagerOptions::ManagerOptions() = default;
HostResolver::ManagerOptions::ManagerOptions(const ManagerOptions& other) =
default;
HostResolver::ManagerOptions::ManagerOptions(ManagerOptions&& other) = default;
HostResolver::ManagerOptions::~ManagerOptions() = default;
const std::vector<bool>*
HostResolver::ResolveHostRequest::GetExperimentalResultsForTesting() const { … }
std::unique_ptr<HostResolver> HostResolver::Factory::CreateResolver(
HostResolverManager* manager,
std::string_view host_mapping_rules,
bool enable_caching) { … }
std::unique_ptr<HostResolver> HostResolver::Factory::CreateStandaloneResolver(
NetLog* net_log,
const ManagerOptions& options,
std::string_view host_mapping_rules,
bool enable_caching) { … }
HostResolver::ResolveHostParameters::ResolveHostParameters() = default;
HostResolver::ResolveHostParameters::ResolveHostParameters(
const ResolveHostParameters& other) = default;
HostResolver::~HostResolver() = default;
std::unique_ptr<HostResolver::ProbeRequest>
HostResolver::CreateDohProbeRequest() { … }
std::unique_ptr<HostResolver::MdnsListener> HostResolver::CreateMdnsListener(
const HostPortPair& host,
DnsQueryType query_type) { … }
HostCache* HostResolver::GetHostCache() { … }
base::Value::Dict HostResolver::GetDnsConfigAsValue() const { … }
void HostResolver::SetRequestContext(URLRequestContext* request_context) { … }
HostResolverManager* HostResolver::GetManagerForTesting() { … }
const URLRequestContext* HostResolver::GetContextForTesting() const { … }
handles::NetworkHandle HostResolver::GetTargetNetworkForTesting() const { … }
std::unique_ptr<HostResolver> HostResolver::CreateResolver(
HostResolverManager* manager,
std::string_view host_mapping_rules,
bool enable_caching) { … }
std::unique_ptr<HostResolver> HostResolver::CreateStandaloneResolver(
NetLog* net_log,
std::optional<ManagerOptions> options,
std::string_view host_mapping_rules,
bool enable_caching) { … }
std::unique_ptr<ContextHostResolver>
HostResolver::CreateStandaloneContextResolver(
NetLog* net_log,
std::optional<ManagerOptions> options,
bool enable_caching) { … }
std::unique_ptr<HostResolver>
HostResolver::CreateStandaloneNetworkBoundResolver(
NetLog* net_log,
handles::NetworkHandle target_network,
std::optional<ManagerOptions> options,
std::string_view host_mapping_rules,
bool enable_caching) { … }
AddressFamily HostResolver::DnsQueryTypeSetToAddressFamily(
DnsQueryTypeSet dns_query_types) { … }
HostResolverFlags HostResolver::ParametersToHostResolverFlags(
const ResolveHostParameters& parameters) { … }
int HostResolver::SquashErrorCode(int error) { … }
AddressList HostResolver::EndpointResultToAddressList(
base::span<const HostResolverEndpointResult> endpoints,
const std::set<std::string>& aliases) { … }
bool HostResolver::MayUseNAT64ForIPv4Literal(HostResolverFlags flags,
HostResolverSource source,
const IPAddress& ip_address) { … }
HostResolver::HostResolver() = default;
std::unique_ptr<HostResolver::ResolveHostRequest>
HostResolver::CreateFailingRequest(int error) { … }
std::unique_ptr<HostResolver::ProbeRequest>
HostResolver::CreateFailingProbeRequest(int error) { … }
}