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/strings/string_piece.h" 14 #include "net/base/ip_address.h" 15 #include "net/base/net_export.h" 16 #include "net/dns/public/dns_over_https_server_config.h" 17 #include "third_party/abseil-cpp/absl/types/optional.h" 18 19 namespace net { 20 21 // Provider ids for usage in histograms. Entries should not be renumbered and 22 // numeric values should never be reused. Please keep in sync with 23 // "DohProviderId" in src/tools/metrics/histograms/enums.xml. 24 enum class DohProviderIdForHistogram { 25 kCustom = 0, 26 kCleanBrowsingFamily = 1, 27 kCloudflare = 2, 28 kGoogle = 3, 29 kIij = 4, 30 kQuad9Secure = 5, 31 kDnsSb = 6, 32 kCznic = 7, 33 kNextDns = 8, 34 kOpenDns = 9, 35 kAlekBergNl = 10, 36 kMaxValue = kAlekBergNl, 37 }; 38 39 // Represents insecure DNS, DoT, and DoH services run by the same provider. 40 // These entries are used to support upgrade from insecure DNS or DoT services 41 // to associated DoH services in automatic mode and to populate the dropdown 42 // menu for secure mode. 43 // 44 // To be eligible for auto-upgrade, an entry must have a non-empty `ip_strs` or 45 // non-empty `dns_over_tls_hostnames`. To be eligible for the dropdown menu, the 46 // entry must have non-empty `ui_name` and `privacy_policy`. If 47 // `display_globally` is true, the entry is eligible to be displayed globally in 48 // the dropdown menu. If `display_globally` is false, `display_countries` should 49 // contain the two-letter ISO 3166-1 country codes, if any, where the entry is 50 // eligible for being displayed in the dropdown menu. 51 // 52 // If `feature` is disabled, the entry is eligible for neither auto-upgrade nor 53 // the dropdown menu. 54 struct NET_EXPORT DohProviderEntry { 55 public: 56 using List = std::vector<const DohProviderEntry*>; 57 58 enum class LoggingLevel { 59 // Indicates the normal amount of logging, monitoring, and metrics. 60 kNormal, 61 62 // Indicates that a provider is of extra interest and eligible for 63 // additional logging, monitoring, and metrics. 64 kExtra, 65 }; 66 67 std::string provider; 68 const base::Feature& feature; 69 // A provider_id_for_histogram is required for entries that are intended to 70 // be visible in the UI. 71 absl::optional<DohProviderIdForHistogram> provider_id_for_histogram; 72 std::set<IPAddress> ip_addresses; 73 std::set<std::string> dns_over_tls_hostnames; 74 DnsOverHttpsServerConfig doh_server_config; 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; 80 81 // Returns the full list of DoH providers. A subset of this list may be used 82 // to support upgrade in automatic mode or to populate the dropdown menu for 83 // secure mode. 84 static const List& GetList(); 85 86 static DohProviderEntry ConstructForTesting( 87 std::string provider, 88 const base::Feature* feature, 89 absl::optional<DohProviderIdForHistogram> provider_id_for_histogram, 90 std::set<base::StringPiece> ip_strs, 91 std::set<std::string> dns_over_tls_hostnames, 92 std::string dns_over_https_template, 93 std::string ui_name, 94 std::string privacy_policy, 95 bool display_globally, 96 std::set<std::string> display_countries, 97 LoggingLevel logging_level = LoggingLevel::kNormal); 98 99 // Entries are neither copyable nor moveable. This allows tests to construct a 100 // List but ensures that `const DohProviderEntry*` is a safe type for 101 // application code. 102 DohProviderEntry(DohProviderEntry& other) = delete; 103 DohProviderEntry(DohProviderEntry&& other) = delete; 104 105 ~DohProviderEntry(); 106 107 private: 108 DohProviderEntry( 109 std::string provider, 110 // Disallow implicit copying of the `feature` parameter because there 111 // cannot be more than one `base::Feature` for a given feature name. 112 const base::Feature* feature, 113 absl::optional<DohProviderIdForHistogram> provider_id_for_histogram, 114 std::set<base::StringPiece> ip_strs, 115 std::set<std::string> dns_over_tls_hostnames, 116 std::string dns_over_https_template, 117 std::string ui_name, 118 std::string privacy_policy, 119 bool display_globally, 120 std::set<std::string> display_countries, 121 LoggingLevel logging_level); 122 }; 123 124 } // namespace net 125 126 #endif // NET_DNS_PUBLIC_DOH_PROVIDER_ENTRY_H_ 127