OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 5 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
6 | 6 |
7 #include <map> | |
8 #include <string> | 7 #include <string> |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/stl_util.h" | |
13 #include "base/string16.h" | 11 #include "base/string16.h" |
14 #include "base/string_util.h" | |
15 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/download/download_util.h" | |
17 #include "chrome/browser/policy/browser_policy_connector.h" | 13 #include "chrome/browser/policy/browser_policy_connector.h" |
14 #include "chrome/browser/policy/configuration_policy_handler.h" | |
15 #include "chrome/browser/policy/configuration_policy_reader.h" | |
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
What is this needed for? I see now, we're referenc
Joao da Silva
2011/10/21 14:22:20
GetPolicyName is now a function in policy:: namesp
| |
16 #include "chrome/browser/policy/policy_error_map.h" | |
18 #include "chrome/browser/policy/policy_map.h" | 17 #include "chrome/browser/policy/policy_map.h" |
19 #include "chrome/browser/policy/policy_path_parser.h" | |
20 #include "chrome/browser/prefs/incognito_mode_prefs.h" | |
21 #include "chrome/browser/prefs/pref_value_map.h" | 18 #include "chrome/browser/prefs/pref_value_map.h" |
22 #include "chrome/browser/prefs/proxy_config_dictionary.h" | |
23 #include "chrome/browser/search_engines/search_terms_data.h" | |
24 #include "chrome/browser/search_engines/template_url.h" | |
25 #include "chrome/common/pref_names.h" | |
26 #include "policy/policy_constants.h" | 19 #include "policy/policy_constants.h" |
27 | 20 |
28 namespace policy { | 21 namespace policy { |
29 | 22 |
30 // Accepts policy settings from a ConfigurationPolicyProvider, converts them | |
31 // to preferences and caches the result. | |
32 class ConfigurationPolicyPrefKeeper { | |
33 public: | |
34 explicit ConfigurationPolicyPrefKeeper(ConfigurationPolicyProvider* provider); | |
35 virtual ~ConfigurationPolicyPrefKeeper(); | |
36 | |
37 // Get a preference value. | |
38 PrefStore::ReadResult GetValue(const std::string& key, | |
39 const Value** result) const; | |
40 | |
41 // Compute the set of preference names that are different in |keeper|. This | |
42 // includes preferences that are missing in either one. | |
43 void GetDifferingPrefPaths(const ConfigurationPolicyPrefKeeper* other, | |
44 std::vector<std::string>* differing_prefs) const; | |
45 | |
46 private: | |
47 // Apply the policy settings stored in |policies|. | |
48 void Apply(PolicyMap* policies); | |
49 | |
50 // Policies that map to a single preference are handled | |
51 // by an automated converter. Each one of these policies | |
52 // has an entry in |simple_policy_map_| with the following type. | |
53 struct PolicyToPreferenceMapEntry { | |
54 base::Value::Type value_type; | |
55 ConfigurationPolicyType policy_type; | |
56 const char* preference_path; // A DictionaryValue path, not a file path. | |
57 }; | |
58 | |
59 // Remove the preferences found in the map from |prefs_|. Returns true if any | |
60 // such preferences were found and removed. | |
61 bool RemovePreferencesOfMap(const PolicyToPreferenceMapEntry* map, | |
62 int table_size); | |
63 | |
64 bool ApplyPolicyFromMap(ConfigurationPolicyType policy, | |
65 Value* value, | |
66 const PolicyToPreferenceMapEntry* map, | |
67 int size); | |
68 | |
69 // Processes proxy-specific policies. Returns true if the specified policy | |
70 // is a proxy-related policy. ApplyProxyPolicy assumes the ownership | |
71 // of |value| in the case that the policy is proxy-specific. | |
72 bool ApplyProxyPolicy(ConfigurationPolicyType policy, Value* value); | |
73 | |
74 // Handles sync-related policies. Returns true if the policy was handled. | |
75 // Assumes ownership of |value| in that case. | |
76 bool ApplySyncPolicy(ConfigurationPolicyType policy, Value* value); | |
77 | |
78 // Handles policies that affect Autofill. Returns true if the policy was | |
79 // handled and assumes ownership of |value| in that case. | |
80 bool ApplyAutofillPolicy(ConfigurationPolicyType policy, Value* value); | |
81 | |
82 // Processes download directory policy. Returns true if the specified policy | |
83 // is the download directory policy. ApplyDownloadDirPolicy assumes the | |
84 // ownership of |value| in the case that the policy is recognized. | |
85 bool ApplyDownloadDirPolicy(ConfigurationPolicyType policy, Value* value); | |
86 | |
87 // Processes disk cache directory policy. Returns true if the specified policy | |
88 // is the right one. ApplyDiskCacheDirPolicy assumes the | |
89 // ownership of |value| in the case that the policy is recognized. | |
90 bool ApplyDiskCacheDirPolicy(ConfigurationPolicyType policy, Value* value); | |
91 | |
92 // Processes file-selection dialogs policy. Returns true if the specified | |
93 // policy is the file-selection dialogs policy. | |
94 // ApplyFileSelectionDialogsPolicy assumes the ownership of |value| in the | |
95 // case that the policy is recognized. | |
96 bool ApplyFileSelectionDialogsPolicy(ConfigurationPolicyType policy, | |
97 Value* value); | |
98 | |
99 // Processes default search provider policies. Returns true if the specified | |
100 // policy is a default search provider related policy. In that case, | |
101 // ApplyDefaultSearchPolicy takes ownership of |value|. | |
102 bool ApplyDefaultSearchPolicy(ConfigurationPolicyType policy, Value* value); | |
103 | |
104 // Processes incognito mode availability related policies. Returns true if the | |
105 // specified policy is pertinent to incognito mode availability. In that case, | |
106 // the function takes ownership of |value|. | |
107 bool ApplyIncognitoModePolicy(ConfigurationPolicyType policy, Value* value); | |
108 | |
109 // Make sure that the |path| if present in |prefs_|. If not, set it to | |
110 // a blank string. | |
111 void EnsureStringPrefExists(const std::string& path); | |
112 | |
113 // If the required entries for default search are specified and valid, | |
114 // finalizes the policy-specified configuration by initializing the | |
115 // unspecified map entries. Otherwise wipes all default search related | |
116 // map entries from |prefs_|. | |
117 void FinalizeDefaultSearchPolicySettings(); | |
118 | |
119 // If the required entries for the proxy settings are specified and valid, | |
120 // finalizes the policy-specified configuration by initializing the | |
121 // respective values in |prefs_|. | |
122 void FinalizeProxyPolicySettings(); | |
123 | |
124 // If the required entries for the Incognito mode availability settings | |
125 // are specified and valid, finalizes the policy-specified configuration | |
126 // by initializing the respective values in |prefs_|. | |
127 void FinalizeIncognitoModeSettings(); | |
128 | |
129 // Returns true if the policy values stored in proxy_* represent a valid proxy | |
130 // configuration, including the case in which there is no configuration at | |
131 // all. | |
132 bool CheckProxySettings(); | |
133 | |
134 // Assumes CheckProxySettings returns true and applies the values stored | |
135 // in proxy_*. | |
136 void ApplyProxySettings(); | |
137 | |
138 bool HasProxyPolicy(ConfigurationPolicyType policy) const; | |
139 | |
140 // Temporary cache that stores values until FinalizeProxyPolicySettings() | |
141 // is called. | |
142 std::map<ConfigurationPolicyType, Value*> proxy_policies_; | |
143 | |
144 // Saved state of the deprecated kPolicyIncognitoEnabled. It is still used for | |
145 // backward compatibility to set the new kIncognitoAvailabilityMode pref in | |
146 // case the corresponding policy for the latter is not specified. | |
147 scoped_ptr<Value> deprecated_incognito_enabled_; | |
148 | |
149 PrefValueMap prefs_; | |
150 | |
151 static const PolicyToPreferenceMapEntry kSimplePolicyMap[]; | |
152 static const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[]; | |
153 | |
154 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefKeeper); | |
155 }; | |
156 | |
157 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry | |
158 ConfigurationPolicyPrefKeeper::kSimplePolicyMap[] = { | |
159 { Value::TYPE_STRING, kPolicyHomepageLocation, prefs::kHomePage }, | |
160 { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage, | |
161 prefs::kHomePageIsNewTabPage }, | |
162 { Value::TYPE_INTEGER, kPolicyRestoreOnStartup, | |
163 prefs::kRestoreOnStartup}, | |
164 { Value::TYPE_LIST, kPolicyRestoreOnStartupURLs, | |
165 prefs::kURLsToRestoreOnStartup }, | |
166 { Value::TYPE_BOOLEAN, kPolicyAlternateErrorPagesEnabled, | |
167 prefs::kAlternateErrorPagesEnabled }, | |
168 { Value::TYPE_BOOLEAN, kPolicySearchSuggestEnabled, | |
169 prefs::kSearchSuggestEnabled }, | |
170 { Value::TYPE_BOOLEAN, kPolicyDnsPrefetchingEnabled, | |
171 prefs::kNetworkPredictionEnabled }, | |
172 { Value::TYPE_BOOLEAN, kPolicyDisableSpdy, | |
173 prefs::kDisableSpdy }, | |
174 { Value::TYPE_LIST, kPolicyDisabledSchemes, | |
175 prefs::kDisabledSchemes }, | |
176 { Value::TYPE_BOOLEAN, kPolicySafeBrowsingEnabled, | |
177 prefs::kSafeBrowsingEnabled }, | |
178 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerEnabled, | |
179 prefs::kPasswordManagerEnabled }, | |
180 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerAllowShowPasswords, | |
181 prefs::kPasswordManagerAllowShowPasswords }, | |
182 { Value::TYPE_BOOLEAN, kPolicyPrintingEnabled, | |
183 prefs::kPrintingEnabled }, | |
184 { Value::TYPE_BOOLEAN, kPolicyMetricsReportingEnabled, | |
185 prefs::kMetricsReportingEnabled }, | |
186 { Value::TYPE_STRING, kPolicyApplicationLocaleValue, | |
187 prefs::kApplicationLocale}, | |
188 { Value::TYPE_LIST, kPolicyExtensionInstallWhitelist, | |
189 prefs::kExtensionInstallAllowList}, | |
190 { Value::TYPE_LIST, kPolicyExtensionInstallBlacklist, | |
191 prefs::kExtensionInstallDenyList}, | |
192 { Value::TYPE_LIST, kPolicyExtensionInstallForcelist, | |
193 prefs::kExtensionInstallForceList}, | |
194 { Value::TYPE_LIST, kPolicyDisabledPlugins, | |
195 prefs::kPluginsDisabledPlugins}, | |
196 { Value::TYPE_LIST, kPolicyDisabledPluginsExceptions, | |
197 prefs::kPluginsDisabledPluginsExceptions}, | |
198 { Value::TYPE_LIST, kPolicyEnabledPlugins, | |
199 prefs::kPluginsEnabledPlugins}, | |
200 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton, | |
201 prefs::kShowHomeButton }, | |
202 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled, | |
203 prefs::kWebKitJavascriptEnabled }, | |
204 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, | |
205 prefs::kSavingBrowserHistoryDisabled }, | |
206 { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit, | |
207 prefs::kClearSiteDataOnExit }, | |
208 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled, | |
209 prefs::kDevToolsDisabled }, | |
210 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies, | |
211 prefs::kBlockThirdPartyCookies }, | |
212 { Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting, | |
213 prefs::kManagedDefaultCookiesSetting }, | |
214 { Value::TYPE_INTEGER, kPolicyDefaultImagesSetting, | |
215 prefs::kManagedDefaultImagesSetting }, | |
216 { Value::TYPE_INTEGER, kPolicyDefaultJavaScriptSetting, | |
217 prefs::kManagedDefaultJavaScriptSetting }, | |
218 { Value::TYPE_INTEGER, kPolicyDefaultPluginsSetting, | |
219 prefs::kManagedDefaultPluginsSetting }, | |
220 { Value::TYPE_INTEGER, kPolicyDefaultPopupsSetting, | |
221 prefs::kManagedDefaultPopupsSetting }, | |
222 { Value::TYPE_LIST, kPolicyAutoSelectCertificateForUrls, | |
223 prefs::kManagedAutoSelectCertificateForUrls}, | |
224 { Value::TYPE_LIST, kPolicyCookiesAllowedForUrls, | |
225 prefs::kManagedCookiesAllowedForUrls }, | |
226 { Value::TYPE_LIST, kPolicyCookiesBlockedForUrls, | |
227 prefs::kManagedCookiesBlockedForUrls }, | |
228 { Value::TYPE_LIST, kPolicyCookiesSessionOnlyForUrls, | |
229 prefs::kManagedCookiesSessionOnlyForUrls }, | |
230 { Value::TYPE_LIST, kPolicyImagesAllowedForUrls, | |
231 prefs::kManagedImagesAllowedForUrls }, | |
232 { Value::TYPE_LIST, kPolicyImagesBlockedForUrls, | |
233 prefs::kManagedImagesBlockedForUrls }, | |
234 { Value::TYPE_LIST, kPolicyJavaScriptAllowedForUrls, | |
235 prefs::kManagedJavaScriptAllowedForUrls }, | |
236 { Value::TYPE_LIST, kPolicyJavaScriptBlockedForUrls, | |
237 prefs::kManagedJavaScriptBlockedForUrls }, | |
238 { Value::TYPE_LIST, kPolicyPluginsAllowedForUrls, | |
239 prefs::kManagedPluginsAllowedForUrls }, | |
240 { Value::TYPE_LIST, kPolicyPluginsBlockedForUrls, | |
241 prefs::kManagedPluginsBlockedForUrls }, | |
242 { Value::TYPE_LIST, kPolicyPopupsAllowedForUrls, | |
243 prefs::kManagedPopupsAllowedForUrls }, | |
244 { Value::TYPE_LIST, kPolicyPopupsBlockedForUrls, | |
245 prefs::kManagedPopupsBlockedForUrls }, | |
246 { Value::TYPE_LIST, kPolicyNotificationsAllowedForUrls, | |
247 prefs::kManagedNotificationsAllowedForUrls }, | |
248 { Value::TYPE_LIST, kPolicyNotificationsBlockedForUrls, | |
249 prefs::kManagedNotificationsBlockedForUrls }, | |
250 { Value::TYPE_INTEGER, kPolicyDefaultNotificationsSetting, | |
251 prefs::kManagedDefaultNotificationsSetting }, | |
252 { Value::TYPE_INTEGER, kPolicyDefaultGeolocationSetting, | |
253 prefs::kManagedDefaultGeolocationSetting }, | |
254 { Value::TYPE_STRING, kPolicyAuthSchemes, | |
255 prefs::kAuthSchemes }, | |
256 { Value::TYPE_BOOLEAN, kPolicyDisableAuthNegotiateCnameLookup, | |
257 prefs::kDisableAuthNegotiateCnameLookup }, | |
258 { Value::TYPE_BOOLEAN, kPolicyEnableAuthNegotiatePort, | |
259 prefs::kEnableAuthNegotiatePort }, | |
260 { Value::TYPE_STRING, kPolicyAuthServerWhitelist, | |
261 prefs::kAuthServerWhitelist }, | |
262 { Value::TYPE_STRING, kPolicyAuthNegotiateDelegateWhitelist, | |
263 prefs::kAuthNegotiateDelegateWhitelist }, | |
264 { Value::TYPE_STRING, kPolicyGSSAPILibraryName, | |
265 prefs::kGSSAPILibraryName }, | |
266 { Value::TYPE_BOOLEAN, kPolicyAllowCrossOriginAuthPrompt, | |
267 prefs::kAllowCrossOriginAuthPrompt }, | |
268 { Value::TYPE_BOOLEAN, kPolicyDisable3DAPIs, | |
269 prefs::kDisable3DAPIs }, | |
270 { Value::TYPE_BOOLEAN, kPolicyDisablePluginFinder, | |
271 prefs::kDisablePluginFinder }, | |
272 { Value::TYPE_INTEGER, kPolicyPolicyRefreshRate, | |
273 prefs::kUserPolicyRefreshRate }, | |
274 { Value::TYPE_INTEGER, kPolicyDevicePolicyRefreshRate, | |
275 prefs::kDevicePolicyRefreshRate }, | |
276 { Value::TYPE_BOOLEAN, kPolicyInstantEnabled, prefs::kInstantEnabled }, | |
277 { Value::TYPE_BOOLEAN, kPolicyDefaultBrowserSettingEnabled, | |
278 prefs::kDefaultBrowserSettingEnabled }, | |
279 { Value::TYPE_BOOLEAN, kPolicyRemoteAccessClientFirewallTraversal, | |
280 prefs::kRemoteAccessClientFirewallTraversal }, | |
281 { Value::TYPE_BOOLEAN, kPolicyRemoteAccessHostFirewallTraversal, | |
282 prefs::kRemoteAccessHostFirewallTraversal }, | |
283 { Value::TYPE_BOOLEAN, kPolicyCloudPrintProxyEnabled, | |
284 prefs::kCloudPrintProxyEnabled }, | |
285 { Value::TYPE_BOOLEAN, kPolicyTranslateEnabled, prefs::kEnableTranslate }, | |
286 { Value::TYPE_BOOLEAN, kPolicyAllowOutdatedPlugins, | |
287 prefs::kPluginsAllowOutdated }, | |
288 { Value::TYPE_BOOLEAN, kPolicyAlwaysAuthorizePlugins, | |
289 prefs::kPluginsAlwaysAuthorize }, | |
290 { Value::TYPE_BOOLEAN, kPolicyBookmarkBarEnabled, | |
291 prefs::kShowBookmarkBar }, | |
292 { Value::TYPE_BOOLEAN, kPolicyEditBookmarksEnabled, | |
293 prefs::kEditBookmarksEnabled }, | |
294 { Value::TYPE_BOOLEAN, kPolicyAllowFileSelectionDialogs, | |
295 prefs::kAllowFileSelectionDialogs }, | |
296 { Value::TYPE_BOOLEAN, kPolicyImportBookmarks, | |
297 prefs::kImportBookmarks}, | |
298 { Value::TYPE_BOOLEAN, kPolicyImportHistory, | |
299 prefs::kImportHistory}, | |
300 { Value::TYPE_BOOLEAN, kPolicyImportHomepage, | |
301 prefs::kImportHomepage}, | |
302 { Value::TYPE_BOOLEAN, kPolicyImportSearchEngine, | |
303 prefs::kImportSearchEngine }, | |
304 { Value::TYPE_BOOLEAN, kPolicyImportSavedPasswords, | |
305 prefs::kImportSavedPasswords }, | |
306 { Value::TYPE_INTEGER, kPolicyMaxConnectionsPerProxy, | |
307 prefs::kMaxConnectionsPerProxy }, | |
308 { Value::TYPE_BOOLEAN, kPolicyHideWebStorePromo, | |
309 prefs::kNTPHideWebStorePromo }, | |
310 { Value::TYPE_LIST, kPolicyURLBlacklist, | |
311 prefs::kUrlBlacklist }, | |
312 { Value::TYPE_LIST, kPolicyURLWhitelist, | |
313 prefs::kUrlWhitelist }, | |
314 | |
315 #if defined(OS_CHROMEOS) | |
316 { Value::TYPE_BOOLEAN, kPolicyChromeOsLockOnIdleSuspend, | |
317 prefs::kEnableScreenLock }, | |
318 { Value::TYPE_STRING, kPolicyChromeOsReleaseChannel, | |
319 prefs::kChromeOsReleaseChannel }, | |
320 #endif | |
321 }; | |
322 | |
323 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry | |
324 ConfigurationPolicyPrefKeeper::kDefaultSearchPolicyMap[] = { | |
325 { Value::TYPE_BOOLEAN, kPolicyDefaultSearchProviderEnabled, | |
326 prefs::kDefaultSearchProviderEnabled }, | |
327 { Value::TYPE_STRING, kPolicyDefaultSearchProviderName, | |
328 prefs::kDefaultSearchProviderName }, | |
329 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword, | |
330 prefs::kDefaultSearchProviderKeyword }, | |
331 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL, | |
332 prefs::kDefaultSearchProviderSearchURL }, | |
333 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL, | |
334 prefs::kDefaultSearchProviderSuggestURL }, | |
335 { Value::TYPE_STRING, kPolicyDefaultSearchProviderInstantURL, | |
336 prefs::kDefaultSearchProviderInstantURL }, | |
337 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL, | |
338 prefs::kDefaultSearchProviderIconURL }, | |
339 { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings, | |
340 prefs::kDefaultSearchProviderEncodings }, | |
341 }; | |
342 | |
343 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper( | |
344 ConfigurationPolicyProvider* provider) { | |
345 scoped_ptr<PolicyMap> policies(new PolicyMap()); | |
346 if (!provider->Provide(policies.get())) | |
347 LOG(WARNING) << "Failed to get policy from provider."; | |
348 | |
349 Apply(policies.get()); | |
350 FinalizeProxyPolicySettings(); | |
351 FinalizeDefaultSearchPolicySettings(); | |
352 FinalizeIncognitoModeSettings(); | |
353 } | |
354 | |
355 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() { | |
356 DCHECK(proxy_policies_.empty()); | |
357 } | |
358 | |
359 PrefStore::ReadResult | |
360 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key, | |
361 const Value** result) const { | |
362 const Value* stored_value = NULL; | |
363 if (!prefs_.GetValue(key, &stored_value)) | |
364 return PrefStore::READ_NO_VALUE; | |
365 | |
366 // Check whether there's a default value, which indicates READ_USE_DEFAULT | |
367 // should be returned. | |
368 if (stored_value->IsType(Value::TYPE_NULL)) | |
369 return PrefStore::READ_USE_DEFAULT; | |
370 | |
371 if (result) | |
372 *result = stored_value; | |
373 return PrefStore::READ_OK; | |
374 } | |
375 | |
376 void ConfigurationPolicyPrefKeeper::GetDifferingPrefPaths( | |
377 const ConfigurationPolicyPrefKeeper* other, | |
378 std::vector<std::string>* differing_prefs) const { | |
379 prefs_.GetDifferingKeys(&other->prefs_, differing_prefs); | |
380 } | |
381 | |
382 void ConfigurationPolicyPrefKeeper::Apply(PolicyMap* policies) { | |
383 PolicyMap::const_iterator current = policies->begin(); | |
384 for ( ; current != policies->end(); ++current) { | |
385 // TODO(simo) Use a separate ConfigurationPolicyHandler class to apply | |
386 // policy settings. | |
387 Value* value = current->second->DeepCopy(); | |
388 if (ApplyProxyPolicy(current->first, value) || | |
389 ApplySyncPolicy(current->first, value) || | |
390 ApplyAutofillPolicy(current->first, value) || | |
391 ApplyDownloadDirPolicy(current->first, value) || | |
392 ApplyDiskCacheDirPolicy(current->first, value) || | |
393 ApplyFileSelectionDialogsPolicy(current->first, value) || | |
394 ApplyDefaultSearchPolicy(current->first, value) || | |
395 ApplyIncognitoModePolicy(current->first, value) || | |
396 ApplyPolicyFromMap(current->first, value, | |
397 kSimplePolicyMap, arraysize(kSimplePolicyMap))) { | |
398 continue; | |
399 } | |
400 delete value; | |
401 | |
402 // Other policy implementations should go into the conditional above. | |
403 NOTIMPLEMENTED(); | |
404 } | |
405 } | |
406 | |
407 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap( | |
408 const PolicyToPreferenceMapEntry* map, int table_size) { | |
409 bool found_any = false; | |
410 for (int i = 0; i < table_size; ++i) { | |
411 if (prefs_.RemoveValue(map[i].preference_path)) | |
412 found_any = true; | |
413 } | |
414 return found_any; | |
415 } | |
416 | |
417 bool ConfigurationPolicyPrefKeeper::ApplyPolicyFromMap( | |
418 ConfigurationPolicyType policy, | |
419 Value* value, | |
420 const PolicyToPreferenceMapEntry* map, | |
421 int size) { | |
422 for (int current = 0; current < size; ++current) { | |
423 if (map[current].policy_type == policy) { | |
424 DCHECK_EQ(map[current].value_type, value->GetType()) | |
425 << "mismatch in provided and expected policy value for preferences " | |
426 << map[current].preference_path << ". expected = " | |
427 << map[current].value_type << ", actual = "<< value->GetType(); | |
428 prefs_.SetValue(map[current].preference_path, value); | |
429 return true; | |
430 } | |
431 } | |
432 return false; | |
433 } | |
434 | |
435 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy( | |
436 ConfigurationPolicyType policy, | |
437 Value* value) { | |
438 // We only collect the values until we have sufficient information when | |
439 // FinalizeProxyPolicySettings() is called to determine whether the presented | |
440 // values were correct and apply them in that case. | |
441 if (ConfigurationPolicyPrefStore::IsProxyPolicy(policy)) { | |
442 delete proxy_policies_[policy]; | |
443 proxy_policies_[policy] = value; | |
444 return true; | |
445 } | |
446 // We are not interested in this policy. | |
447 return false; | |
448 } | |
449 | |
450 bool ConfigurationPolicyPrefKeeper::ApplySyncPolicy( | |
451 ConfigurationPolicyType policy, Value* value) { | |
452 if (policy == kPolicySyncDisabled) { | |
453 bool disable_sync; | |
454 if (value->GetAsBoolean(&disable_sync) && disable_sync) | |
455 prefs_.SetValue(prefs::kSyncManaged, value); | |
456 else | |
457 delete value; | |
458 return true; | |
459 } | |
460 return false; | |
461 } | |
462 | |
463 bool ConfigurationPolicyPrefKeeper::ApplyAutofillPolicy( | |
464 ConfigurationPolicyType policy, Value* value) { | |
465 if (policy == kPolicyAutoFillEnabled) { | |
466 bool auto_fill_enabled; | |
467 if (value->GetAsBoolean(&auto_fill_enabled) && !auto_fill_enabled) | |
468 prefs_.SetValue(prefs::kAutofillEnabled, | |
469 Value::CreateBooleanValue(false)); | |
470 delete value; | |
471 return true; | |
472 } | |
473 return false; | |
474 } | |
475 | |
476 bool ConfigurationPolicyPrefKeeper::ApplyDownloadDirPolicy( | |
477 ConfigurationPolicyType policy, | |
478 Value* value) { | |
479 // Replace the policy string which might contain some user variables to an | |
480 // expanded string. | |
481 if (policy == kPolicyDownloadDirectory) { | |
482 // This policy is ignored on ChromeOS because the download path there is | |
483 // fixed and can not be configured by the user. | |
484 #if !defined(OS_CHROMEOS) | |
485 FilePath::StringType string_value; | |
486 bool result = value->GetAsString(&string_value); | |
487 DCHECK(result); | |
488 FilePath::StringType expanded_value = | |
489 policy::path_parser::ExpandPathVariables(string_value); | |
490 // Leaving the policy empty would revert to the default download location | |
491 // else we would point in an undefined location. We do this after the | |
492 // path expansion because it might lead to an empty string(e.g. for "\"\""). | |
493 if (expanded_value.empty()) | |
494 expanded_value = download_util::GetDefaultDownloadDirectory().value(); | |
495 prefs_.SetValue(prefs::kDownloadDefaultDirectory, | |
496 Value::CreateStringValue(expanded_value)); | |
497 prefs_.SetValue(prefs::kPromptForDownload, | |
498 Value::CreateBooleanValue(false)); | |
499 #endif // !defined(OS_CHROMEOS) | |
500 delete value; | |
501 return true; | |
502 } | |
503 // We are not interested in this policy. | |
504 return false; | |
505 } | |
506 | |
507 bool ConfigurationPolicyPrefKeeper::ApplyDiskCacheDirPolicy( | |
508 ConfigurationPolicyType policy, | |
509 Value* value) { | |
510 // Replace the policy string which might contain some user variables to an | |
511 // expanded string. | |
512 if (policy == kPolicyDiskCacheDir) { | |
513 FilePath::StringType string_value; | |
514 bool result = value->GetAsString(&string_value); | |
515 DCHECK(result); | |
516 FilePath::StringType expanded_value = | |
517 policy::path_parser::ExpandPathVariables(string_value); | |
518 prefs_.SetValue(prefs::kDiskCacheDir, | |
519 Value::CreateStringValue(expanded_value)); | |
520 delete value; | |
521 return true; | |
522 } | |
523 // We are not interested in this policy. | |
524 return false; | |
525 } | |
526 | |
527 bool ConfigurationPolicyPrefKeeper::ApplyFileSelectionDialogsPolicy( | |
528 ConfigurationPolicyType policy, | |
529 Value* value) { | |
530 if (policy == kPolicyAllowFileSelectionDialogs) { | |
531 prefs_.SetValue(prefs::kAllowFileSelectionDialogs, value); | |
532 // If file-selection dialogs are not allowed we forbid the user to be | |
533 // prompted for the download location, since this would end up in an Infobar | |
534 // explaining that file-selection dialogs are forbidden anyways. | |
535 bool allow_file_selection_dialogs = true; | |
536 bool result = value->GetAsBoolean(&allow_file_selection_dialogs); | |
537 DCHECK(result); | |
538 if (!allow_file_selection_dialogs) { | |
539 prefs_.SetValue(prefs::kPromptForDownload, | |
540 Value::CreateBooleanValue(false)); | |
541 } | |
542 return true; | |
543 } | |
544 // We are not interested in this policy. | |
545 return false; | |
546 } | |
547 | |
548 bool ConfigurationPolicyPrefKeeper::ApplyDefaultSearchPolicy( | |
549 ConfigurationPolicyType policy, | |
550 Value* value) { | |
551 // The DefaultSearchProviderEncodings policy has type list, but the related | |
552 // preference has type string. Convert one into the other here, using | |
553 // ';' as a separator. | |
554 if (policy == kPolicyDefaultSearchProviderEncodings) { | |
555 ListValue* list; | |
556 if (!value->GetAsList(&list)) { | |
557 NOTREACHED() | |
558 << "mismatch in provided and expected policy value for preferences " | |
559 << prefs::kDefaultSearchProviderEncodings << ". expected = " | |
560 << Value::TYPE_LIST << ", actual = "<< value->GetType(); | |
561 return false; | |
562 } | |
563 ListValue::const_iterator iter(list->begin()); | |
564 ListValue::const_iterator end(list->end()); | |
565 std::string encodings; | |
566 for (; iter != end; ++iter) { | |
567 std::string s; | |
568 if ((*iter)->GetAsString(&s)) { | |
569 if (!encodings.empty()) | |
570 encodings.push_back(';'); | |
571 encodings.append(s); | |
572 } else { | |
573 NOTREACHED(); | |
574 } | |
575 } | |
576 // We own |value|. | |
577 delete value; | |
578 prefs_.SetValue(prefs::kDefaultSearchProviderEncodings, | |
579 Value::CreateStringValue(encodings)); | |
580 return true; | |
581 } | |
582 | |
583 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, | |
584 arraysize(kDefaultSearchPolicyMap))) { | |
585 return true; | |
586 } | |
587 return false; | |
588 } | |
589 | |
590 bool ConfigurationPolicyPrefKeeper::ApplyIncognitoModePolicy( | |
591 ConfigurationPolicyType policy, | |
592 Value* value) { | |
593 if (policy == kPolicyIncognitoModeAvailability) { | |
594 int availability = IncognitoModePrefs::ENABLED; | |
595 bool result = value->GetAsInteger(&availability); | |
596 delete value; | |
597 if (result) { | |
598 IncognitoModePrefs::Availability availability_enum_value; | |
599 if (IncognitoModePrefs::IntToAvailability(availability, | |
600 &availability_enum_value)) { | |
601 prefs_.SetValue(prefs::kIncognitoModeAvailability, | |
602 Value::CreateIntegerValue(availability_enum_value)); | |
603 } else { | |
604 LOG(WARNING) << "IncognitoModeAvailability policy value is " | |
605 << "out of range " << availability; | |
606 } | |
607 } else { | |
608 LOG(WARNING) << "IncognitoModeAvailability policy value could not be " | |
609 << "parsed"; | |
610 } | |
611 return true; | |
612 } | |
613 if (policy == kPolicyIncognitoEnabled) { | |
614 deprecated_incognito_enabled_.reset(value); | |
615 return true; | |
616 } | |
617 // The policy is not relevant to incognito. | |
618 return false; | |
619 } | |
620 | |
621 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( | |
622 const std::string& path) { | |
623 std::string value; | |
624 if (!prefs_.GetString(path, &value)) | |
625 prefs_.SetString(path, value); | |
626 } | |
627 | |
628 namespace { | |
629 | |
630 // Implementation of SearchTermsData just for validation. | |
631 class SearchTermsDataForValidation : public SearchTermsData { | |
632 public: | |
633 SearchTermsDataForValidation() {} | |
634 | |
635 // Implementation of SearchTermsData. | |
636 virtual std::string GoogleBaseURLValue() const { | |
637 return "http://www.google.com/"; | |
638 } | |
639 virtual std::string GetApplicationLocale() const { | |
640 return "en"; | |
641 } | |
642 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | |
643 virtual string16 GetRlzParameterValue() const { | |
644 return string16(); | |
645 } | |
646 #endif | |
647 private: | |
648 DISALLOW_COPY_AND_ASSIGN(SearchTermsDataForValidation); | |
649 }; | |
650 | |
651 } // namespace | |
652 | |
653 void ConfigurationPolicyPrefKeeper::FinalizeDefaultSearchPolicySettings() { | |
654 bool enabled = true; | |
655 if (prefs_.GetBoolean(prefs::kDefaultSearchProviderEnabled, &enabled) && | |
656 !enabled) { | |
657 // If default search is disabled, we ignore the other fields. | |
658 prefs_.SetString(prefs::kDefaultSearchProviderName, std::string()); | |
659 prefs_.SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); | |
660 prefs_.SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); | |
661 prefs_.SetString(prefs::kDefaultSearchProviderIconURL, std::string()); | |
662 prefs_.SetString(prefs::kDefaultSearchProviderEncodings, std::string()); | |
663 prefs_.SetString(prefs::kDefaultSearchProviderKeyword, std::string()); | |
664 prefs_.SetString(prefs::kDefaultSearchProviderInstantURL, std::string()); | |
665 return; | |
666 } | |
667 std::string search_url; | |
668 // The search URL is required. | |
669 if (prefs_.GetString(prefs::kDefaultSearchProviderSearchURL, &search_url) && | |
670 !search_url.empty()) { | |
671 SearchTermsDataForValidation search_terms_data; | |
672 const TemplateURLRef search_url_ref(search_url, 0, 0); | |
673 // It must support replacement (which implies it is valid). | |
674 if (search_url_ref.SupportsReplacementUsingTermsData(search_terms_data)) { | |
675 // The other entries are optional. Just make sure that they are all | |
676 // specified via policy, so that we don't use regular prefs. | |
677 EnsureStringPrefExists(prefs::kDefaultSearchProviderSuggestURL); | |
678 EnsureStringPrefExists(prefs::kDefaultSearchProviderIconURL); | |
679 EnsureStringPrefExists(prefs::kDefaultSearchProviderEncodings); | |
680 EnsureStringPrefExists(prefs::kDefaultSearchProviderKeyword); | |
681 EnsureStringPrefExists(prefs::kDefaultSearchProviderInstantURL); | |
682 | |
683 // For the name, default to the host if not specified. | |
684 std::string name; | |
685 if (!prefs_.GetString(prefs::kDefaultSearchProviderName, &name) || | |
686 name.empty()) | |
687 prefs_.SetString(prefs::kDefaultSearchProviderName, | |
688 GURL(search_url).host()); | |
689 | |
690 // And clear the IDs since these are not specified via policy. | |
691 prefs_.SetString(prefs::kDefaultSearchProviderID, std::string()); | |
692 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID, | |
693 std::string()); | |
694 return; | |
695 } | |
696 } | |
697 // Required entries are not there. Remove any related entries. | |
698 RemovePreferencesOfMap(kDefaultSearchPolicyMap, | |
699 arraysize(kDefaultSearchPolicyMap)); | |
700 } | |
701 | |
702 void ConfigurationPolicyPrefKeeper::FinalizeIncognitoModeSettings() { | |
703 int int_value; | |
704 if (!prefs_.GetInteger(prefs::kIncognitoModeAvailability, &int_value)) { | |
705 // If kPolicyIncognitoModeAvailability is not specified, check the obsolete | |
706 // kPolicyIncognitoEnabled. | |
707 if (deprecated_incognito_enabled_.get()) { | |
708 bool enabled = true; | |
709 if (deprecated_incognito_enabled_->GetAsBoolean(&enabled)) { | |
710 prefs_.SetInteger( | |
711 prefs::kIncognitoModeAvailability, | |
712 enabled ? IncognitoModePrefs::ENABLED : | |
713 IncognitoModePrefs::DISABLED); | |
714 } else { | |
715 LOG(WARNING) << "IncognitoEnabled policy value could not be parsed"; | |
716 } | |
717 } | |
718 } | |
719 } | |
720 | |
721 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { | |
722 if (CheckProxySettings()) | |
723 ApplyProxySettings(); | |
724 | |
725 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), | |
726 proxy_policies_.end()); | |
727 proxy_policies_.clear(); | |
728 } | |
729 | |
730 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { | |
731 bool mode = HasProxyPolicy(kPolicyProxyMode); | |
732 bool server_mode = HasProxyPolicy(kPolicyProxyServerMode); // deprecated | |
733 bool server = HasProxyPolicy(kPolicyProxyServer); | |
734 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl); | |
735 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList); | |
736 | |
737 if ((server || pac_url || bypass_list) && !(mode || server_mode)) { | |
738 LOG(WARNING) << "A centrally-administered policy defines proxy setting" | |
739 << " details without setting a proxy mode."; | |
740 return false; | |
741 } | |
742 | |
743 // If there's a server mode, convert it into a mode. | |
744 std::string mode_value; | |
745 if (mode) { | |
746 if (server_mode) | |
747 LOG(WARNING) << "Both ProxyMode and ProxyServerMode policies defined, " | |
748 << "ignoring ProxyMode."; | |
749 if (!proxy_policies_[kPolicyProxyMode]->GetAsString(&mode_value)) { | |
750 LOG(WARNING) << "Invalid ProxyMode value."; | |
751 return false; | |
752 } | |
753 } else if (server_mode) { | |
754 int server_mode_value; | |
755 if (!proxy_policies_[kPolicyProxyServerMode]->GetAsInteger( | |
756 &server_mode_value)) { | |
757 LOG(WARNING) << "Invalid ProxyServerMode value."; | |
758 return false; | |
759 } | |
760 | |
761 switch (server_mode_value) { | |
762 case kPolicyNoProxyServerMode: | |
763 mode_value = ProxyPrefs::kDirectProxyModeName; | |
764 break; | |
765 case kPolicyAutoDetectProxyServerMode: | |
766 mode_value = ProxyPrefs::kAutoDetectProxyModeName; | |
767 break; | |
768 case kPolicyManuallyConfiguredProxyServerMode: | |
769 if (server && pac_url) { | |
770 LOG(WARNING) << "A centrally-administered policy dictates that" | |
771 << " both fixed proxy servers and a .pac url. should" | |
772 << " be used for proxy configuration."; | |
773 return false; | |
774 } | |
775 if (!server && !pac_url) { | |
776 LOG(WARNING) << "A centrally-administered policy dictates that the" | |
777 << " proxy settings should use either fixed proxy" | |
778 << " servers or a .pac url, but specifies neither."; | |
779 return false; | |
780 } | |
781 if (pac_url) | |
782 mode_value = ProxyPrefs::kPacScriptProxyModeName; | |
783 else | |
784 mode_value = ProxyPrefs::kFixedServersProxyModeName; | |
785 break; | |
786 case kPolicyUseSystemProxyServerMode: | |
787 mode_value = ProxyPrefs::kSystemProxyModeName; | |
788 break; | |
789 default: | |
790 LOG(WARNING) << "Invalid proxy mode " << server_mode_value; | |
791 return false; | |
792 } | |
793 } | |
794 | |
795 // If neither ProxyMode nor ProxyServerMode are specified, mode_value will be | |
796 // empty and the proxy shouldn't be configured at all. | |
797 if (mode_value.empty()) | |
798 return true; | |
799 | |
800 if (mode_value == ProxyPrefs::kDirectProxyModeName) { | |
801 if (server || pac_url || bypass_list) { | |
802 LOG(WARNING) << "A centrally-administered policy disables the use of" | |
803 << " a proxy but also specifies an explicit proxy" | |
804 << " configuration."; | |
805 return false; | |
806 } | |
807 } else if (mode_value == ProxyPrefs::kAutoDetectProxyModeName) { | |
808 if (server || bypass_list || pac_url) { | |
809 LOG(WARNING) << "A centrally-administered policy dictates that a proxy" | |
810 << " shall be auto configured but specifies fixed proxy" | |
811 << " servers, a by-pass list or a .pac script URL."; | |
812 return false; | |
813 } | |
814 } else if (mode_value == ProxyPrefs::kPacScriptProxyModeName) { | |
815 if (server || bypass_list) { | |
816 LOG(WARNING) << "A centrally-administered policy dictates that a .pac" | |
817 << " script URL should be used for proxy configuration but" | |
818 << " also specifies policies required only for fixed" | |
819 << " proxy servers."; | |
820 return false; | |
821 } | |
822 } else if (mode_value == ProxyPrefs::kFixedServersProxyModeName) { | |
823 if (pac_url) { | |
824 LOG(WARNING) << "A centrally-administered policy dictates that" | |
825 << " fixed proxy servers should be used but also" | |
826 << " specifies a .pac script URL."; | |
827 return false; | |
828 } | |
829 } else if (mode_value == ProxyPrefs::kSystemProxyModeName) { | |
830 if (server || pac_url || bypass_list) { | |
831 LOG(WARNING) << "A centrally-administered policy dictates that the" | |
832 << " system proxy settings should be used but also " | |
833 << " specifies an explicit proxy configuration."; | |
834 return false; | |
835 } | |
836 } else { | |
837 LOG(WARNING) << "Invalid proxy mode " << mode_value; | |
838 return false; | |
839 } | |
840 return true; | |
841 } | |
842 | |
843 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { | |
844 ProxyPrefs::ProxyMode mode; | |
845 if (HasProxyPolicy(kPolicyProxyMode)) { | |
846 std::string string_mode; | |
847 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode)); | |
848 if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) { | |
849 LOG(WARNING) << "A centrally-administered policy specifies a value for " | |
850 << "the ProxyMode policy that isn't recognized."; | |
851 return; | |
852 } | |
853 } else if (HasProxyPolicy(kPolicyProxyServerMode)) { | |
854 int int_mode = 0; | |
855 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode)); | |
856 switch (int_mode) { | |
857 case kPolicyNoProxyServerMode: | |
858 mode = ProxyPrefs::MODE_DIRECT; | |
859 break; | |
860 case kPolicyAutoDetectProxyServerMode: | |
861 mode = ProxyPrefs::MODE_AUTO_DETECT; | |
862 break; | |
863 case kPolicyManuallyConfiguredProxyServerMode: | |
864 mode = ProxyPrefs::MODE_FIXED_SERVERS; | |
865 if (HasProxyPolicy(kPolicyProxyPacUrl)) | |
866 mode = ProxyPrefs::MODE_PAC_SCRIPT; | |
867 break; | |
868 case kPolicyUseSystemProxyServerMode: | |
869 mode = ProxyPrefs::MODE_SYSTEM; | |
870 break; | |
871 default: | |
872 mode = ProxyPrefs::MODE_DIRECT; | |
873 NOTREACHED(); | |
874 } | |
875 } else { | |
876 return; | |
877 } | |
878 switch (mode) { | |
879 case ProxyPrefs::MODE_DIRECT: | |
880 prefs_.SetValue(prefs::kProxy, ProxyConfigDictionary::CreateDirect()); | |
881 break; | |
882 case ProxyPrefs::MODE_AUTO_DETECT: | |
883 prefs_.SetValue(prefs::kProxy, ProxyConfigDictionary::CreateAutoDetect()); | |
884 break; | |
885 case ProxyPrefs::MODE_PAC_SCRIPT: { | |
886 if (!HasProxyPolicy(kPolicyProxyPacUrl)) { | |
887 LOG(WARNING) << "A centrally-administered policy specifies to use a " | |
888 << "PAC script, but doesn't supply the PAC script URL."; | |
889 return; | |
890 } | |
891 std::string pac_url; | |
892 proxy_policies_[kPolicyProxyPacUrl]->GetAsString(&pac_url); | |
893 prefs_.SetValue(prefs::kProxy, | |
894 ProxyConfigDictionary::CreatePacScript(pac_url, false)); | |
895 break; | |
896 } | |
897 case ProxyPrefs::MODE_FIXED_SERVERS: { | |
898 if (!HasProxyPolicy(kPolicyProxyServer)) { | |
899 LOG(WARNING) << "A centrally-administered policy specifies to use a " | |
900 << "fixed server, but doesn't supply the server address."; | |
901 return; | |
902 } | |
903 std::string proxy_server; | |
904 proxy_policies_[kPolicyProxyServer]->GetAsString(&proxy_server); | |
905 std::string bypass_list; | |
906 if (HasProxyPolicy(kPolicyProxyBypassList)) | |
907 proxy_policies_[kPolicyProxyBypassList]->GetAsString(&bypass_list); | |
908 prefs_.SetValue(prefs::kProxy, | |
909 ProxyConfigDictionary::CreateFixedServers(proxy_server, | |
910 bypass_list)); | |
911 break; | |
912 } | |
913 case ProxyPrefs::MODE_SYSTEM: | |
914 prefs_.SetValue(prefs::kProxy, | |
915 ProxyConfigDictionary::CreateSystem()); | |
916 break; | |
917 case ProxyPrefs::kModeCount: | |
918 NOTREACHED(); | |
919 } | |
920 } | |
921 | |
922 bool ConfigurationPolicyPrefKeeper::HasProxyPolicy( | |
923 ConfigurationPolicyType policy) const { | |
924 std::map<ConfigurationPolicyType, Value*>::const_iterator iter; | |
925 iter = proxy_policies_.find(policy); | |
926 std::string tmp; | |
927 if (iter == proxy_policies_.end() || | |
928 !iter->second || | |
929 iter->second->IsType(Value::TYPE_NULL) || | |
930 (iter->second->IsType(Value::TYPE_STRING) && | |
931 iter->second->GetAsString(&tmp) && | |
932 tmp.empty())) { | |
933 return false; | |
934 } | |
935 return true; | |
936 } | |
937 | |
938 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( | 23 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( |
939 ConfigurationPolicyProvider* provider) | 24 ConfigurationPolicyProvider* provider) |
940 : provider_(provider), | 25 : provider_(provider), |
941 initialization_complete_(false) { | 26 initialization_complete_(false) { |
942 if (provider_) { | 27 if (provider_) { |
943 // Read initial policy. | 28 // Read initial policy. |
944 policy_keeper_.reset(new ConfigurationPolicyPrefKeeper(provider_)); | 29 prefs_.reset(CreatePreferencesFromPolicies()); |
945 registrar_.Init(provider_, this); | 30 registrar_.Init(provider_, this); |
946 initialization_complete_ = provider_->IsInitializationComplete(); | 31 initialization_complete_ = provider_->IsInitializationComplete(); |
947 } else { | 32 } else { |
948 initialization_complete_ = true; | 33 initialization_complete_ = true; |
949 } | 34 } |
950 } | 35 } |
951 | 36 |
952 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { | 37 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { |
953 } | 38 } |
954 | 39 |
955 void ConfigurationPolicyPrefStore::AddObserver(PrefStore::Observer* observer) { | 40 void ConfigurationPolicyPrefStore::AddObserver(PrefStore::Observer* observer) { |
956 observers_.AddObserver(observer); | 41 observers_.AddObserver(observer); |
957 } | 42 } |
958 | 43 |
959 void ConfigurationPolicyPrefStore::RemoveObserver( | 44 void ConfigurationPolicyPrefStore::RemoveObserver( |
960 PrefStore::Observer* observer) { | 45 PrefStore::Observer* observer) { |
961 observers_.RemoveObserver(observer); | 46 observers_.RemoveObserver(observer); |
962 } | 47 } |
963 | 48 |
964 bool ConfigurationPolicyPrefStore::IsInitializationComplete() const { | 49 bool ConfigurationPolicyPrefStore::IsInitializationComplete() const { |
965 return initialization_complete_; | 50 return initialization_complete_; |
966 } | 51 } |
967 | 52 |
968 PrefStore::ReadResult | 53 PrefStore::ReadResult |
969 ConfigurationPolicyPrefStore::GetValue(const std::string& key, | 54 ConfigurationPolicyPrefStore::GetValue(const std::string& key, |
970 const Value** value) const { | 55 const Value** value) const { |
971 if (policy_keeper_.get()) | 56 const Value* stored_value = NULL; |
972 return policy_keeper_->GetValue(key, value); | 57 if (!prefs_.get() || !prefs_->GetValue(key, &stored_value)) |
58 return PrefStore::READ_NO_VALUE; | |
973 | 59 |
974 return PrefStore::READ_NO_VALUE; | 60 // Check whether there's a default value, which indicates READ_USE_DEFAULT |
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
I think this is not used anymore, maybe we should
Joao da Silva
2011/10/11 15:09:23
Removed. I guess I was on autopilot while shufflin
| |
61 // should be returned. | |
62 if (stored_value->IsType(Value::TYPE_NULL)) | |
63 return PrefStore::READ_USE_DEFAULT; | |
64 | |
65 if (value) | |
66 *value = stored_value; | |
67 return PrefStore::READ_OK; | |
975 } | 68 } |
976 | 69 |
977 void ConfigurationPolicyPrefStore::OnUpdatePolicy() { | 70 void ConfigurationPolicyPrefStore::OnUpdatePolicy() { |
978 Refresh(); | 71 Refresh(); |
979 } | 72 } |
980 | 73 |
981 void ConfigurationPolicyPrefStore::OnProviderGoingAway() { | 74 void ConfigurationPolicyPrefStore::OnProviderGoingAway() { |
982 provider_ = NULL; | 75 provider_ = NULL; |
983 } | 76 } |
984 | 77 |
985 // static | 78 // static |
986 ConfigurationPolicyPrefStore* | 79 ConfigurationPolicyPrefStore* |
987 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore() { | 80 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore() { |
988 BrowserPolicyConnector* connector = | |
989 g_browser_process->browser_policy_connector(); | |
990 return new ConfigurationPolicyPrefStore( | 81 return new ConfigurationPolicyPrefStore( |
991 connector->GetManagedPlatformProvider()); | 82 g_browser_process->browser_policy_connector()-> |
83 GetManagedPlatformProvider()); | |
992 } | 84 } |
993 | 85 |
994 // static | 86 // static |
995 ConfigurationPolicyPrefStore* | 87 ConfigurationPolicyPrefStore* |
996 ConfigurationPolicyPrefStore::CreateManagedCloudPolicyPrefStore() { | 88 ConfigurationPolicyPrefStore::CreateManagedCloudPolicyPrefStore() { |
997 return new ConfigurationPolicyPrefStore( | 89 return new ConfigurationPolicyPrefStore( |
998 g_browser_process->browser_policy_connector()->GetManagedCloudProvider()); | 90 g_browser_process->browser_policy_connector()->GetManagedCloudProvider()); |
999 } | 91 } |
1000 | 92 |
1001 // static | 93 // static |
1002 ConfigurationPolicyPrefStore* | 94 ConfigurationPolicyPrefStore* |
1003 ConfigurationPolicyPrefStore::CreateRecommendedPlatformPolicyPrefStore() { | 95 ConfigurationPolicyPrefStore::CreateRecommendedPlatformPolicyPrefStore() { |
1004 BrowserPolicyConnector* connector = | |
1005 g_browser_process->browser_policy_connector(); | |
1006 return new ConfigurationPolicyPrefStore( | 96 return new ConfigurationPolicyPrefStore( |
1007 connector->GetRecommendedPlatformProvider()); | 97 g_browser_process->browser_policy_connector()-> |
98 GetRecommendedPlatformProvider()); | |
1008 } | 99 } |
1009 | 100 |
1010 // static | 101 // static |
1011 ConfigurationPolicyPrefStore* | 102 ConfigurationPolicyPrefStore* |
1012 ConfigurationPolicyPrefStore::CreateRecommendedCloudPolicyPrefStore() { | 103 ConfigurationPolicyPrefStore::CreateRecommendedCloudPolicyPrefStore() { |
1013 return new ConfigurationPolicyPrefStore( | 104 return new ConfigurationPolicyPrefStore( |
1014 g_browser_process->browser_policy_connector()-> | 105 g_browser_process->browser_policy_connector()-> |
1015 GetRecommendedCloudProvider()); | 106 GetRecommendedCloudProvider()); |
1016 } | 107 } |
1017 | 108 |
1018 /* static */ | 109 // static |
1019 const ConfigurationPolicyProvider::PolicyDefinitionList* | 110 const ConfigurationPolicyProvider::PolicyDefinitionList* |
1020 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { | 111 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { |
1021 static ConfigurationPolicyProvider::PolicyDefinitionList::Entry entries[] = { | 112 static ConfigurationPolicyProvider::PolicyDefinitionList::Entry entries[] = { |
1022 { kPolicyHomepageLocation, Value::TYPE_STRING, key::kHomepageLocation }, | 113 { kPolicyHomepageLocation, Value::TYPE_STRING, key::kHomepageLocation }, |
1023 { kPolicyHomepageIsNewTabPage, Value::TYPE_BOOLEAN, | 114 { kPolicyHomepageIsNewTabPage, Value::TYPE_BOOLEAN, |
1024 key::kHomepageIsNewTabPage }, | 115 key::kHomepageIsNewTabPage }, |
1025 { kPolicyRestoreOnStartup, Value::TYPE_INTEGER, key::kRestoreOnStartup }, | 116 { kPolicyRestoreOnStartup, Value::TYPE_INTEGER, key::kRestoreOnStartup }, |
1026 { kPolicyRestoreOnStartupURLs, Value::TYPE_LIST, | 117 { kPolicyRestoreOnStartupURLs, Value::TYPE_LIST, |
1027 key::kRestoreOnStartupURLs }, | 118 key::kRestoreOnStartupURLs }, |
1028 { kPolicyDefaultSearchProviderEnabled, Value::TYPE_BOOLEAN, | 119 { kPolicyDefaultSearchProviderEnabled, Value::TYPE_BOOLEAN, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1204 #endif | 295 #endif |
1205 }; | 296 }; |
1206 | 297 |
1207 static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = { | 298 static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = { |
1208 entries, | 299 entries, |
1209 entries + arraysize(entries), | 300 entries + arraysize(entries), |
1210 }; | 301 }; |
1211 return &policy_list; | 302 return &policy_list; |
1212 } | 303 } |
1213 | 304 |
305 // static | |
1214 bool | 306 bool |
1215 ConfigurationPolicyPrefStore::IsProxyPolicy(ConfigurationPolicyType policy) { | 307 ConfigurationPolicyPrefStore::IsProxyPolicy(ConfigurationPolicyType policy) { |
1216 return policy == kPolicyProxyMode || | 308 return policy == kPolicyProxyMode || |
1217 policy == kPolicyProxyServerMode || | 309 policy == kPolicyProxyServerMode || |
1218 policy == kPolicyProxyServer || | 310 policy == kPolicyProxyServer || |
1219 policy == kPolicyProxyPacUrl || | 311 policy == kPolicyProxyPacUrl || |
1220 policy == kPolicyProxyBypassList; | 312 policy == kPolicyProxyBypassList; |
1221 } | 313 } |
1222 | 314 |
1223 void ConfigurationPolicyPrefStore::Refresh() { | 315 void ConfigurationPolicyPrefStore::Refresh() { |
1224 if (!provider_) | 316 if (!provider_) |
1225 return; | 317 return; |
1226 | 318 scoped_ptr<PrefValueMap> new_prefs(CreatePreferencesFromPolicies()); |
1227 // Construct a new keeper, determine what changed and swap the keeper in. | |
1228 scoped_ptr<ConfigurationPolicyPrefKeeper> new_keeper( | |
1229 new ConfigurationPolicyPrefKeeper(provider_)); | |
1230 std::vector<std::string> changed_prefs; | 319 std::vector<std::string> changed_prefs; |
1231 new_keeper->GetDifferingPrefPaths(policy_keeper_.get(), &changed_prefs); | 320 new_prefs->GetDifferingKeys(prefs_.get(), &changed_prefs); |
1232 policy_keeper_.swap(new_keeper); | 321 prefs_.swap(new_prefs); |
1233 | 322 |
1234 // Send out change notifications. | 323 // Send out change notifications. |
1235 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin()); | 324 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin()); |
1236 pref != changed_prefs.end(); | 325 pref != changed_prefs.end(); |
1237 ++pref) { | 326 ++pref) { |
1238 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | 327 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, |
1239 OnPrefValueChanged(*pref)); | 328 OnPrefValueChanged(*pref)); |
1240 } | 329 } |
1241 | 330 |
1242 // Update the initialization flag. | 331 // Update the initialization flag. |
1243 if (!initialization_complete_ && | 332 if (!initialization_complete_ && |
1244 provider_->IsInitializationComplete()) { | 333 provider_->IsInitializationComplete()) { |
1245 initialization_complete_ = true; | 334 initialization_complete_ = true; |
1246 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | 335 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, |
1247 OnInitializationCompleted(true)); | 336 OnInitializationCompleted(true)); |
1248 } | 337 } |
1249 } | 338 } |
1250 | 339 |
340 PrefValueMap* ConfigurationPolicyPrefStore::CreatePreferencesFromPolicies() { | |
341 scoped_ptr<PrefValueMap> prefs(new PrefValueMap); | |
342 | |
343 PolicyMap policies; | |
344 if (!provider_->Provide(&policies)) | |
345 LOG(WARNING) << "Failed to get policy from provider."; | |
346 | |
347 const ConfigurationPolicyHandler::HandlerList* handlers = | |
348 g_browser_process->browser_policy_connector()-> | |
349 GetConfigurationPolicyHandlerList(); | |
350 | |
351 ConfigurationPolicyHandler::HandlerList::const_iterator handler; | |
352 for (handler = handlers->begin(); handler != handlers->end(); ++handler) { | |
353 PolicyErrorMap errors; | |
354 if ((*handler)->CheckPolicySettings(&policies, &errors)) { | |
355 (*handler)->ApplyPolicySettings(&policies, prefs.get()); | |
356 } else { | |
357 PolicyErrorMap::const_iterator iter; | |
358 for (iter = errors.begin(); iter != errors.end(); ++iter) { | |
359 string16 policy = PolicyStatus::GetPolicyName(iter->first); | |
Mattias Nissler (ping if slow)
2011/10/11 11:10:57
Hm, maybe the GetPolicyName() call should move to
Mattias Nissler (ping if slow)
2011/10/12 17:10:00
What about this?
Joao da Silva
2011/10/21 14:22:20
GetPolicyName() moved to policy_constants.h in htt
| |
360 LOG(WARNING) << "Policy " << policy << ": " << iter->second; | |
361 } | |
362 } | |
363 } | |
364 | |
365 return prefs.release(); | |
366 } | |
367 | |
1251 } // namespace policy | 368 } // namespace policy |
OLD | NEW |