OLD | NEW |
---|---|
(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; | |
Mattias Nissler (ping if slow)
2011/09/30 13:33:35
Hm, why did the simpler Apply disappear from here?
| |
33 | |
34 protected: | |
35 virtual ~TypeCheckingPolicyHandler(); | |
36 | |
37 ConfigurationPolicyType policy_type() const; | |
38 | |
39 private: | |
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 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler ); | |
47 }; | |
48 | |
49 // ConfigurationPolicyHandlerInterface implementation for policies that map | |
50 // directly to a preference. | |
51 class SimplePolicyHandler : public TypeCheckingPolicyHandler { | |
52 public: | |
53 SimplePolicyHandler(ConfigurationPolicyType policy, | |
54 base::Value::Type value_type, | |
55 const char* pref_path); | |
56 virtual ~SimplePolicyHandler(); | |
57 | |
58 // ConfigurationPolicyHandlerInterface methods: | |
59 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
60 PrefValueMap* prefs) OVERRIDE; | |
61 | |
62 private: | |
63 // The DictionaryValue path of the preference the policy maps to. | |
64 const char* pref_path_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); | |
67 }; | |
68 | |
69 // ConfigurationPolicyHandlerInterface implementation for the SyncDisabled | |
70 // policy. | |
71 class SyncPolicyHandler : public TypeCheckingPolicyHandler { | |
72 public: | |
73 SyncPolicyHandler(); | |
74 virtual ~SyncPolicyHandler(); | |
75 | |
76 // ConfigurationPolicyHandlerInterface methods: | |
77 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
78 PrefValueMap* prefs) OVERRIDE; | |
79 | |
80 private: | |
81 DISALLOW_COPY_AND_ASSIGN(SyncPolicyHandler); | |
82 }; | |
83 | |
84 // ConfigurationPolicyHandlerInterface implementation for the AutofillEnabled | |
85 // policy. | |
86 class AutofillPolicyHandler : public TypeCheckingPolicyHandler { | |
87 public: | |
88 AutofillPolicyHandler(); | |
89 virtual ~AutofillPolicyHandler(); | |
90 | |
91 // ConfigurationPolicyHandlerInterface methods: | |
92 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
93 PrefValueMap* prefs) OVERRIDE; | |
94 | |
95 private: | |
96 DISALLOW_COPY_AND_ASSIGN(AutofillPolicyHandler); | |
97 }; | |
98 | |
99 // ConfigurationPolicyHandlerInterface implementation for the DownloadDirectory | |
100 // policy. | |
101 class DownloadDirPolicyHandler : public TypeCheckingPolicyHandler { | |
102 public: | |
103 DownloadDirPolicyHandler(); | |
104 virtual ~DownloadDirPolicyHandler(); | |
105 | |
106 // ConfigurationPolicyHandlerInterface methods: | |
107 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
108 PrefValueMap* prefs) OVERRIDE; | |
109 | |
110 private: | |
111 DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler); | |
112 }; | |
113 | |
114 // ConfigurationPolicyHandlerInterface implementation for the DiskCacheDir | |
115 // policy. | |
116 class DiskCacheDirPolicyHandler : public TypeCheckingPolicyHandler { | |
117 public: | |
118 explicit DiskCacheDirPolicyHandler(); | |
119 virtual ~DiskCacheDirPolicyHandler(); | |
120 | |
121 // ConfigurationPolicyHandlerInterface methods: | |
122 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
123 PrefValueMap* prefs) OVERRIDE; | |
124 | |
125 private: | |
126 DISALLOW_COPY_AND_ASSIGN(DiskCacheDirPolicyHandler); | |
127 }; | |
128 | |
129 // ConfigurationPolicyHandlerInterface implementation for the | |
130 // FileSelectionDialogsHandler policy. | |
131 class FileSelectionDialogsHandler : public TypeCheckingPolicyHandler { | |
132 public: | |
133 FileSelectionDialogsHandler(); | |
134 virtual ~FileSelectionDialogsHandler(); | |
135 | |
136 // ConfigurationPolicyHandlerInterface methods: | |
137 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
138 PrefValueMap* prefs) OVERRIDE; | |
139 | |
140 private: | |
141 DISALLOW_COPY_AND_ASSIGN(FileSelectionDialogsHandler); | |
142 }; | |
143 | |
144 // ConfigurationPolicyHandlerInterface implementation for the BookmarkBarEnabled | |
145 // policy. | |
146 class BookmarksPolicyHandler : public TypeCheckingPolicyHandler { | |
147 public: | |
148 BookmarksPolicyHandler(); | |
149 virtual ~BookmarksPolicyHandler(); | |
150 | |
151 // ConfigurationPolicyHandlerInterface methods: | |
152 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
153 PrefValueMap* prefs) OVERRIDE; | |
154 | |
155 private: | |
156 DISALLOW_COPY_AND_ASSIGN(BookmarksPolicyHandler); | |
157 }; | |
158 | |
159 // ConfigurationPolicyHandlerInterface implementation for the incognito mode | |
160 // policies. | |
161 class IncognitoModePolicyHandler : public ConfigurationPolicyHandlerInterface { | |
162 public: | |
163 IncognitoModePolicyHandler(); | |
164 virtual ~IncognitoModePolicyHandler(); | |
165 | |
166 // ConfigurationPolicyHandlerInterface methods: | |
167 virtual bool CheckPolicySettings(const PolicyMap* policies, | |
168 PolicyErrorMap* errors) OVERRIDE; | |
169 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
170 PrefValueMap* prefs) OVERRIDE; | |
171 | |
172 private: | |
173 IncognitoModePrefs::Availability GetAvailabilityValueAsEnum( | |
174 const Value* availability); | |
175 | |
176 DISALLOW_COPY_AND_ASSIGN(IncognitoModePolicyHandler); | |
177 }; | |
178 | |
179 // ConfigurationPolicyHandlerInterface implementation for the | |
180 // DefaultSearchEncodings policy. | |
181 class DefaultSearchEncodingsPolicyHandler : public TypeCheckingPolicyHandler { | |
182 public: | |
183 DefaultSearchEncodingsPolicyHandler(); | |
184 virtual ~DefaultSearchEncodingsPolicyHandler(); | |
185 | |
186 // ConfigurationPolicyHandlerInterface methods: | |
187 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
188 PrefValueMap* prefs) OVERRIDE; | |
189 | |
190 private: | |
191 DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler); | |
192 }; | |
193 | |
194 // ConfigurationPolicyHandlerInterface implementation for the default search | |
195 // policies. | |
196 class DefaultSearchPolicyHandler : public ConfigurationPolicyHandlerInterface { | |
197 public: | |
198 DefaultSearchPolicyHandler(); | |
199 virtual ~DefaultSearchPolicyHandler(); | |
200 | |
201 // ConfigurationPolicyHandlerInterface methods: | |
202 virtual bool CheckPolicySettings(const PolicyMap* policies, | |
203 PolicyErrorMap* errors) OVERRIDE; | |
204 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
205 PrefValueMap* prefs) OVERRIDE; | |
206 | |
207 private: | |
208 typedef std::vector<ConfigurationPolicyHandlerInterface*> HandlerList; | |
209 | |
210 // Calls |CheckPolicySettings()| on each of the handlers in |handlers_| | |
211 // and returns true if all of the calls return true and false otherwise. | |
212 bool CheckIndividualPolicies(const PolicyMap* policies, | |
213 PolicyErrorMap* errors); | |
214 | |
215 // Returns true if there is a value for |policy_type| in |policies| and false | |
216 // otherwise. | |
217 bool HasDefaultSearchPolicy(const PolicyMap* policies, | |
218 ConfigurationPolicyType policy_type); | |
219 | |
220 // Returns true if any default search policies are specified in |policies| and | |
221 // false otherwise. | |
222 bool AnyDefaultSearchPoliciesSpecified(const PolicyMap* policies); | |
223 | |
224 // Returns true if the default search provider is disabled and false | |
225 // otherwise. | |
226 bool DefaultSearchProviderIsDisabled(const PolicyMap* policies); | |
227 | |
228 // Returns true if the default search URL was set and is valid and false | |
229 // otherwise. | |
230 bool DefaultSearchURLIsValid(const PolicyMap* policies); | |
231 | |
232 // Make sure that the |path| if present in |prefs_|. If not, set it to | |
233 // a blank string. | |
234 void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); | |
235 | |
236 // The ConfigurationPolicyHandlerInterface handlers for each of default search | |
237 // policies. | |
238 HandlerList handlers_; | |
239 | |
240 DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); | |
241 }; | |
242 | |
243 // ConfigurationPolicyHandlerInterface implementation for the proxy policies. | |
244 class ProxyPolicyHandler : public ConfigurationPolicyHandlerInterface { | |
245 public: | |
246 ProxyPolicyHandler(); | |
247 virtual ~ProxyPolicyHandler(); | |
248 | |
249 // ConfigurationPolicyHandlerInterface methods: | |
250 virtual bool CheckPolicySettings(const PolicyMap* policies, | |
251 PolicyErrorMap* errors) OVERRIDE; | |
252 virtual void ApplyPolicySettings(const PolicyMap* policies, | |
253 PrefValueMap* prefs) OVERRIDE; | |
254 | |
255 private: | |
256 const Value* GetProxyPolicyValue(const PolicyMap* policies, | |
257 ConfigurationPolicyType policy); | |
258 | |
259 // Converts the deprecated ProxyServerMode policy value to a ProxyMode value | |
260 // and places the result in |mode_value|. Returns true if the conversion | |
261 // succeeded and false otherwise. | |
262 bool CheckProxyModeAndServerMode(const PolicyMap* policies, | |
263 PolicyErrorMap* errors, | |
264 std::string* mode_value); | |
265 | |
266 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler); | |
267 }; | |
268 | |
269 } // namespace policy | |
270 | |
271 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ | |
OLD | NEW |