| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_ | 5 #ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_ |
| 6 #define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_ | 6 #define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "components/policy/core/browser/configuration_policy_handler.h" | 12 #include "components/policy/core/browser/configuration_policy_handler.h" |
| 13 | 13 |
| 14 namespace policy { | 14 namespace policy { |
| 15 | 15 |
| 16 // ConfigurationPolicyHandler for the DefaultSearchEncodings policy. | |
| 17 class DefaultSearchEncodingsPolicyHandler | |
| 18 : public TypeCheckingPolicyHandler { | |
| 19 public: | |
| 20 DefaultSearchEncodingsPolicyHandler(); | |
| 21 ~DefaultSearchEncodingsPolicyHandler() override; | |
| 22 | |
| 23 // ConfigurationPolicyHandler methods: | |
| 24 void ApplyPolicySettings(const PolicyMap& policies, | |
| 25 PrefValueMap* prefs) override; | |
| 26 | |
| 27 private: | |
| 28 DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler); | |
| 29 }; | |
| 30 | |
| 31 // ConfigurationPolicyHandler for the default search policies. | 16 // ConfigurationPolicyHandler for the default search policies. |
| 32 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler { | 17 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler { |
| 33 public: | 18 public: |
| 34 DefaultSearchPolicyHandler(); | 19 DefaultSearchPolicyHandler(); |
| 35 ~DefaultSearchPolicyHandler() override; | 20 ~DefaultSearchPolicyHandler() override; |
| 36 | 21 |
| 37 // ConfigurationPolicyHandler methods: | 22 // ConfigurationPolicyHandler methods: |
| 38 bool CheckPolicySettings(const PolicyMap& policies, | 23 bool CheckPolicySettings(const PolicyMap& policies, |
| 39 PolicyErrorMap* errors) override; | 24 PolicyErrorMap* errors) override; |
| 40 void ApplyPolicySettings(const PolicyMap& policies, | 25 void ApplyPolicySettings(const PolicyMap& policies, |
| 41 PrefValueMap* prefs) override; | 26 PrefValueMap* prefs) override; |
| 42 | 27 |
| 43 private: | 28 private: |
| 44 // Calls |CheckPolicySettings()| on each of the handlers in |handlers_| | 29 // Checks that value type is valid for each policy and returns whether all of |
| 45 // and returns whether all of the calls succeeded. | 30 // the policies are valid. |
| 46 bool CheckIndividualPolicies(const PolicyMap& policies, | 31 bool CheckIndividualPolicies(const PolicyMap& policies, |
| 47 PolicyErrorMap* errors); | 32 PolicyErrorMap* errors); |
| 48 | 33 |
| 49 // Returns whether there is a value for |policy_name| in |policies|. | 34 // Returns whether there is a value for |policy_name| in |policies|. |
| 50 bool HasDefaultSearchPolicy(const PolicyMap& policies, | 35 bool HasDefaultSearchPolicy(const PolicyMap& policies, |
| 51 const char* policy_name); | 36 const char* policy_name); |
| 52 | 37 |
| 53 // Returns whether any default search policies are specified in |policies|. | 38 // Returns whether any default search policies are specified in |policies|. |
| 54 bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies); | 39 bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies); |
| 55 | 40 |
| 56 // Returns whether the default search provider is disabled. | 41 // Returns whether the default search provider is disabled. |
| 57 bool DefaultSearchProviderIsDisabled(const PolicyMap& policies); | 42 bool DefaultSearchProviderIsDisabled(const PolicyMap& policies); |
| 58 | 43 |
| 59 // Returns whether the default search URL is set and valid. On success, both | 44 // Returns whether the default search URL is set and valid. On success, both |
| 60 // outparams (which must be non-NULL) are filled with the search URL. | 45 // outparams (which must be non-NULL) are filled with the search URL. |
| 61 bool DefaultSearchURLIsValid(const PolicyMap& policies, | 46 bool DefaultSearchURLIsValid(const PolicyMap& policies, |
| 62 const base::Value** url_value, | 47 const base::Value** url_value, |
| 63 std::string* url_string); | 48 std::string* url_string); |
| 64 | 49 |
| 65 // Make sure that the |path| is present in |prefs_|. If not, set it to | 50 // Make sure that the |path| is present in |prefs_|. If not, set it to |
| 66 // a blank string. | 51 // a blank string. |
| 67 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); | 52 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); |
| 68 | 53 |
| 69 // Make sure that the |path| is present in |prefs_| and is a ListValue. If | 54 // Make sure that the |path| is present in |prefs_| and is a ListValue. If |
| 70 // not, set it to an empty list. | 55 // not, set it to an empty list. |
| 71 void EnsureListPrefExists(PrefValueMap* prefs, const std::string& path); | 56 void EnsureListPrefExists(PrefValueMap* prefs, const std::string& path); |
| 72 | 57 |
| 73 // The ConfigurationPolicyHandler handlers for each default search policy. | |
| 74 std::vector<std::unique_ptr<TypeCheckingPolicyHandler>> handlers_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); | 58 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); |
| 77 }; | 59 }; |
| 78 | 60 |
| 79 } // namespace policy | 61 } // namespace policy |
| 80 | 62 |
| 81 #endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_ | 63 #endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_ |
| OLD | NEW |