- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / search_engines / default_search_policy_handler.h
1 // Copyright 2013 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 CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_
7
8 #include <vector>
9
10 #include "chrome/browser/policy/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   virtual ~DefaultSearchEncodingsPolicyHandler();
20
21   // ConfigurationPolicyHandler methods:
22   virtual 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   virtual ~DefaultSearchPolicyHandler();
34
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;
40
41  private:
42   // Calls |CheckPolicySettings()| on each of the handlers in |handlers_|
43   // and returns whether all of the calls succeeded.
44   bool CheckIndividualPolicies(const PolicyMap& policies,
45                                PolicyErrorMap* errors);
46
47   // Returns whether there is a value for |policy_name| in |policies|.
48   bool HasDefaultSearchPolicy(const PolicyMap& policies,
49                               const char* policy_name);
50
51   // Returns whether any default search policies are specified in |policies|.
52   bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies);
53
54   // Returns whether the default search provider is disabled.
55   bool DefaultSearchProviderIsDisabled(const PolicyMap& policies);
56
57   // Returns whether the default search URL is set and valid.  On success, both
58   // outparams (which must be non-NULL) are filled with the search URL.
59   bool DefaultSearchURLIsValid(const PolicyMap& policies,
60                                const Value** url_value,
61                                std::string* url_string);
62
63   // Make sure that the |path| is present in |prefs_|.  If not, set it to
64   // a blank string.
65   void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path);
66
67   // Make sure that the |path| is present in |prefs_| and is a ListValue.  If
68   // not, set it to an empty list.
69   void EnsureListPrefExists(PrefValueMap* prefs, const std::string& path);
70
71   // The ConfigurationPolicyHandler handlers for each default search policy.
72   std::vector<TypeCheckingPolicyHandler*> handlers_;
73
74   DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler);
75 };
76
77 }  // namespace policy
78
79 #endif  // CHROME_BROWSER_SEARCH_ENGINES_DEFAULT_SEARCH_POLICY_HANDLER_H_