Upload upstream chromium 67.0.3396
[platform/framework/web/chromium-efl.git] / 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 <memory>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "components/policy/core/browser/configuration_policy_handler.h"
13
14 namespace policy {
15
16 // ConfigurationPolicyHandler for the default search policies.
17 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler {
18  public:
19   DefaultSearchPolicyHandler();
20   ~DefaultSearchPolicyHandler() override;
21
22   // ConfigurationPolicyHandler methods:
23   bool CheckPolicySettings(const PolicyMap& policies,
24                            PolicyErrorMap* errors) override;
25   void ApplyPolicySettings(const PolicyMap& policies,
26                            PrefValueMap* prefs) override;
27
28  private:
29   // Checks that value type is valid for each policy and returns whether all of
30   // the policies are valid.
31   bool CheckIndividualPolicies(const PolicyMap& policies,
32                                PolicyErrorMap* errors);
33
34   // Returns whether there is a value for |policy_name| in |policies|.
35   bool HasDefaultSearchPolicy(const PolicyMap& policies,
36                               const char* policy_name);
37
38   // Returns whether any default search policies are specified in |policies|.
39   bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies);
40
41   // Returns whether the default search provider policy has a value.
42   bool DefaultSearchProviderPolicyIsSet(const PolicyMap& policies);
43
44   // Returns whether the default search provider is disabled.
45   bool DefaultSearchProviderIsDisabled(const PolicyMap& policies);
46
47   // Returns whether the default search URL is set and valid.  On success, both
48   // outparams (which must be non-NULL) are filled with the search URL.
49   bool DefaultSearchURLIsValid(const PolicyMap& policies,
50                                const base::Value** url_value,
51                                std::string* url_string);
52
53   // Make sure that the |path| is present in |prefs_|.  If not, set it to
54   // a blank string.
55   void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path);
56
57   // Make sure that the |path| is present in |prefs_| and is a ListValue.  If
58   // not, set it to an empty list.
59   void EnsureListPrefExists(PrefValueMap* prefs, const std::string& path);
60
61   DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler);
62 };
63
64 }  // namespace policy
65
66 #endif  // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_