1 // Copyright 2020 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_DOH_PROVIDER_ENTRY_H_ 6 #define NET_DNS_PUBLIC_DOH_PROVIDER_ENTRY_H_ 7 8 #include <initializer_list> 9 #include <optional> 10 #include <set> 11 #include <string> 12 #include <string_view> 13 #include <vector> 14 15 #include "base/containers/flat_set.h" 16 #include "base/feature_list.h" 17 #include "base/memory/raw_ptr.h" 18 #include "base/memory/raw_ptr_exclusion.h" 19 #include "net/base/ip_address.h" 20 #include "net/base/net_export.h" 21 #include "net/dns/public/dns_over_https_server_config.h" 22 23 namespace net { 24 25 // Represents insecure DNS, DoT, and DoH services run by the same provider. 26 // These entries are used to support upgrade from insecure DNS or DoT services 27 // to associated DoH services in automatic mode and to populate the dropdown 28 // menu for secure mode. 29 // 30 // To be eligible for auto-upgrade, an entry must have a non-empty 31 // `dns_over_53_server_ip_strs` or non-empty `dns_over_tls_hostnames`. To be 32 // eligible for the dropdown menu, the entry must have non-empty `ui_name` and 33 // `privacy_policy`. If `display_globally` is true, the entry is eligible to be 34 // displayed globally in the dropdown menu. If `display_globally` is false, 35 // `display_countries` should contain the two-letter ISO 3166-1 country codes, 36 // if any, where the entry is eligible for being displayed in the dropdown menu. 37 // 38 // If `feature` is disabled, the entry is eligible for neither auto-upgrade nor 39 // the dropdown menu. 40 // DohProviderEntries are only constructed with static data in production. 41 struct NET_EXPORT DohProviderEntry { 42 public: 43 using List = std::vector<raw_ptr<const DohProviderEntry, VectorExperimental>>; 44 45 enum class LoggingLevel { 46 // Indicates the normal amount of logging, monitoring, and metrics. 47 kNormal, 48 49 // Indicates that a provider is of extra interest and eligible for 50 // additional logging, monitoring, and metrics. 51 kExtra, 52 }; 53 54 std::string_view provider; 55 // Avoid using base::Feature& and use raw_ref instead. Use feature.get() 56 // for accessing the raw reference. 57 raw_ref<const base::Feature> feature; 58 std::set<IPAddress> ip_addresses; 59 base::flat_set<std::string_view> dns_over_tls_hostnames; 60 DnsOverHttpsServerConfig doh_server_config; 61 std::string_view ui_name; 62 std::string_view privacy_policy; 63 bool display_globally; 64 base::flat_set<std::string> display_countries; 65 LoggingLevel logging_level; 66 67 // Returns the full list of DoH providers. A subset of this list may be used 68 // to support upgrade in automatic mode or to populate the dropdown menu for 69 // secure mode. 70 static const List& GetList(); 71 72 static DohProviderEntry ConstructForTesting( 73 std::string_view provider, 74 const base::Feature* feature, 75 std::initializer_list<std::string_view> dns_over_53_server_ip_strs, 76 base::flat_set<std::string_view> dns_over_tls_hostnames, 77 std::string dns_over_https_template, 78 std::string_view ui_name, 79 std::string_view privacy_policy, 80 bool display_globally, 81 base::flat_set<std::string> display_countries, 82 LoggingLevel logging_level = LoggingLevel::kNormal); 83 84 // Entries are neither copyable nor moveable. This allows tests to construct a 85 // List but ensures that `const DohProviderEntry*` is a safe type for 86 // application code. 87 DohProviderEntry(DohProviderEntry& other) = delete; 88 DohProviderEntry(DohProviderEntry&& other); 89 90 ~DohProviderEntry(); 91 92 private: 93 // DohProviderEntry must be constructed with strings with static storage 94 // duration that are never destroyed. 95 DohProviderEntry( 96 std::string_view provider, 97 // Disallow implicit copying of the `feature` parameter because there 98 // cannot be more than one `base::Feature` for a given feature name. 99 const base::Feature* feature, 100 std::initializer_list<std::string_view> dns_over_53_server_ip_strs, 101 base::flat_set<std::string_view> dns_over_tls_hostnames, 102 std::string dns_over_https_template, 103 std::string_view ui_name, 104 std::string_view privacy_policy, 105 bool display_globally, 106 base::flat_set<std::string> display_countries, 107 LoggingLevel logging_level, 108 std::initializer_list<std::string_view> dns_over_https_server_ip_strs = 109 {}); 110 }; 111 112 } // namespace net 113 114 #endif // NET_DNS_PUBLIC_DOH_PROVIDER_ENTRY_H_ 115