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

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

Powered by Google App Engine
This is Rietveld 408576698