dalyk | 272d4b0 | 2019-08-14 00:37:51 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Schwartz | 135746c | 2020-05-14 04:37:03 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_NET_SECURE_DNS_UTIL_H_ |
| 6 | #define CHROME_BROWSER_NET_SECURE_DNS_UTIL_H_ |
dalyk | 272d4b0 | 2019-08-14 00:37:51 | [diff] [blame] | 7 | |
Ben Schwartz | 4e146861 | 2020-03-31 21:23:45 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
| 10 | #include "base/strings/string_piece.h" |
Ben Schwartz | 35685c7 | 2020-06-03 04:53:13 | [diff] [blame] | 11 | #include "net/dns/public/doh_provider_entry.h" |
Ben Schwartz | e91bdcfe4 | 2020-05-07 14:49:50 | [diff] [blame] | 12 | |
| 13 | namespace net { |
| 14 | struct DnsConfigOverrides; |
| 15 | } // namespace net |
dalyk | 272d4b0 | 2019-08-14 00:37:51 | [diff] [blame] | 16 | |
Martin Šrámek | 5921f631 | 2020-03-25 09:31:47 | [diff] [blame] | 17 | class PrefRegistrySimple; |
| 18 | class PrefService; |
| 19 | |
Steven Bingler | dd2307b | 2019-08-27 20:44:36 | [diff] [blame] | 20 | namespace chrome_browser_net { |
| 21 | |
Ben Schwartz | 135746c | 2020-05-14 04:37:03 | [diff] [blame] | 22 | namespace secure_dns { |
| 23 | |
Ben Schwartz | 35685c7 | 2020-06-03 04:53:13 | [diff] [blame] | 24 | // Returns the subset of |providers| that are marked for use in the specified |
| 25 | // country. |
| 26 | net::DohProviderEntry::List ProvidersForCountry( |
| 27 | const net::DohProviderEntry::List& providers, |
| 28 | int country_id); |
| 29 | |
| 30 | // Returns the names of providers that have been remotely disabled, for use with |
| 31 | // RemoveDisabledProviders(). |
| 32 | std::vector<std::string> GetDisabledProviders(); |
| 33 | |
| 34 | // Returns the subset of |providers| for which |DohProviderEntry::provider| is |
| 35 | // not listed in |disabled_providers|. |
| 36 | net::DohProviderEntry::List RemoveDisabledProviders( |
| 37 | const net::DohProviderEntry::List& providers, |
| 38 | const std::vector<std::string>& disabled_providers); |
| 39 | |
Ben Schwartz | 4e146861 | 2020-03-31 21:23:45 | [diff] [blame] | 40 | // Implements the whitespace-delimited group syntax for DoH templates. |
Ben Schwartz | 135746c | 2020-05-14 04:37:03 | [diff] [blame] | 41 | std::vector<base::StringPiece> SplitGroup(base::StringPiece group); |
Ben Schwartz | 4e146861 | 2020-03-31 21:23:45 | [diff] [blame] | 42 | |
| 43 | // Returns true if a group of templates are all valid per |
| 44 | // net::dns_util::IsValidDohTemplate(). This should be checked before updating |
| 45 | // stored preferences. |
Ben Schwartz | 135746c | 2020-05-14 04:37:03 | [diff] [blame] | 46 | bool IsValidGroup(base::StringPiece group); |
Ben Schwartz | 4e146861 | 2020-03-31 21:23:45 | [diff] [blame] | 47 | |
Ben Schwartz | 35685c7 | 2020-06-03 04:53:13 | [diff] [blame] | 48 | // When the selected template changes, call this function to update the |
| 49 | // Selected, Unselected, and Ignored histograms for all the included providers, |
| 50 | // and also for the custom provider option. If the old or new selection is the |
| 51 | // custom provider option, pass an empty string as the template. |
| 52 | void UpdateDropdownHistograms(const net::DohProviderEntry::List& providers, |
| 53 | base::StringPiece old_template, |
| 54 | base::StringPiece new_template); |
| 55 | void UpdateValidationHistogram(bool valid); |
| 56 | void UpdateProbeHistogram(bool success); |
| 57 | |
Ben Schwartz | 78ff2568f | 2020-04-30 05:15:18 | [diff] [blame] | 58 | // Modifies |overrides| to use the DoH server specified by |server_template|. |
Ben Schwartz | 135746c | 2020-05-14 04:37:03 | [diff] [blame] | 59 | void ApplyTemplate(net::DnsConfigOverrides* overrides, |
| 60 | base::StringPiece server_template); |
Ben Schwartz | 78ff2568f | 2020-04-30 05:15:18 | [diff] [blame] | 61 | |
Martin Šrámek | 5921f631 | 2020-03-25 09:31:47 | [diff] [blame] | 62 | // Registers the backup preference required for the DNS probes setting reset. |
| 63 | // TODO(crbug.com/1062698): Remove this once the privacy settings redesign |
| 64 | // is fully launched. |
Ben Schwartz | 135746c | 2020-05-14 04:37:03 | [diff] [blame] | 65 | void RegisterProbesSettingBackupPref(PrefRegistrySimple* registry); |
Martin Šrámek | 5921f631 | 2020-03-25 09:31:47 | [diff] [blame] | 66 | |
| 67 | // Backs up the unneeded preference controlling DNS and captive portal probes |
| 68 | // once the privacy settings redesign is enabled, or restores the backup |
| 69 | // in case the feature is rolled back. |
| 70 | // TODO(crbug.com/1062698): Remove this once the privacy settings redesign |
| 71 | // is fully launched. |
Ben Schwartz | 135746c | 2020-05-14 04:37:03 | [diff] [blame] | 72 | void MigrateProbesSettingToOrFromBackup(PrefService* prefs); |
| 73 | |
| 74 | } // namespace secure_dns |
Martin Šrámek | 5921f631 | 2020-03-25 09:31:47 | [diff] [blame] | 75 | |
Steven Bingler | dd2307b | 2019-08-27 20:44:36 | [diff] [blame] | 76 | } // namespace chrome_browser_net |
| 77 | |
Ben Schwartz | 135746c | 2020-05-14 04:37:03 | [diff] [blame] | 78 | #endif // CHROME_BROWSER_NET_SECURE_DNS_UTIL_H_ |