xref: /aosp_15_r20/external/cronet/net/dns/public/host_resolver_source.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_DNS_PUBLIC_HOST_RESOLVER_SOURCE_H_
6 #define NET_DNS_PUBLIC_HOST_RESOLVER_SOURCE_H_
7 
8 #include <iterator>
9 #include <optional>
10 
11 #include "base/values.h"
12 
13 namespace net {
14 
15 // Enumeration to specify the allowed results source for HostResolver
16 // requests.
17 //
18 // Integer values used for (de)serialization. Do not renumber.
19 enum class HostResolverSource {
20   // Resolver will pick an appropriate source. Results could come from DNS,
21   // MulticastDNS, HOSTS file, etc.
22   ANY = 0,
23 
24   // Results will only be retrieved from the system or OS, eg via the
25   // getaddrinfo() system call.
26   SYSTEM = 1,
27 
28   // Results will only come from DNS queries.
29   DNS = 2,
30 
31   // Results will only come from Multicast DNS queries.
32   MULTICAST_DNS = 3,
33 
34   // No external sources will be used. Results will only come from fast local
35   // sources that are available no matter the source setting, e.g. cache, hosts
36   // file, IP literal resolution, etc. Resolves with this setting are guaranteed
37   // to finish synchronously. Resolves with this settings will return
38   // ERR_NAME_NOT_RESOLVED if an asynchronous IPv6 reachability probe needs to
39   // be done.
40   LOCAL_ONLY = 4,
41 
42   MAX = LOCAL_ONLY
43 };
44 
45 base::Value ToValue(HostResolverSource source);
46 
47 // std::nullopt if `value` is malformed for deserialization.
48 std::optional<HostResolverSource> HostResolverSourceFromValue(
49     const base::Value& value);
50 
51 const HostResolverSource kHostResolverSources[] = {
52     HostResolverSource::ANY, HostResolverSource::SYSTEM,
53     HostResolverSource::DNS, HostResolverSource::MULTICAST_DNS,
54     HostResolverSource::LOCAL_ONLY};
55 
56 static_assert(
57     std::size(kHostResolverSources) ==
58         static_cast<unsigned>(HostResolverSource::MAX) + 1,
59     "All HostResolverSource values should be in kHostResolverSources.");
60 
61 }  // namespace net
62 
63 #endif  // NET_DNS_PUBLIC_HOST_RESOLVER_SOURCE_H_
64