Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / search_engines / default_search_policy_handler.h
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.
4
5 #ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_
6 #define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_
7
8 #include <vector>
9
10 #include "components/policy/core/browser/configuration_policy_handler.h"
11
12 namespace policy {
13
14 // ConfigurationPolicyHandler for the DefaultSearchEncodings policy.
15 class DefaultSearchEncodingsPolicyHandler
16     : public TypeCheckingPolicyHandler {
17  public:
18   DefaultSearchEncodingsPolicyHandler();
19   ~DefaultSearchEncodingsPolicyHandler() override;
20
21   // ConfigurationPolicyHandler methods:
22   void ApplyPolicySettings(const PolicyMap& policies,
23                            PrefValueMap* prefs) override;
24
25  private:
26   DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler);
27 };
28
29 // ConfigurationPolicyHandler for the default search policies.
30 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler {
31  public:
32   DefaultSearchPolicyHandler();
33   ~DefaultSearchPolicyHandler() override;
34
35   // ConfigurationPolicyHandler methods:
36   bool CheckPolicySettings(const PolicyMap& policies,
37                            PolicyErrorMap* errors) override;
38   void ApplyPolicySettings(const PolicyMap& policies,
39                            PrefValueMap* prefs) override;
40
41  private:
42   void HandleDictionaryPref(const PolicyMap& policies, PrefValueMap* prefs);
43
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);
48
49   // Returns whether there is a value for |policy_name| in |policies|.
50   bool HasDefaultSearchPolicy(const PolicyMap& policies,
51                               const char* policy_name);
52
53   // Returns whether any default search policies are specified in |policies|.
54   bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies);
55
56   // Returns whether the default search provider is disabled.
57   bool DefaultSearchProviderIsDisabled(const PolicyMap& policies);
58
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);
64
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);
68
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);
72
73   // The ConfigurationPolicyHandler handlers for each default search policy.
74   std::vector<TypeCheckingPolicyHandler*> handlers_;
75
76   DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler);
77 };
78
79 }  // namespace policy
80
81 #endif  // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_