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

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

Issue 7972013: ConfigurationPolicyPrefStore refactoring to surface error messages. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 9 years, 3 months 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) 2011 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 #pragma once
8
9 #include <string>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
13 #include "chrome/browser/policy/configuration_policy_handler_interface.h"
14 #include "chrome/browser/policy/policy_error_map.h"
15 #include "chrome/browser/policy/policy_map.h"
16 #include "chrome/browser/prefs/incognito_mode_prefs.h"
17 #include "chrome/browser/prefs/pref_value_map.h"
18 #include "policy/configuration_policy_type.h"
19
20 namespace policy {
21
22 // Abstract class derived from ConfigurationPolicyHandlerInterface that should
23 // be subclassed to handle a single policy (not a combination of policies).
24 class TypeCheckingPolicyHandler : public ConfigurationPolicyHandlerInterface {
25 public:
26 TypeCheckingPolicyHandler(ConfigurationPolicyType policy,
27 base::Value::Type value_type);
28
29 // ConfigurationPolicyHandlerInterface method. Returns true if the value of
30 // the policy is of the correct type and false otherwise.
31 virtual bool CheckPolicySettings(const PolicyMap* policies,
32 PolicyErrorMap* errors) OVERRIDE;
33 virtual void ApplyPolicySettings(const PolicyMap* policies,
34 PrefValueMap* prefs) OVERRIDE;
35 virtual void ApplyPolicyValue(PrefValueMap* prefs, const Value* value) = 0;
Mattias Nissler (ping if slow) 2011/09/26 13:30:48 Please document.
simo 2011/09/29 09:33:08 Done.
36
37 protected:
38 virtual ~TypeCheckingPolicyHandler();
39
40 ConfigurationPolicyType policy_type() const;
41
42 private:
43 static std::string ValueTypeToString(Value::Type type);
44
45 // The ConfigurationPolicyType of the policy.
46 ConfigurationPolicyType policy_type_;
47
48 // The type the value of the policy should have.
49 base::Value::Type value_type_;
50
51 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler );
52 };
53
54 // ConfigurationPolicyHandlerInterface implementation for policies that map
55 // directly to a preference.
56 class SimplePolicyHandler : public TypeCheckingPolicyHandler {
57 public:
58 SimplePolicyHandler(ConfigurationPolicyType policy,
59 base::Value::Type value_type,
60 const char* pref_path);
61 virtual ~SimplePolicyHandler();
62
63 // ConfigurationPolicyHandlerInterface method:
Mattias Nissler (ping if slow) 2011/09/26 13:30:48 This is actually a TypeCheckingPolicyHandler overr
simo 2011/09/29 09:33:08 Done.
64 virtual void ApplyPolicyValue(PrefValueMap* prefs,
65 const Value* value) OVERRIDE;
66
67 private:
68 // The DictionaryValue path of the preference the policy maps to.
69 const char* pref_path_;
70
71 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler);
72 };
73
74 // ConfigurationPolicyHandlerInterface implementation for the SyncDisabled
75 // policy.
76 class SyncPolicyHandler : public TypeCheckingPolicyHandler {
77 public:
78 SyncPolicyHandler();
79 virtual ~SyncPolicyHandler();
80
81 // TypeCheckingPolicyHandler method:
82 virtual void ApplyPolicyValue(PrefValueMap* prefs,
83 const Value* value) OVERRIDE;
84
85 private:
86 DISALLOW_COPY_AND_ASSIGN(SyncPolicyHandler);
87 };
88
89 // ConfigurationPolicyHandlerInterface implementation for the AutofillEnabled
90 // policy.
91 class AutofillPolicyHandler : public TypeCheckingPolicyHandler {
92 public:
93 AutofillPolicyHandler();
94 virtual ~AutofillPolicyHandler();
95
96 // ConfigurationPolicyHandlerInterface method:
97 // virtual void ApplyPolicySettings(const PolicyMap* policies,
98 // PrefValueMap* prefs) OVERRIDE;
Mattias Nissler (ping if slow) 2011/09/26 13:30:48 remove old code.
simo 2011/09/29 09:33:08 Done.
99 virtual void ApplyPolicyValue(PrefValueMap* prefs,
100 const Value* value) OVERRIDE;
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(AutofillPolicyHandler);
104 };
105
106 // ConfigurationPolicyHandlerInterface implementation for the DownloadDirectory
107 // policy.
108 class DownloadDirPolicyHandler : public TypeCheckingPolicyHandler {
109 public:
110 DownloadDirPolicyHandler();
111 virtual ~DownloadDirPolicyHandler();
112
Mattias Nissler (ping if slow) 2011/09/26 13:30:48 remove extra newline
simo 2011/09/29 09:33:08 Done.
113
114 // TypeCheckingPolicyHandler methods:
115 virtual bool CheckPolicySettings(const PolicyMap* map,
116 PolicyErrorMap* errors) OVERRIDE;
117 virtual void ApplyPolicyValue(PrefValueMap* prefs,
118 const Value* value) OVERRIDE;
119
120 private:
121 DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler);
122 };
123
124 // ConfigurationPolicyHandlerInterface implementation for the DiskCacheDir
125 // policy.
126 class DiskCacheDirPolicyHandler : public TypeCheckingPolicyHandler {
127 public:
128 explicit DiskCacheDirPolicyHandler();
129 virtual ~DiskCacheDirPolicyHandler();
130
131 // TypeCheckingPolicyHandler method:
132 virtual void ApplyPolicyValue(PrefValueMap* prefs,
133 const Value* value) OVERRIDE;
134
135 private:
136 DISALLOW_COPY_AND_ASSIGN(DiskCacheDirPolicyHandler);
137 };
138
139 // ConfigurationPolicyHandlerInterface implementation for the
140 // FileSelectionDialogsHandler policy.
141 class FileSelectionDialogsHandler : public TypeCheckingPolicyHandler {
142 public:
143 FileSelectionDialogsHandler();
144 virtual ~FileSelectionDialogsHandler();
145
146 // TypeCheckingPolicyHandler method:
147 virtual void ApplyPolicyValue(PrefValueMap* prefs,
148 const Value* value) OVERRIDE;
149
150 private:
151 DISALLOW_COPY_AND_ASSIGN(FileSelectionDialogsHandler);
152 };
153
154 // ConfigurationPolicyHandlerInterface implementation for the BookmarkBarEnabled
155 // policy.
156 class BookmarksPolicyHandler : public TypeCheckingPolicyHandler {
157 public:
158 BookmarksPolicyHandler();
159 virtual ~BookmarksPolicyHandler();
160
161 // TypeCheckingPolicyHandler method:
162 virtual void ApplyPolicyValue(PrefValueMap* prefs,
163 const Value* value) OVERRIDE;
164
165 private:
166 DISALLOW_COPY_AND_ASSIGN(BookmarksPolicyHandler);
167 };
168
169 // ConfigurationPolicyHandlerInterface implementation for the incognito mode
170 // policies.
171 class IncognitoModePolicyHandler : public ConfigurationPolicyHandlerInterface {
172 public:
173 IncognitoModePolicyHandler();
174 virtual ~IncognitoModePolicyHandler();
175
176 // TypeCheckingPolicyHandler methods:
177 virtual bool CheckPolicySettings(const PolicyMap* policies,
178 PolicyErrorMap* errors) OVERRIDE;
179 virtual void ApplyPolicySettings(const PolicyMap* policies,
180 PrefValueMap* prefs) OVERRIDE;
181
182 private:
183 IncognitoModePrefs::Availability GetAvailabilityValueAsEnum(
184 const Value* availability);
185
186 DISALLOW_COPY_AND_ASSIGN(IncognitoModePolicyHandler);
187 };
188
189 // ConfigurationPolicyHandlerInterface implementation for the
190 // DefaultSearchEncodings policy.
191 class DefaultSearchEncodingsPolicyHandler : public TypeCheckingPolicyHandler {
192 public:
193 DefaultSearchEncodingsPolicyHandler();
194 virtual ~DefaultSearchEncodingsPolicyHandler();
195
196 // TypeCheckingPolicyHandler method:
197 virtual void ApplyPolicyValue(PrefValueMap* prefs,
198 const Value* value) OVERRIDE;
199
200 private:
201 DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler);
202 };
203
204 // ConfigurationPolicyHandlerInterface implementation for the default search
205 // policies.
206 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandlerInterface {
207 public:
208 DefaultSearchPolicyHandler();
209 virtual ~DefaultSearchPolicyHandler();
210
211 // ConfigurationPolicyHandlerInterface methods:
212 virtual bool CheckPolicySettings(const PolicyMap* policies,
213 PolicyErrorMap* errors) OVERRIDE;
214 virtual void ApplyPolicySettings(const PolicyMap* policies,
215 PrefValueMap* prefs) OVERRIDE;
216
217 private:
218 typedef std::vector<ConfigurationPolicyHandlerInterface*> HandlerList;
219
220 // Calls |CheckPolicySettings()| on each of the handlers in |handlers_|
221 // and returns true if all of the calls return true and false otherwise.
222 bool CheckIndividualPolicies(const PolicyMap* policies,
223 PolicyErrorMap* errors);
224
225 // Returns true if the default search provider is disabled and false
226 // otherwise.
227 bool DefaultSearchProviderIsDisabled(const PolicyMap* policies);
228
229 // Returns true if the default search URL was set and is valid and false
230 // otherwise.
231 bool DefaultSearchURLIsPresentAndValid(const PolicyMap* policies);
232
233 // Make sure that the |path| if present in |prefs_|. If not, set it to
234 // a blank string.
235 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path);
236
237 // Copies all default search preferences in |temp_prefs| to |prefs|.
238 void CopyTempPrefsToRealPrefs(PrefValueMap* temp_prefs, PrefValueMap* prefs);
239
240 // Clears all default search preferences in |prefs|.
241 void ClearDefaultSearchPreferences(PrefValueMap* prefs);
242
243 // The ConfigurationPolicyHandlerInterface handlers for each of default search
244 // policies.
245 HandlerList handlers_;
246
247 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler);
248 };
249
250 // ConfigurationPolicyHandlerInterface implementation for the proxy policies.
251 class ProxyPolicyHandler : public ConfigurationPolicyHandlerInterface {
252 public:
253 ProxyPolicyHandler();
254 virtual ~ProxyPolicyHandler();
255
256 // ConfigurationPolicyHandlerInterface methods:
257 virtual bool CheckPolicySettings(const PolicyMap* policies,
258 PolicyErrorMap* errors) OVERRIDE;
259 virtual void ApplyPolicySettings(const PolicyMap* policies,
260 PrefValueMap* prefs) OVERRIDE;
261
262 private:
263 const Value* GetProxyPolicyValue(const PolicyMap* policies,
264 ConfigurationPolicyType policy);
265
266 // Converts the deprecated ProxyServerMode policy value to a ProxyMode value
267 // and places the result in |mode_value|. Returns true if the conversion
268 // succeeded and false otherwise.
269 bool CheckProxyModeAndServerMode(const PolicyMap* policies,
270 PolicyErrorMap* errors,
271 std::string* mode_value);
272
273 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler);
274 };
275
276 } // namespace policy
277
278 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698