Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: chrome/browser/policy/configuration_policy_handler.h

Issue 109743002: Move policy code into components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar fixes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_POLICY_CONFIGURATION_POLICY_HANDLER_H_
6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/values.h"
14
15 class PrefValueMap;
16
17 namespace policy {
18
19 class PolicyErrorMap;
20 class PolicyMap;
21
22 // Maps a policy type to a preference path, and to the expected value type.
23 struct PolicyToPreferenceMapEntry {
24 const char* const policy_name;
25 const char* const preference_path;
26 const base::Value::Type value_type;
27 };
28
29 // An abstract super class that subclasses should implement to map policies to
30 // their corresponding preferences, and to check whether the policies are valid.
31 class ConfigurationPolicyHandler {
32 public:
33 static std::string ValueTypeToString(Value::Type type);
34
35 ConfigurationPolicyHandler();
36 virtual ~ConfigurationPolicyHandler();
37
38 // Returns whether the policy settings handled by this
39 // ConfigurationPolicyHandler can be applied. Fills |errors| with error
40 // messages or warnings. |errors| may contain error messages even when
41 // |CheckPolicySettings()| returns true.
42 virtual bool CheckPolicySettings(const PolicyMap& policies,
43 PolicyErrorMap* errors) = 0;
44
45 // Processes the policies handled by this ConfigurationPolicyHandler and sets
46 // the appropriate preferences in |prefs|.
47 virtual void ApplyPolicySettings(const PolicyMap& policies,
48 PrefValueMap* prefs) = 0;
49
50 // Modifies the values of some of the policies in |policies| so that they
51 // are more suitable to display to the user. This can be used to remove
52 // sensitive values such as passwords, or to pretty-print values.
53 virtual void PrepareForDisplaying(PolicyMap* policies) const;
54
55 private:
56 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler);
57 };
58
59 // Abstract class derived from ConfigurationPolicyHandler that should be
60 // subclassed to handle a single policy (not a combination of policies).
61 class TypeCheckingPolicyHandler : public ConfigurationPolicyHandler {
62 public:
63 TypeCheckingPolicyHandler(const char* policy_name,
64 base::Value::Type value_type);
65 virtual ~TypeCheckingPolicyHandler();
66
67 // ConfigurationPolicyHandler methods:
68 virtual bool CheckPolicySettings(const PolicyMap& policies,
69 PolicyErrorMap* errors) OVERRIDE;
70
71 const char* policy_name() const;
72
73 protected:
74 // Runs policy checks and returns the policy value if successful.
75 bool CheckAndGetValue(const PolicyMap& policies,
76 PolicyErrorMap* errors,
77 const Value** value);
78
79 private:
80 // The name of the policy.
81 const char* policy_name_;
82
83 // The type the value of the policy should have.
84 base::Value::Type value_type_;
85
86 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler);
87 };
88
89 // Abstract class derived from TypeCheckingPolicyHandler that ensures an int
90 // policy's value lies in an allowed range. Either clamps or rejects values
91 // outside the range.
92 class IntRangePolicyHandlerBase : public TypeCheckingPolicyHandler {
93 public:
94 IntRangePolicyHandlerBase(const char* policy_name,
95 int min,
96 int max,
97 bool clamp);
98
99 // ConfigurationPolicyHandler:
100 virtual bool CheckPolicySettings(const PolicyMap& policies,
101 PolicyErrorMap* errors) OVERRIDE;
102
103 protected:
104 virtual ~IntRangePolicyHandlerBase();
105
106 // Ensures that the value is in the allowed range. Returns false if the value
107 // cannot be parsed or lies outside the allowed range and clamping is
108 // disabled.
109 bool EnsureInRange(const base::Value* input,
110 int* output,
111 PolicyErrorMap* errors);
112
113 private:
114 // The minimum value allowed.
115 int min_;
116
117 // The maximum value allowed.
118 int max_;
119
120 // Whether to clamp values lying outside the allowed range instead of
121 // rejecting them.
122 bool clamp_;
123
124 DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandlerBase);
125 };
126
127 // ConfigurationPolicyHandler for policies that map directly to a preference.
128 class SimplePolicyHandler : public TypeCheckingPolicyHandler {
129 public:
130 SimplePolicyHandler(const char* policy_name,
131 const char* pref_path,
132 base::Value::Type value_type);
133 virtual ~SimplePolicyHandler();
134
135 // ConfigurationPolicyHandler methods:
136 virtual void ApplyPolicySettings(const PolicyMap& policies,
137 PrefValueMap* prefs) OVERRIDE;
138
139 private:
140 // The DictionaryValue path of the preference the policy maps to.
141 const char* pref_path_;
142
143 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler);
144 };
145
146 // A policy handler implementation that maps a string enum list to an int enum
147 // list as specified by a mapping table.
148 class StringToIntEnumListPolicyHandler : public TypeCheckingPolicyHandler {
149 public:
150 struct MappingEntry {
151 const char* enum_value;
152 int int_value;
153 };
154
155 StringToIntEnumListPolicyHandler(const char* policy_name,
156 const char* pref_path,
157 const MappingEntry* mapping_begin,
158 const MappingEntry* mapping_end);
159
160 // ConfigurationPolicyHandler methods:
161 virtual bool CheckPolicySettings(const PolicyMap& policies,
162 PolicyErrorMap* errors) OVERRIDE;
163 virtual void ApplyPolicySettings(const PolicyMap& policies,
164 PrefValueMap* prefs) OVERRIDE;
165
166 private:
167 // Attempts to convert the list in |input| to |output| according to the table,
168 // returns false on errors.
169 bool Convert(const base::Value* input,
170 base::ListValue* output,
171 PolicyErrorMap* errors);
172
173 // Name of the pref to write.
174 const char* pref_path_;
175
176 // The mapping table.
177 const MappingEntry* mapping_begin_;
178 const MappingEntry* mapping_end_;
179
180 DISALLOW_COPY_AND_ASSIGN(StringToIntEnumListPolicyHandler);
181 };
182
183 // A policy handler implementation that ensures an int policy's value lies in an
184 // allowed range.
185 class IntRangePolicyHandler : public IntRangePolicyHandlerBase {
186 public:
187 IntRangePolicyHandler(const char* policy_name,
188 const char* pref_path,
189 int min,
190 int max,
191 bool clamp);
192 virtual ~IntRangePolicyHandler();
193
194 // ConfigurationPolicyHandler:
195 virtual void ApplyPolicySettings(const PolicyMap& policies,
196 PrefValueMap* prefs) OVERRIDE;
197
198 private:
199 // Name of the pref to write.
200 const char* pref_path_;
201
202 DISALLOW_COPY_AND_ASSIGN(IntRangePolicyHandler);
203 };
204
205 // A policy handler implementation that maps an int percentage value to a
206 // double.
207 class IntPercentageToDoublePolicyHandler : public IntRangePolicyHandlerBase {
208 public:
209 IntPercentageToDoublePolicyHandler(const char* policy_name,
210 const char* pref_path,
211 int min,
212 int max,
213 bool clamp);
214 virtual ~IntPercentageToDoublePolicyHandler();
215
216 // ConfigurationPolicyHandler:
217 virtual void ApplyPolicySettings(const PolicyMap& policies,
218 PrefValueMap* prefs) OVERRIDE;
219
220 private:
221 // Name of the pref to write.
222 const char* pref_path_;
223
224 DISALLOW_COPY_AND_ASSIGN(IntPercentageToDoublePolicyHandler);
225 };
226
227 } // namespace policy
228
229 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/config_dir_policy_loader_unittest.cc ('k') | chrome/browser/policy/configuration_policy_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698