ProjectingObserverChromeos: Drop DBusThreadManager dependency for better testing.
[chromium-blink-merge.git] / components / search_engines / default_search_policy_handler.h
blob1a53a488c385076a9d5385a8806b40c73ddf448f
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_
6 #define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_
8 #include <vector>
10 #include "components/policy/core/browser/configuration_policy_handler.h"
12 namespace policy {
14 // ConfigurationPolicyHandler for the DefaultSearchEncodings policy.
15 class DefaultSearchEncodingsPolicyHandler
16 : public TypeCheckingPolicyHandler {
17 public:
18 DefaultSearchEncodingsPolicyHandler();
19 virtual ~DefaultSearchEncodingsPolicyHandler();
21 // ConfigurationPolicyHandler methods:
22 virtual void ApplyPolicySettings(const PolicyMap& policies,
23 PrefValueMap* prefs) override;
25 private:
26 DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler);
29 // ConfigurationPolicyHandler for the default search policies.
30 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler {
31 public:
32 DefaultSearchPolicyHandler();
33 virtual ~DefaultSearchPolicyHandler();
35 // ConfigurationPolicyHandler methods:
36 virtual bool CheckPolicySettings(const PolicyMap& policies,
37 PolicyErrorMap* errors) override;
38 virtual void ApplyPolicySettings(const PolicyMap& policies,
39 PrefValueMap* prefs) override;
41 private:
42 void HandleDictionaryPref(const PolicyMap& policies, PrefValueMap* prefs);
44 // Calls |CheckPolicySettings()| on each of the handlers in |handlers_|
45 // and returns whether all of the calls succeeded.
46 bool CheckIndividualPolicies(const PolicyMap& policies,
47 PolicyErrorMap* errors);
49 // Returns whether there is a value for |policy_name| in |policies|.
50 bool HasDefaultSearchPolicy(const PolicyMap& policies,
51 const char* policy_name);
53 // Returns whether any default search policies are specified in |policies|.
54 bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies);
56 // Returns whether the default search provider is disabled.
57 bool DefaultSearchProviderIsDisabled(const PolicyMap& policies);
59 // 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.
61 bool DefaultSearchURLIsValid(const PolicyMap& policies,
62 const base::Value** url_value,
63 std::string* url_string);
65 // Make sure that the |path| is present in |prefs_|. If not, set it to
66 // a blank string.
67 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path);
69 // Make sure that the |path| is present in |prefs_| and is a ListValue. If
70 // not, set it to an empty list.
71 void EnsureListPrefExists(PrefValueMap* prefs, const std::string& path);
73 // The ConfigurationPolicyHandler handlers for each default search policy.
74 std::vector<TypeCheckingPolicyHandler*> handlers_;
76 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler);
79 } // namespace policy
81 #endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_