Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Steven Bingler | ace5fd2 | 2019-08-20 21:01:20 | [diff] [blame] | 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 CHROME_BROWSER_NET_SECURE_DNS_POLICY_HANDLER_H_ |
| 6 | #define CHROME_BROWSER_NET_SECURE_DNS_POLICY_HANDLER_H_ |
| 7 | |
Helmut Januschka | 52aa1302 | 2024-03-19 00:29:19 | [diff] [blame] | 8 | #include <string_view> |
| 9 | |
Andreea Costinas | 6a54f7a | 2022-11-23 11:23:18 | [diff] [blame] | 10 | #include "build/chromeos_buildflags.h" |
Steven Bingler | ace5fd2 | 2019-08-20 21:01:20 | [diff] [blame] | 11 | #include "components/policy/core/browser/configuration_policy_handler.h" |
| 12 | |
| 13 | class PrefValueMap; |
| 14 | |
| 15 | namespace policy { |
| 16 | |
Andreea Costinas | 6a54f7a | 2022-11-23 11:23:18 | [diff] [blame] | 17 | // Handles DnsOverHttpsMode, DnsOverHttpsTemplates, |
| 18 | // DnsOverHttpsTemplatesWithIdentifiers and DnsOverHttpsSalt policies. |
Steven Bingler | ace5fd2 | 2019-08-20 21:01:20 | [diff] [blame] | 19 | class SecureDnsPolicyHandler : public ConfigurationPolicyHandler { |
| 20 | public: |
| 21 | SecureDnsPolicyHandler(); |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 22 | |
| 23 | SecureDnsPolicyHandler(const SecureDnsPolicyHandler&) = delete; |
| 24 | SecureDnsPolicyHandler& operator=(const SecureDnsPolicyHandler&) = delete; |
| 25 | |
Steven Bingler | ace5fd2 | 2019-08-20 21:01:20 | [diff] [blame] | 26 | ~SecureDnsPolicyHandler() override; |
| 27 | |
| 28 | // ConfigurationPolicyHandler methods: |
| 29 | bool CheckPolicySettings(const PolicyMap& policies, |
| 30 | PolicyErrorMap* errors) override; |
| 31 | void ApplyPolicySettings(const PolicyMap& policies, |
| 32 | PrefValueMap* prefs) override; |
| 33 | |
| 34 | private: |
Andreea Costinas | 6a54f7a | 2022-11-23 11:23:18 | [diff] [blame] | 35 | // Returns true if templates must be specified (i.e. `mode_str` is secure), |
| 36 | // but they are not set or invalid (non-string). |
| 37 | bool IsTemplatesPolicyNotSpecified(bool is_templates_policy_valid, |
Tom Sepez | b55f2f1 | 2024-10-02 21:54:33 | [diff] [blame] | 38 | std::string_view mode_str); |
Andreea Costinas | 6a54f7a | 2022-11-23 11:23:18 | [diff] [blame] | 39 | // Indicates whether the DnsOverHttpsTemplates policy is valid and can be |
| 40 | // applied. If not, the corresponding pref is not set. If the DNS mode is |
| 41 | // secure, either `is_templates_policy_valid_` or, on Chrome OS only, |
| 42 | // `is_templates_with_identifiers_policy_valid_` must be true, otherwise |
| 43 | // `CheckPolicySettings` will report a policy error. Set in |
| 44 | // `CheckPolicySettings`. |
| 45 | bool is_templates_policy_valid_ = false; |
Steven Bingler | bb471bc6 | 2019-10-30 16:11:09 | [diff] [blame] | 46 | |
Andrew Williams | 41c8b0c | 2025-01-07 18:20:30 | [diff] [blame] | 47 | #if BUILDFLAG(IS_CHROMEOS) |
Andreea Costinas | 6a54f7a | 2022-11-23 11:23:18 | [diff] [blame] | 48 | // Indicates whether the DnsOverHttpsTemplatesWithIdentifiers policy is valid |
| 49 | // and can be applied. If not, the corresponding pref is not set. Set in |
| 50 | // `CheckPolicySettings`. |
| 51 | bool is_templates_with_identifiers_policy_valid_ = false; |
| 52 | #endif |
Steven Bingler | ace5fd2 | 2019-08-20 21:01:20 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | } // namespace policy |
| 56 | |
| 57 | #endif // CHROME_BROWSER_NET_SECURE_DNS_POLICY_HANDLER_H_ |