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