Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / policy / configuration_policy_handler_list_factory.cc
blob46b96ee7f6a9847fcfc1dab6053a046f3d977668
1 // Copyright 2013 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.
5 #include "chrome/browser/policy/configuration_policy_handler_list_factory.h"
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/values.h"
11 #include "chrome/browser/net/proxy_policy_handler.h"
12 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h"
13 #include "chrome/browser/profiles/incognito_mode_policy_handler.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/password_manager/core/common/password_manager_pref_names.h"
17 #include "components/policy/core/browser/autofill_policy_handler.h"
18 #include "components/policy/core/browser/configuration_policy_handler.h"
19 #include "components/policy/core/browser/configuration_policy_handler_list.h"
20 #include "components/policy/core/browser/configuration_policy_handler_parameters.h"
21 #include "components/policy/core/browser/url_blacklist_policy_handler.h"
22 #include "components/policy/core/common/policy_details.h"
23 #include "components/policy/core/common/policy_map.h"
24 #include "components/policy/core/common/policy_pref_names.h"
25 #include "components/policy/core/common/schema.h"
26 #include "components/rappor/rappor_pref_names.h"
27 #include "components/search_engines/default_search_policy_handler.h"
28 #include "components/translate/core/common/translate_pref_names.h"
29 #include "policy/policy_constants.h"
31 #if defined(OS_ANDROID)
32 #include "chrome/browser/search/contextual_search_policy_handler_android.h"
33 #endif
35 #if !defined(OS_IOS)
36 #include "chrome/browser/net/disk_cache_dir_policy_handler.h"
37 #include "chrome/browser/policy/file_selection_dialogs_policy_handler.h"
38 #include "chrome/browser/policy/javascript_policy_handler.h"
39 #include "chrome/browser/policy/network_prediction_policy_handler.h"
40 #include "chrome/browser/sessions/restore_on_startup_policy_handler.h"
41 #include "chrome/browser/sync/sync_policy_handler.h"
42 #endif
44 #if defined(OS_CHROMEOS)
45 #include "chrome/browser/chromeos/policy/configuration_policy_handler_chromeos.h"
46 #include "chromeos/chromeos_pref_names.h"
47 #include "chromeos/dbus/power_policy_controller.h"
48 #include "components/user_manager/user.h"
49 #include "components/user_manager/user_manager.h"
50 #include "ui/chromeos/accessibility_types.h"
51 #endif
53 #if !defined(OS_ANDROID) && !defined(OS_IOS)
54 #include "chrome/browser/download/download_dir_policy_handler.h"
55 #endif
57 #if defined(ENABLE_EXTENSIONS)
58 #include "chrome/browser/extensions/api/messaging/native_messaging_policy_handler.h"
59 #include "chrome/browser/extensions/extension_management_constants.h"
60 #include "chrome/browser/extensions/policy_handlers.h"
61 #include "extensions/browser/pref_names.h"
62 #include "extensions/common/manifest.h"
63 #endif
65 namespace policy {
67 namespace {
69 // List of policy types to preference names. This is used for simple policies
70 // that directly map to a single preference.
71 const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
72 { key::kHomepageLocation,
73 prefs::kHomePage,
74 base::Value::TYPE_STRING },
75 { key::kHomepageIsNewTabPage,
76 prefs::kHomePageIsNewTabPage,
77 base::Value::TYPE_BOOLEAN },
78 { key::kRestoreOnStartupURLs,
79 prefs::kURLsToRestoreOnStartup,
80 base::Value::TYPE_LIST },
81 { key::kAlternateErrorPagesEnabled,
82 prefs::kAlternateErrorPagesEnabled,
83 base::Value::TYPE_BOOLEAN },
84 { key::kSearchSuggestEnabled,
85 prefs::kSearchSuggestEnabled,
86 base::Value::TYPE_BOOLEAN },
87 { key::kBuiltInDnsClientEnabled,
88 prefs::kBuiltInDnsClientEnabled,
89 base::Value::TYPE_BOOLEAN },
90 { key::kWPADQuickCheckEnabled,
91 prefs::kQuickCheckEnabled,
92 base::Value::TYPE_BOOLEAN },
93 { key::kDisableSpdy,
94 prefs::kDisableSpdy,
95 base::Value::TYPE_BOOLEAN },
96 { key::kSafeBrowsingEnabled,
97 prefs::kSafeBrowsingEnabled,
98 base::Value::TYPE_BOOLEAN },
99 { key::kForceSafeSearch,
100 prefs::kForceSafeSearch,
101 base::Value::TYPE_BOOLEAN },
102 { key::kForceGoogleSafeSearch,
103 prefs::kForceGoogleSafeSearch,
104 base::Value::TYPE_BOOLEAN },
105 { key::kForceYouTubeSafetyMode,
106 prefs::kForceYouTubeSafetyMode,
107 base::Value::TYPE_BOOLEAN },
108 { key::kPasswordManagerEnabled,
109 password_manager::prefs::kPasswordManagerSavingEnabled,
110 base::Value::TYPE_BOOLEAN },
111 { key::kPasswordManagerAllowShowPasswords,
112 password_manager::prefs::kPasswordManagerAllowShowPasswords,
113 base::Value::TYPE_BOOLEAN },
114 { key::kPrintingEnabled,
115 prefs::kPrintingEnabled,
116 base::Value::TYPE_BOOLEAN },
117 { key::kDisablePrintPreview,
118 prefs::kPrintPreviewDisabled,
119 base::Value::TYPE_BOOLEAN },
120 { key::kMetricsReportingEnabled,
121 prefs::kMetricsReportingEnabled,
122 base::Value::TYPE_BOOLEAN },
123 { key::kMetricsReportingEnabled,
124 rappor::prefs::kRapporEnabled,
125 base::Value::TYPE_BOOLEAN },
126 { key::kApplicationLocaleValue,
127 prefs::kApplicationLocale,
128 base::Value::TYPE_STRING },
129 { key::kDisabledPlugins,
130 prefs::kPluginsDisabledPlugins,
131 base::Value::TYPE_LIST },
132 { key::kDisabledPluginsExceptions,
133 prefs::kPluginsDisabledPluginsExceptions,
134 base::Value::TYPE_LIST },
135 { key::kEnabledPlugins,
136 prefs::kPluginsEnabledPlugins,
137 base::Value::TYPE_LIST },
138 { key::kShowHomeButton,
139 prefs::kShowHomeButton,
140 base::Value::TYPE_BOOLEAN },
141 { key::kSavingBrowserHistoryDisabled,
142 prefs::kSavingBrowserHistoryDisabled,
143 base::Value::TYPE_BOOLEAN },
144 { key::kAllowDeletingBrowserHistory,
145 prefs::kAllowDeletingBrowserHistory,
146 base::Value::TYPE_BOOLEAN },
147 { key::kDeveloperToolsDisabled,
148 prefs::kDevToolsDisabled,
149 base::Value::TYPE_BOOLEAN },
150 { key::kBlockThirdPartyCookies,
151 prefs::kBlockThirdPartyCookies,
152 base::Value::TYPE_BOOLEAN },
153 { key::kDefaultCookiesSetting,
154 prefs::kManagedDefaultCookiesSetting,
155 base::Value::TYPE_INTEGER },
156 { key::kDefaultImagesSetting,
157 prefs::kManagedDefaultImagesSetting,
158 base::Value::TYPE_INTEGER },
159 { key::kDefaultPluginsSetting,
160 prefs::kManagedDefaultPluginsSetting,
161 base::Value::TYPE_INTEGER },
162 { key::kDefaultPopupsSetting,
163 prefs::kManagedDefaultPopupsSetting,
164 base::Value::TYPE_INTEGER },
165 { key::kAutoSelectCertificateForUrls,
166 prefs::kManagedAutoSelectCertificateForUrls,
167 base::Value::TYPE_LIST },
168 { key::kCookiesAllowedForUrls,
169 prefs::kManagedCookiesAllowedForUrls,
170 base::Value::TYPE_LIST },
171 { key::kCookiesBlockedForUrls,
172 prefs::kManagedCookiesBlockedForUrls,
173 base::Value::TYPE_LIST },
174 { key::kCookiesSessionOnlyForUrls,
175 prefs::kManagedCookiesSessionOnlyForUrls,
176 base::Value::TYPE_LIST },
177 { key::kImagesAllowedForUrls,
178 prefs::kManagedImagesAllowedForUrls,
179 base::Value::TYPE_LIST },
180 { key::kImagesBlockedForUrls,
181 prefs::kManagedImagesBlockedForUrls,
182 base::Value::TYPE_LIST },
183 { key::kJavaScriptAllowedForUrls,
184 prefs::kManagedJavaScriptAllowedForUrls,
185 base::Value::TYPE_LIST },
186 { key::kJavaScriptBlockedForUrls,
187 prefs::kManagedJavaScriptBlockedForUrls,
188 base::Value::TYPE_LIST },
189 { key::kPluginsAllowedForUrls,
190 prefs::kManagedPluginsAllowedForUrls,
191 base::Value::TYPE_LIST },
192 { key::kPluginsBlockedForUrls,
193 prefs::kManagedPluginsBlockedForUrls,
194 base::Value::TYPE_LIST },
195 { key::kPopupsAllowedForUrls,
196 prefs::kManagedPopupsAllowedForUrls,
197 base::Value::TYPE_LIST },
198 { key::kPopupsBlockedForUrls,
199 prefs::kManagedPopupsBlockedForUrls,
200 base::Value::TYPE_LIST },
201 { key::kNotificationsAllowedForUrls,
202 prefs::kManagedNotificationsAllowedForUrls,
203 base::Value::TYPE_LIST },
204 { key::kNotificationsBlockedForUrls,
205 prefs::kManagedNotificationsBlockedForUrls,
206 base::Value::TYPE_LIST },
207 { key::kDefaultNotificationsSetting,
208 prefs::kManagedDefaultNotificationsSetting,
209 base::Value::TYPE_INTEGER },
210 { key::kDefaultGeolocationSetting,
211 prefs::kManagedDefaultGeolocationSetting,
212 base::Value::TYPE_INTEGER },
213 { key::kSigninAllowed,
214 prefs::kSigninAllowed,
215 base::Value::TYPE_BOOLEAN },
216 { key::kDisableSSLRecordSplitting,
217 prefs::kDisableSSLRecordSplitting,
218 base::Value::TYPE_BOOLEAN },
219 { key::kEnableOnlineRevocationChecks,
220 prefs::kCertRevocationCheckingEnabled,
221 base::Value::TYPE_BOOLEAN },
222 { key::kRequireOnlineRevocationChecksForLocalAnchors,
223 prefs::kCertRevocationCheckingRequiredLocalAnchors,
224 base::Value::TYPE_BOOLEAN },
225 { key::kAuthSchemes,
226 prefs::kAuthSchemes,
227 base::Value::TYPE_STRING },
228 { key::kDisableAuthNegotiateCnameLookup,
229 prefs::kDisableAuthNegotiateCnameLookup,
230 base::Value::TYPE_BOOLEAN },
231 { key::kEnableAuthNegotiatePort,
232 prefs::kEnableAuthNegotiatePort,
233 base::Value::TYPE_BOOLEAN },
234 { key::kAuthServerWhitelist,
235 prefs::kAuthServerWhitelist,
236 base::Value::TYPE_STRING },
237 { key::kAuthNegotiateDelegateWhitelist,
238 prefs::kAuthNegotiateDelegateWhitelist,
239 base::Value::TYPE_STRING },
240 { key::kGSSAPILibraryName,
241 prefs::kGSSAPILibraryName,
242 base::Value::TYPE_STRING },
243 { key::kAllowCrossOriginAuthPrompt,
244 prefs::kAllowCrossOriginAuthPrompt,
245 base::Value::TYPE_BOOLEAN },
246 { key::kDisable3DAPIs,
247 prefs::kDisable3DAPIs,
248 base::Value::TYPE_BOOLEAN },
249 { key::kDisablePluginFinder,
250 prefs::kDisablePluginFinder,
251 base::Value::TYPE_BOOLEAN },
252 { key::kDiskCacheSize,
253 prefs::kDiskCacheSize,
254 base::Value::TYPE_INTEGER },
255 { key::kMediaCacheSize,
256 prefs::kMediaCacheSize,
257 base::Value::TYPE_INTEGER },
258 { key::kPolicyRefreshRate,
259 policy_prefs::kUserPolicyRefreshRate,
260 base::Value::TYPE_INTEGER },
261 { key::kDevicePolicyRefreshRate,
262 prefs::kDevicePolicyRefreshRate,
263 base::Value::TYPE_INTEGER },
264 { key::kDefaultBrowserSettingEnabled,
265 prefs::kDefaultBrowserSettingEnabled,
266 base::Value::TYPE_BOOLEAN },
267 { key::kCloudPrintProxyEnabled,
268 prefs::kCloudPrintProxyEnabled,
269 base::Value::TYPE_BOOLEAN },
270 { key::kCloudPrintSubmitEnabled,
271 prefs::kCloudPrintSubmitEnabled,
272 base::Value::TYPE_BOOLEAN },
273 { key::kTranslateEnabled,
274 prefs::kEnableTranslate,
275 base::Value::TYPE_BOOLEAN },
276 { key::kAllowOutdatedPlugins,
277 prefs::kPluginsAllowOutdated,
278 base::Value::TYPE_BOOLEAN },
279 { key::kAlwaysAuthorizePlugins,
280 prefs::kPluginsAlwaysAuthorize,
281 base::Value::TYPE_BOOLEAN },
282 { key::kBookmarkBarEnabled,
283 bookmarks::prefs::kShowBookmarkBar,
284 base::Value::TYPE_BOOLEAN },
285 { key::kEditBookmarksEnabled,
286 bookmarks::prefs::kEditBookmarksEnabled,
287 base::Value::TYPE_BOOLEAN },
288 { key::kShowAppsShortcutInBookmarkBar,
289 bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
290 base::Value::TYPE_BOOLEAN },
291 { key::kAllowFileSelectionDialogs,
292 prefs::kAllowFileSelectionDialogs,
293 base::Value::TYPE_BOOLEAN },
294 { key::kImportBookmarks,
295 prefs::kImportBookmarks,
296 base::Value::TYPE_BOOLEAN },
297 { key::kImportHistory,
298 prefs::kImportHistory,
299 base::Value::TYPE_BOOLEAN },
300 { key::kImportHomepage,
301 prefs::kImportHomepage,
302 base::Value::TYPE_BOOLEAN },
303 { key::kImportSearchEngine,
304 prefs::kImportSearchEngine,
305 base::Value::TYPE_BOOLEAN },
306 { key::kImportSavedPasswords,
307 prefs::kImportSavedPasswords,
308 base::Value::TYPE_BOOLEAN },
309 { key::kImportAutofillFormData,
310 prefs::kImportAutofillFormData,
311 base::Value::TYPE_BOOLEAN },
312 { key::kMaxConnectionsPerProxy,
313 prefs::kMaxConnectionsPerProxy,
314 base::Value::TYPE_INTEGER },
315 { key::kURLWhitelist,
316 policy_prefs::kUrlWhitelist,
317 base::Value::TYPE_LIST },
318 { key::kRestrictSigninToPattern,
319 prefs::kGoogleServicesUsernamePattern,
320 base::Value::TYPE_STRING },
321 { key::kDefaultMediaStreamSetting,
322 prefs::kManagedDefaultMediaStreamSetting,
323 base::Value::TYPE_INTEGER },
324 { key::kDisableSafeBrowsingProceedAnyway,
325 prefs::kSafeBrowsingProceedAnywayDisabled,
326 base::Value::TYPE_BOOLEAN },
328 #if defined(ENABLE_SPELLCHECK)
329 { key::kSpellCheckServiceEnabled,
330 prefs::kSpellCheckUseSpellingService,
331 base::Value::TYPE_BOOLEAN },
332 #endif // defined(ENABLE_SPELLCHECK)
334 { key::kDisableScreenshots,
335 prefs::kDisableScreenshots,
336 base::Value::TYPE_BOOLEAN },
337 { key::kAudioCaptureAllowed,
338 prefs::kAudioCaptureAllowed,
339 base::Value::TYPE_BOOLEAN },
340 { key::kVideoCaptureAllowed,
341 prefs::kVideoCaptureAllowed,
342 base::Value::TYPE_BOOLEAN },
343 { key::kAudioCaptureAllowedUrls,
344 prefs::kAudioCaptureAllowedUrls,
345 base::Value::TYPE_LIST },
346 { key::kVideoCaptureAllowedUrls,
347 prefs::kVideoCaptureAllowedUrls,
348 base::Value::TYPE_LIST },
349 { key::kHideWebStoreIcon,
350 prefs::kHideWebStoreIcon,
351 base::Value::TYPE_BOOLEAN },
352 { key::kVariationsRestrictParameter,
353 prefs::kVariationsRestrictParameter,
354 base::Value::TYPE_STRING },
355 { key::kSupervisedUserCreationEnabled,
356 prefs::kSupervisedUserCreationAllowed,
357 base::Value::TYPE_BOOLEAN },
358 { key::kForceEphemeralProfiles,
359 prefs::kForceEphemeralProfiles,
360 base::Value::TYPE_BOOLEAN },
361 { key::kSSLVersionMin,
362 prefs::kSSLVersionMin,
363 base::Value::TYPE_STRING },
364 { key::kSSLVersionFallbackMin,
365 prefs::kSSLVersionFallbackMin,
366 base::Value::TYPE_STRING },
368 #if !defined(OS_MACOSX) && !defined(OS_IOS)
369 { key::kFullscreenAllowed,
370 prefs::kFullscreenAllowed,
371 base::Value::TYPE_BOOLEAN },
372 #if defined(ENABLE_EXTENSIONS)
373 { key::kFullscreenAllowed,
374 extensions::pref_names::kAppFullscreenAllowed,
375 base::Value::TYPE_BOOLEAN },
376 #endif // defined(ENABLE_EXTENSIONS)
377 #endif // !defined(OS_MACOSX) && !defined(OS_IOS)
379 #if defined(OS_CHROMEOS)
380 { key::kChromeOsLockOnIdleSuspend,
381 prefs::kEnableAutoScreenLock,
382 base::Value::TYPE_BOOLEAN },
383 { key::kChromeOsReleaseChannel,
384 prefs::kChromeOsReleaseChannel,
385 base::Value::TYPE_STRING },
386 { key::kDriveDisabled,
387 prefs::kDisableDrive,
388 base::Value::TYPE_BOOLEAN },
389 { key::kDriveDisabledOverCellular,
390 prefs::kDisableDriveOverCellular,
391 base::Value::TYPE_BOOLEAN },
392 { key::kExternalStorageDisabled,
393 prefs::kExternalStorageDisabled,
394 base::Value::TYPE_BOOLEAN },
395 { key::kAudioOutputAllowed,
396 chromeos::prefs::kAudioOutputAllowed,
397 base::Value::TYPE_BOOLEAN },
398 { key::kShowLogoutButtonInTray,
399 prefs::kShowLogoutButtonInTray,
400 base::Value::TYPE_BOOLEAN },
401 { key::kShelfAutoHideBehavior,
402 prefs::kShelfAutoHideBehaviorLocal,
403 base::Value::TYPE_STRING },
404 { key::kSessionLengthLimit,
405 prefs::kSessionLengthLimit,
406 base::Value::TYPE_INTEGER },
407 { key::kWaitForInitialUserActivity,
408 prefs::kSessionWaitForInitialUserActivity,
409 base::Value::TYPE_BOOLEAN },
410 { key::kPowerManagementUsesAudioActivity,
411 prefs::kPowerUseAudioActivity,
412 base::Value::TYPE_BOOLEAN },
413 { key::kPowerManagementUsesVideoActivity,
414 prefs::kPowerUseVideoActivity,
415 base::Value::TYPE_BOOLEAN },
416 { key::kAllowScreenWakeLocks,
417 prefs::kPowerAllowScreenWakeLocks,
418 base::Value::TYPE_BOOLEAN },
419 { key::kWaitForInitialUserActivity,
420 prefs::kPowerWaitForInitialUserActivity,
421 base::Value::TYPE_BOOLEAN },
422 { key::kTermsOfServiceURL,
423 prefs::kTermsOfServiceURL,
424 base::Value::TYPE_STRING },
425 { key::kShowAccessibilityOptionsInSystemTrayMenu,
426 prefs::kShouldAlwaysShowAccessibilityMenu,
427 base::Value::TYPE_BOOLEAN },
428 { key::kLargeCursorEnabled,
429 prefs::kAccessibilityLargeCursorEnabled,
430 base::Value::TYPE_BOOLEAN },
431 { key::kSpokenFeedbackEnabled,
432 prefs::kAccessibilitySpokenFeedbackEnabled,
433 base::Value::TYPE_BOOLEAN },
434 { key::kHighContrastEnabled,
435 prefs::kAccessibilityHighContrastEnabled,
436 base::Value::TYPE_BOOLEAN },
437 { key::kVirtualKeyboardEnabled,
438 prefs::kAccessibilityVirtualKeyboardEnabled,
439 base::Value::TYPE_BOOLEAN },
440 { key::kDeviceLoginScreenDefaultLargeCursorEnabled,
441 NULL,
442 base::Value::TYPE_BOOLEAN },
443 { key::kDeviceLoginScreenDefaultSpokenFeedbackEnabled,
444 NULL,
445 base::Value::TYPE_BOOLEAN },
446 { key::kDeviceLoginScreenDefaultHighContrastEnabled,
447 NULL,
448 base::Value::TYPE_BOOLEAN },
449 { key::kDeviceLoginScreenDefaultVirtualKeyboardEnabled,
450 NULL,
451 base::Value::TYPE_BOOLEAN },
452 { key::kRebootAfterUpdate,
453 prefs::kRebootAfterUpdate,
454 base::Value::TYPE_BOOLEAN },
455 { key::kAttestationEnabledForUser,
456 prefs::kAttestationEnabled,
457 base::Value::TYPE_BOOLEAN },
458 { key::kChromeOsMultiProfileUserBehavior,
459 prefs::kMultiProfileUserBehavior,
460 base::Value::TYPE_STRING },
461 { key::kKeyboardDefaultToFunctionKeys,
462 prefs::kLanguageSendFunctionKeys,
463 base::Value::TYPE_BOOLEAN },
464 { key::kTouchVirtualKeyboardEnabled,
465 prefs::kTouchVirtualKeyboardEnabled,
466 base::Value::TYPE_BOOLEAN },
467 { key::kEasyUnlockAllowed,
468 prefs::kEasyUnlockAllowed,
469 base::Value::TYPE_BOOLEAN },
470 #endif // defined(OS_CHROMEOS)
472 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
473 { key::kBackgroundModeEnabled,
474 prefs::kBackgroundModeEnabled,
475 base::Value::TYPE_BOOLEAN },
476 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
478 #if defined(OS_ANDROID)
479 { key::kDataCompressionProxyEnabled,
480 data_reduction_proxy::prefs::kDataReductionProxyEnabled,
481 base::Value::TYPE_BOOLEAN },
482 #endif // defined(OS_ANDROID)
484 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
485 { key::kNativeMessagingUserLevelHosts,
486 extensions::pref_names::kNativeMessagingUserLevelHosts,
487 base::Value::TYPE_BOOLEAN },
488 { key::kBrowserGuestModeEnabled,
489 prefs::kBrowserGuestModeEnabled,
490 base::Value::TYPE_BOOLEAN },
491 { key::kBrowserAddPersonEnabled,
492 prefs::kBrowserAddPersonEnabled,
493 base::Value::TYPE_BOOLEAN },
494 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
497 #if defined(ENABLE_EXTENSIONS)
498 void GetExtensionAllowedTypesMap(
499 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) {
500 // Mapping from extension type names to Manifest::Type.
501 for (size_t index = 0;
502 index < extensions::schema_constants::kAllowedTypesMapSize;
503 ++index) {
504 const extensions::schema_constants::AllowedTypesMapEntry& entry =
505 extensions::schema_constants::kAllowedTypesMap[index];
506 result->push_back(new StringMappingListPolicyHandler::MappingEntry(
507 entry.name,
508 scoped_ptr<base::Value>(
509 new base::FundamentalValue(entry.manifest_type))));
512 #endif
514 #if !defined(OS_IOS)
515 void GetDeprecatedFeaturesMap(
516 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) {
517 // Maps feature tags as specified in policy to the corresponding switch to
518 // re-enable them.
519 // TODO(atwilson): Remove after 2015-04-30 per http://crbug.com/374782.
520 result->push_back(new StringMappingListPolicyHandler::MappingEntry(
521 "ShowModalDialog_EffectiveUntil20150430",
522 scoped_ptr<base::Value>(new base::StringValue(
523 switches::kEnableShowModalDialog))));
525 #endif // !defined(OS_IOS)
527 } // namespace
529 void PopulatePolicyHandlerParameters(PolicyHandlerParameters* parameters) {
530 #if defined(OS_CHROMEOS)
531 if (user_manager::UserManager::IsInitialized()) {
532 const user_manager::User* user =
533 user_manager::UserManager::Get()->GetActiveUser();
534 if (user)
535 parameters->user_id_hash = user->username_hash();
537 #endif
540 scoped_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(
541 const Schema& chrome_schema) {
542 scoped_ptr<ConfigurationPolicyHandlerList> handlers(
543 new ConfigurationPolicyHandlerList(
544 base::Bind(&PopulatePolicyHandlerParameters),
545 base::Bind(&GetChromePolicyDetails)));
546 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) {
547 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
548 new SimplePolicyHandler(kSimplePolicyMap[i].policy_name,
549 kSimplePolicyMap[i].preference_path,
550 kSimplePolicyMap[i].value_type)));
553 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
554 new AutofillPolicyHandler()));
555 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
556 new DefaultSearchPolicyHandler()));
557 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
558 new IncognitoModePolicyHandler()));
559 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
560 new ManagedBookmarksPolicyHandler(chrome_schema)));
561 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
562 new ProxyPolicyHandler()));
563 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
564 new URLBlacklistPolicyHandler()));
566 #if defined(OS_ANDROID)
567 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
568 new ContextualSearchPolicyHandlerAndroid()));
569 #endif
571 #if !defined(OS_IOS)
572 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
573 new FileSelectionDialogsPolicyHandler()));
574 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
575 new JavascriptPolicyHandler()));
576 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
577 new NetworkPredictionPolicyHandler()));
578 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
579 new RestoreOnStartupPolicyHandler()));
580 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
581 new browser_sync::SyncPolicyHandler()));
583 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
584 new StringMappingListPolicyHandler(
585 key::kEnableDeprecatedWebPlatformFeatures,
586 prefs::kEnableDeprecatedWebPlatformFeatures,
587 base::Bind(GetDeprecatedFeaturesMap))));
588 #endif // !defined(OS_IOS)
590 #if defined(ENABLE_EXTENSIONS)
591 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
592 new extensions::ExtensionListPolicyHandler(
593 key::kExtensionInstallWhitelist,
594 extensions::pref_names::kInstallAllowList,
595 false)));
596 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
597 new extensions::ExtensionListPolicyHandler(
598 key::kExtensionInstallBlacklist,
599 extensions::pref_names::kInstallDenyList,
600 true)));
601 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
602 new extensions::ExtensionInstallForcelistPolicyHandler()));
603 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
604 new extensions::ExtensionURLPatternListPolicyHandler(
605 key::kExtensionInstallSources,
606 extensions::pref_names::kAllowedInstallSites)));
607 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
608 new StringMappingListPolicyHandler(
609 key::kExtensionAllowedTypes,
610 extensions::pref_names::kAllowedTypes,
611 base::Bind(GetExtensionAllowedTypesMap))));
612 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
613 new extensions::ExtensionSettingsPolicyHandler(chrome_schema)));
614 #endif
616 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
617 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
618 new DiskCacheDirPolicyHandler()));
620 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
621 new extensions::NativeMessagingHostListPolicyHandler(
622 key::kNativeMessagingWhitelist,
623 extensions::pref_names::kNativeMessagingWhitelist,
624 false)));
625 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
626 new extensions::NativeMessagingHostListPolicyHandler(
627 key::kNativeMessagingBlacklist,
628 extensions::pref_names::kNativeMessagingBlacklist,
629 true)));
630 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
632 #if !defined(OS_ANDROID) && !defined(OS_IOS)
633 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
634 new DownloadDirPolicyHandler));
636 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
637 new SimpleSchemaValidatingPolicyHandler(
638 key::kRegisteredProtocolHandlers,
639 prefs::kPolicyRegisteredProtocolHandlers,
640 chrome_schema,
641 SCHEMA_STRICT,
642 SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED,
643 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED)));
644 #endif
646 #if defined(OS_CHROMEOS)
647 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
648 new extensions::ExtensionListPolicyHandler(
649 key::kAttestationExtensionWhitelist,
650 prefs::kAttestationExtensionWhitelist,
651 false)));
652 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
653 NetworkConfigurationPolicyHandler::CreateForDevicePolicy()));
654 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
655 NetworkConfigurationPolicyHandler::CreateForUserPolicy()));
656 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
657 new PinnedLauncherAppsPolicyHandler()));
658 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
659 new ScreenMagnifierPolicyHandler()));
660 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
661 new LoginScreenPowerManagementPolicyHandler(chrome_schema)));
663 ScopedVector<ConfigurationPolicyHandler>
664 power_management_idle_legacy_policies;
665 power_management_idle_legacy_policies.push_back(
666 new IntRangePolicyHandler(key::kScreenDimDelayAC,
667 prefs::kPowerAcScreenDimDelayMs,
669 INT_MAX,
670 true));
671 power_management_idle_legacy_policies.push_back(
672 new IntRangePolicyHandler(key::kScreenOffDelayAC,
673 prefs::kPowerAcScreenOffDelayMs,
675 INT_MAX,
676 true));
677 power_management_idle_legacy_policies.push_back(
678 new IntRangePolicyHandler(key::kIdleWarningDelayAC,
679 prefs::kPowerAcIdleWarningDelayMs,
681 INT_MAX,
682 true));
683 power_management_idle_legacy_policies.push_back(new IntRangePolicyHandler(
684 key::kIdleDelayAC, prefs::kPowerAcIdleDelayMs, 0, INT_MAX, true));
685 power_management_idle_legacy_policies.push_back(
686 new IntRangePolicyHandler(key::kScreenDimDelayBattery,
687 prefs::kPowerBatteryScreenDimDelayMs,
689 INT_MAX,
690 true));
691 power_management_idle_legacy_policies.push_back(
692 new IntRangePolicyHandler(key::kScreenOffDelayBattery,
693 prefs::kPowerBatteryScreenOffDelayMs,
695 INT_MAX,
696 true));
697 power_management_idle_legacy_policies.push_back(
698 new IntRangePolicyHandler(key::kIdleWarningDelayBattery,
699 prefs::kPowerBatteryIdleWarningDelayMs,
701 INT_MAX,
702 true));
703 power_management_idle_legacy_policies.push_back(
704 new IntRangePolicyHandler(key::kIdleDelayBattery,
705 prefs::kPowerBatteryIdleDelayMs,
707 INT_MAX,
708 true));
709 power_management_idle_legacy_policies.push_back(new IntRangePolicyHandler(
710 key::kIdleActionAC,
711 prefs::kPowerAcIdleAction,
712 chromeos::PowerPolicyController::ACTION_SUSPEND,
713 chromeos::PowerPolicyController::ACTION_DO_NOTHING,
714 false));
715 power_management_idle_legacy_policies.push_back(new IntRangePolicyHandler(
716 key::kIdleActionBattery,
717 prefs::kPowerBatteryIdleAction,
718 chromeos::PowerPolicyController::ACTION_SUSPEND,
719 chromeos::PowerPolicyController::ACTION_DO_NOTHING,
720 false));
721 power_management_idle_legacy_policies.push_back(
722 new DeprecatedIdleActionHandler());
724 ScopedVector<ConfigurationPolicyHandler> screen_lock_legacy_policies;
725 screen_lock_legacy_policies.push_back(
726 new IntRangePolicyHandler(key::kScreenLockDelayAC,
727 prefs::kPowerAcScreenLockDelayMs,
729 INT_MAX,
730 true));
731 screen_lock_legacy_policies.push_back(
732 new IntRangePolicyHandler(key::kScreenLockDelayBattery,
733 prefs::kPowerBatteryScreenLockDelayMs,
735 INT_MAX,
736 true));
738 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
739 new IntRangePolicyHandler(key::kSAMLOfflineSigninTimeLimit,
740 prefs::kSAMLOfflineSigninTimeLimit,
742 INT_MAX,
743 true)));
744 handlers->AddHandler(
745 make_scoped_ptr<ConfigurationPolicyHandler>(new IntRangePolicyHandler(
746 key::kLidCloseAction,
747 prefs::kPowerLidClosedAction,
748 chromeos::PowerPolicyController::ACTION_SUSPEND,
749 chromeos::PowerPolicyController::ACTION_DO_NOTHING,
750 false)));
751 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
752 new IntPercentageToDoublePolicyHandler(
753 key::kPresentationScreenDimDelayScale,
754 prefs::kPowerPresentationScreenDimDelayFactor,
755 100,
756 INT_MAX,
757 true)));
758 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
759 new IntPercentageToDoublePolicyHandler(
760 key::kUserActivityScreenDimDelayScale,
761 prefs::kPowerUserActivityScreenDimDelayFactor,
762 100,
763 INT_MAX,
764 true)));
765 handlers->AddHandler(
766 make_scoped_ptr<ConfigurationPolicyHandler>(new IntRangePolicyHandler(
767 key::kUptimeLimit, prefs::kUptimeLimit, 3600, INT_MAX, true)));
768 handlers->AddHandler(
769 make_scoped_ptr<ConfigurationPolicyHandler>(new IntRangePolicyHandler(
770 key::kDeviceLoginScreenDefaultScreenMagnifierType,
771 NULL,
773 ui::MAGNIFIER_FULL,
774 false)));
775 // TODO(binjin): Remove LegacyPoliciesDeprecatingPolicyHandler for these two
776 // policies once deprecation of legacy power management policies is done.
777 // http://crbug.com/346229
778 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
779 new LegacyPoliciesDeprecatingPolicyHandler(
780 power_management_idle_legacy_policies.Pass(),
781 make_scoped_ptr<SchemaValidatingPolicyHandler>(
782 new PowerManagementIdleSettingsPolicyHandler(chrome_schema)))));
783 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
784 new LegacyPoliciesDeprecatingPolicyHandler(
785 screen_lock_legacy_policies.Pass(),
786 make_scoped_ptr<SchemaValidatingPolicyHandler>(
787 new ScreenLockDelayPolicyHandler(chrome_schema)))));
788 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
789 new ExternalDataPolicyHandler(key::kUserAvatarImage)));
790 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
791 new ExternalDataPolicyHandler(key::kWallpaperImage)));
792 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
793 new SimpleSchemaValidatingPolicyHandler(
794 key::kSessionLocales,
795 NULL,
796 chrome_schema,
797 SCHEMA_STRICT,
798 SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED,
799 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED)));
800 #endif // defined(OS_CHROMEOS)
802 return handlers.Pass();
805 } // namespace policy