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