Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_policy_decoder_chromeos.cc
blob555d18bd44bf3c2f970828bc7cd1efce4c1f2d31
1 // Copyright (c) 2012 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/chromeos/policy/device_policy_decoder_chromeos.h"
7 #include <limits>
8 #include <string>
10 #include "base/callback.h"
11 #include "base/json/json_reader.h"
12 #include "base/logging.h"
13 #include "base/values.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chromeos/policy/device_local_account.h"
16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/update_engine_client.h"
19 #include "chromeos/settings/cros_settings_names.h"
20 #include "components/policy/core/browser/browser_policy_connector.h"
21 #include "components/policy/core/common/external_data_fetcher.h"
22 #include "components/policy/core/common/policy_map.h"
23 #include "components/policy/core/common/schema.h"
24 #include "policy/policy_constants.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h"
27 using google::protobuf::RepeatedField;
28 using google::protobuf::RepeatedPtrField;
30 namespace em = enterprise_management;
32 namespace policy {
34 namespace {
36 // Decodes a protobuf integer to an IntegerValue. Returns NULL in case the input
37 // value is out of bounds.
38 scoped_ptr<base::Value> DecodeIntegerValue(google::protobuf::int64 value) {
39 if (value < std::numeric_limits<int>::min() ||
40 value > std::numeric_limits<int>::max()) {
41 LOG(WARNING) << "Integer value " << value
42 << " out of numeric limits, ignoring.";
43 return scoped_ptr<base::Value>();
46 return scoped_ptr<base::Value>(
47 new base::FundamentalValue(static_cast<int>(value)));
50 // Decodes a JSON string to a base::Value, and drops unknown properties
51 // according to a policy schema. |policy_name| is the name of a policy schema
52 // defined in policy_templates.json. Returns NULL in case the input is not a
53 // valid JSON string.
54 scoped_ptr<base::Value> DecodeJsonStringAndDropUnknownBySchema(
55 const std::string& json_string,
56 const std::string& policy_name) {
57 std::string error;
58 scoped_ptr<base::Value> root = base::JSONReader::ReadAndReturnError(
59 json_string, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error);
61 if (!root) {
62 LOG(WARNING) << "Invalid JSON string: " << error << ", ignoring.";
63 return scoped_ptr<base::Value>();
66 const Schema& schema = g_browser_process
67 ->browser_policy_connector()
68 ->GetChromeSchema()
69 .GetKnownProperty(policy_name);
71 if (schema.valid()) {
72 std::string error_path;
73 bool changed = false;
75 if (!schema.Normalize(root.get(), SCHEMA_ALLOW_UNKNOWN, &error_path, &error,
76 &changed)) {
77 LOG(WARNING) << "Invalid policy value for " << policy_name << ": "
78 << error << " at " << error_path << ".";
79 return scoped_ptr<base::Value>();
82 if (changed) {
83 LOG(WARNING) << "Some properties in " << policy_name
84 << " were dropped: " << error << " at " << error_path << ".";
86 } else {
87 LOG(WARNING) << "Unknown or invalid policy schema for " << policy_name
88 << ".";
89 return scoped_ptr<base::Value>();
92 return root;
95 base::Value* DecodeConnectionType(int value) {
96 static const char* const kConnectionTypes[] = {
97 shill::kTypeEthernet,
98 shill::kTypeWifi,
99 shill::kTypeWimax,
100 shill::kTypeBluetooth,
101 shill::kTypeCellular,
104 if (value < 0 || value >= static_cast<int>(arraysize(kConnectionTypes)))
105 return NULL;
107 return new base::StringValue(kConnectionTypes[value]);
110 void DecodeLoginPolicies(const em::ChromeDeviceSettingsProto& policy,
111 PolicyMap* policies) {
112 if (policy.has_guest_mode_enabled()) {
113 const em::GuestModeEnabledProto& container(policy.guest_mode_enabled());
114 if (container.has_guest_mode_enabled()) {
115 policies->Set(key::kDeviceGuestModeEnabled,
116 POLICY_LEVEL_MANDATORY,
117 POLICY_SCOPE_MACHINE,
118 new base::FundamentalValue(
119 container.guest_mode_enabled()),
120 NULL);
124 if (policy.has_reboot_on_shutdown()) {
125 const em::RebootOnShutdownProto& container(policy.reboot_on_shutdown());
126 if (container.has_reboot_on_shutdown()) {
127 policies->Set(key::kDeviceRebootOnShutdown, POLICY_LEVEL_MANDATORY,
128 POLICY_SCOPE_MACHINE,
129 new base::FundamentalValue(container.reboot_on_shutdown()),
130 NULL);
134 if (policy.has_show_user_names()) {
135 const em::ShowUserNamesOnSigninProto& container(policy.show_user_names());
136 if (container.has_show_user_names()) {
137 policies->Set(key::kDeviceShowUserNamesOnSignin,
138 POLICY_LEVEL_MANDATORY,
139 POLICY_SCOPE_MACHINE,
140 new base::FundamentalValue(
141 container.show_user_names()),
142 NULL);
146 if (policy.has_allow_new_users()) {
147 const em::AllowNewUsersProto& container(policy.allow_new_users());
148 if (container.has_allow_new_users()) {
149 policies->Set(key::kDeviceAllowNewUsers,
150 POLICY_LEVEL_MANDATORY,
151 POLICY_SCOPE_MACHINE,
152 new base::FundamentalValue(
153 container.allow_new_users()),
154 NULL);
158 if (policy.has_user_whitelist()) {
159 const em::UserWhitelistProto& container(policy.user_whitelist());
160 base::ListValue* whitelist = new base::ListValue();
161 RepeatedPtrField<std::string>::const_iterator entry;
162 for (entry = container.user_whitelist().begin();
163 entry != container.user_whitelist().end();
164 ++entry) {
165 whitelist->Append(new base::StringValue(*entry));
167 policies->Set(key::kDeviceUserWhitelist,
168 POLICY_LEVEL_MANDATORY,
169 POLICY_SCOPE_MACHINE,
170 whitelist,
171 NULL);
174 if (policy.has_ephemeral_users_enabled()) {
175 const em::EphemeralUsersEnabledProto& container(
176 policy.ephemeral_users_enabled());
177 if (container.has_ephemeral_users_enabled()) {
178 policies->Set(key::kDeviceEphemeralUsersEnabled,
179 POLICY_LEVEL_MANDATORY,
180 POLICY_SCOPE_MACHINE,
181 new base::FundamentalValue(
182 container.ephemeral_users_enabled()),
183 NULL);
187 if (policy.has_device_local_accounts()) {
188 const em::DeviceLocalAccountsProto& container(
189 policy.device_local_accounts());
190 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts =
191 container.account();
192 scoped_ptr<base::ListValue> account_list(new base::ListValue());
193 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry;
194 for (entry = accounts.begin(); entry != accounts.end(); ++entry) {
195 scoped_ptr<base::DictionaryValue> entry_dict(
196 new base::DictionaryValue());
197 if (entry->has_type()) {
198 if (entry->has_account_id()) {
199 entry_dict->SetStringWithoutPathExpansion(
200 chromeos::kAccountsPrefDeviceLocalAccountsKeyId,
201 entry->account_id());
203 entry_dict->SetIntegerWithoutPathExpansion(
204 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, entry->type());
205 if (entry->kiosk_app().has_app_id()) {
206 entry_dict->SetStringWithoutPathExpansion(
207 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
208 entry->kiosk_app().app_id());
210 if (entry->kiosk_app().has_update_url()) {
211 entry_dict->SetStringWithoutPathExpansion(
212 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL,
213 entry->kiosk_app().update_url());
215 } else if (entry->has_deprecated_public_session_id()) {
216 // Deprecated public session specification.
217 entry_dict->SetStringWithoutPathExpansion(
218 chromeos::kAccountsPrefDeviceLocalAccountsKeyId,
219 entry->deprecated_public_session_id());
220 entry_dict->SetIntegerWithoutPathExpansion(
221 chromeos::kAccountsPrefDeviceLocalAccountsKeyType,
222 DeviceLocalAccount::TYPE_PUBLIC_SESSION);
224 account_list->Append(entry_dict.release());
226 policies->Set(key::kDeviceLocalAccounts,
227 POLICY_LEVEL_MANDATORY,
228 POLICY_SCOPE_MACHINE,
229 account_list.release(),
230 NULL);
231 if (container.has_auto_login_id()) {
232 policies->Set(key::kDeviceLocalAccountAutoLoginId,
233 POLICY_LEVEL_MANDATORY,
234 POLICY_SCOPE_MACHINE,
235 new base::StringValue(container.auto_login_id()),
236 NULL);
238 if (container.has_auto_login_delay()) {
239 policies->Set(key::kDeviceLocalAccountAutoLoginDelay,
240 POLICY_LEVEL_MANDATORY,
241 POLICY_SCOPE_MACHINE,
242 DecodeIntegerValue(container.auto_login_delay()).release(),
243 NULL);
245 if (container.has_enable_auto_login_bailout()) {
246 policies->Set(key::kDeviceLocalAccountAutoLoginBailoutEnabled,
247 POLICY_LEVEL_MANDATORY,
248 POLICY_SCOPE_MACHINE,
249 new base::FundamentalValue(
250 container.enable_auto_login_bailout()),
251 NULL);
253 if (container.has_prompt_for_network_when_offline()) {
254 policies->Set(key::kDeviceLocalAccountPromptForNetworkWhenOffline,
255 POLICY_LEVEL_MANDATORY,
256 POLICY_SCOPE_MACHINE,
257 new base::FundamentalValue(
258 container.prompt_for_network_when_offline()),
259 NULL);
263 if (policy.has_supervised_users_settings()) {
264 const em::SupervisedUsersSettingsProto& container =
265 policy.supervised_users_settings();
266 if (container.has_supervised_users_enabled()) {
267 base::Value* value = new base::FundamentalValue(
268 container.supervised_users_enabled());
269 policies->Set(key::kSupervisedUsersEnabled,
270 POLICY_LEVEL_MANDATORY,
271 POLICY_SCOPE_MACHINE,
272 value,
273 NULL);
277 if (policy.has_saml_settings()) {
278 const em::SAMLSettingsProto& container(policy.saml_settings());
279 if (container.has_transfer_saml_cookies()) {
280 policies->Set(key::kDeviceTransferSAMLCookies,
281 POLICY_LEVEL_MANDATORY,
282 POLICY_SCOPE_MACHINE,
283 new base::FundamentalValue(
284 container.transfer_saml_cookies()),
285 NULL);
290 void DecodeNetworkPolicies(const em::ChromeDeviceSettingsProto& policy,
291 PolicyMap* policies) {
292 if (policy.has_data_roaming_enabled()) {
293 const em::DataRoamingEnabledProto& container(policy.data_roaming_enabled());
294 if (container.has_data_roaming_enabled()) {
295 policies->Set(key::kDeviceDataRoamingEnabled,
296 POLICY_LEVEL_MANDATORY,
297 POLICY_SCOPE_MACHINE,
298 new base::FundamentalValue(
299 container.data_roaming_enabled()),
300 NULL);
304 if (policy.has_open_network_configuration() &&
305 policy.open_network_configuration().has_open_network_configuration()) {
306 std::string config(
307 policy.open_network_configuration().open_network_configuration());
308 policies->Set(key::kDeviceOpenNetworkConfiguration,
309 POLICY_LEVEL_MANDATORY,
310 POLICY_SCOPE_MACHINE,
311 new base::StringValue(config),
312 NULL);
316 void DecodeReportingPolicies(const em::ChromeDeviceSettingsProto& policy,
317 PolicyMap* policies) {
318 if (policy.has_device_reporting()) {
319 const em::DeviceReportingProto& container(policy.device_reporting());
320 if (container.has_report_version_info()) {
321 policies->Set(key::kReportDeviceVersionInfo,
322 POLICY_LEVEL_MANDATORY,
323 POLICY_SCOPE_MACHINE,
324 new base::FundamentalValue(
325 container.report_version_info()),
326 NULL);
328 if (container.has_report_activity_times()) {
329 policies->Set(key::kReportDeviceActivityTimes,
330 POLICY_LEVEL_MANDATORY,
331 POLICY_SCOPE_MACHINE,
332 new base::FundamentalValue(
333 container.report_activity_times()),
334 NULL);
336 if (container.has_report_boot_mode()) {
337 policies->Set(key::kReportDeviceBootMode,
338 POLICY_LEVEL_MANDATORY,
339 POLICY_SCOPE_MACHINE,
340 new base::FundamentalValue(
341 container.report_boot_mode()),
342 NULL);
344 if (container.has_report_location()) {
345 policies->Set(key::kReportDeviceLocation,
346 POLICY_LEVEL_MANDATORY,
347 POLICY_SCOPE_MACHINE,
348 new base::FundamentalValue(
349 container.report_location()),
350 NULL);
352 if (container.has_report_network_interfaces()) {
353 policies->Set(key::kReportDeviceNetworkInterfaces,
354 POLICY_LEVEL_MANDATORY,
355 POLICY_SCOPE_MACHINE,
356 new base::FundamentalValue(
357 container.report_network_interfaces()),
358 NULL);
360 if (container.has_report_users()) {
361 policies->Set(key::kReportDeviceUsers,
362 POLICY_LEVEL_MANDATORY,
363 POLICY_SCOPE_MACHINE,
364 new base::FundamentalValue(container.report_users()),
365 NULL);
367 if (container.has_report_hardware_status()) {
368 policies->Set(key::kReportDeviceHardwareStatus,
369 POLICY_LEVEL_MANDATORY,
370 POLICY_SCOPE_MACHINE,
371 new base::FundamentalValue(
372 container.report_hardware_status()),
373 NULL);
375 if (container.has_report_session_status()) {
376 policies->Set(key::kReportDeviceSessionStatus,
377 POLICY_LEVEL_MANDATORY,
378 POLICY_SCOPE_MACHINE,
379 new base::FundamentalValue(
380 container.report_session_status()),
381 NULL);
383 if (container.has_device_status_frequency()) {
384 policies->Set(key::kReportUploadFrequency,
385 POLICY_LEVEL_MANDATORY,
386 POLICY_SCOPE_MACHINE,
387 DecodeIntegerValue(
388 container.device_status_frequency()).release(),
389 NULL);
393 if (policy.has_device_heartbeat_settings()) {
394 const em::DeviceHeartbeatSettingsProto& container(
395 policy.device_heartbeat_settings());
396 if (container.has_heartbeat_enabled()) {
397 policies->Set(key::kHeartbeatEnabled,
398 POLICY_LEVEL_MANDATORY,
399 POLICY_SCOPE_MACHINE,
400 new base::FundamentalValue(
401 container.heartbeat_enabled()),
402 NULL);
404 if (container.has_heartbeat_frequency()) {
405 policies->Set(key::kHeartbeatFrequency,
406 POLICY_LEVEL_MANDATORY,
407 POLICY_SCOPE_MACHINE,
408 DecodeIntegerValue(
409 container.heartbeat_frequency()).release(),
410 NULL);
414 if (policy.has_device_log_upload_settings()) {
415 const em::DeviceLogUploadSettingsProto& container(
416 policy.device_log_upload_settings());
417 if (container.has_log_upload_enabled()) {
418 policies->Set(
419 key::kLogUploadEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
420 new base::FundamentalValue(container.log_upload_enabled()), NULL);
425 void DecodeAutoUpdatePolicies(const em::ChromeDeviceSettingsProto& policy,
426 PolicyMap* policies) {
427 if (policy.has_release_channel()) {
428 const em::ReleaseChannelProto& container(policy.release_channel());
429 if (container.has_release_channel()) {
430 std::string channel(container.release_channel());
431 policies->Set(key::kChromeOsReleaseChannel,
432 POLICY_LEVEL_MANDATORY,
433 POLICY_SCOPE_MACHINE,
434 new base::StringValue(channel),
435 NULL);
436 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't
437 // have to pass the channel in here, only ping the update engine to tell
438 // it to fetch the channel from the policy.
439 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->
440 SetChannel(channel, false);
442 if (container.has_release_channel_delegated()) {
443 policies->Set(key::kChromeOsReleaseChannelDelegated,
444 POLICY_LEVEL_MANDATORY,
445 POLICY_SCOPE_MACHINE,
446 new base::FundamentalValue(
447 container.release_channel_delegated()),
448 NULL);
452 if (policy.has_auto_update_settings()) {
453 const em::AutoUpdateSettingsProto& container(policy.auto_update_settings());
454 if (container.has_update_disabled()) {
455 policies->Set(key::kDeviceAutoUpdateDisabled,
456 POLICY_LEVEL_MANDATORY,
457 POLICY_SCOPE_MACHINE,
458 new base::FundamentalValue(
459 container.update_disabled()),
460 NULL);
463 if (container.has_target_version_prefix()) {
464 policies->Set(key::kDeviceTargetVersionPrefix,
465 POLICY_LEVEL_MANDATORY,
466 POLICY_SCOPE_MACHINE,
467 new base::StringValue(
468 container.target_version_prefix()),
469 NULL);
472 // target_version_display_name is not actually a policy, but a display
473 // string for target_version_prefix, so we ignore it.
475 if (container.has_scatter_factor_in_seconds()) {
476 policies->Set(key::kDeviceUpdateScatterFactor,
477 POLICY_LEVEL_MANDATORY,
478 POLICY_SCOPE_MACHINE,
479 new base::FundamentalValue(static_cast<int>(
480 container.scatter_factor_in_seconds())),
481 NULL);
484 if (container.allowed_connection_types_size()) {
485 base::ListValue* allowed_connection_types = new base::ListValue();
486 RepeatedField<int>::const_iterator entry;
487 for (entry = container.allowed_connection_types().begin();
488 entry != container.allowed_connection_types().end();
489 ++entry) {
490 base::Value* value = DecodeConnectionType(*entry);
491 if (value)
492 allowed_connection_types->Append(value);
494 policies->Set(key::kDeviceUpdateAllowedConnectionTypes,
495 POLICY_LEVEL_MANDATORY,
496 POLICY_SCOPE_MACHINE,
497 allowed_connection_types,
498 NULL);
501 if (container.has_http_downloads_enabled()) {
502 policies->Set(
503 key::kDeviceUpdateHttpDownloadsEnabled,
504 POLICY_LEVEL_MANDATORY,
505 POLICY_SCOPE_MACHINE,
506 new base::FundamentalValue(container.http_downloads_enabled()),
507 NULL);
510 if (container.has_reboot_after_update()) {
511 policies->Set(key::kRebootAfterUpdate,
512 POLICY_LEVEL_MANDATORY,
513 POLICY_SCOPE_MACHINE,
514 new base::FundamentalValue(
515 container.reboot_after_update()),
516 NULL);
519 if (container.has_p2p_enabled()) {
520 policies->Set(key::kDeviceAutoUpdateP2PEnabled,
521 POLICY_LEVEL_MANDATORY,
522 POLICY_SCOPE_MACHINE,
523 new base::FundamentalValue(container.p2p_enabled()),
524 NULL);
529 void DecodeAccessibilityPolicies(const em::ChromeDeviceSettingsProto& policy,
530 PolicyMap* policies) {
531 if (policy.has_accessibility_settings()) {
532 const em::AccessibilitySettingsProto&
533 container(policy.accessibility_settings());
535 if (container.has_login_screen_default_large_cursor_enabled()) {
536 policies->Set(
537 key::kDeviceLoginScreenDefaultLargeCursorEnabled,
538 POLICY_LEVEL_MANDATORY,
539 POLICY_SCOPE_MACHINE,
540 new base::FundamentalValue(
541 container.login_screen_default_large_cursor_enabled()),
542 NULL);
545 if (container.has_login_screen_default_spoken_feedback_enabled()) {
546 policies->Set(
547 key::kDeviceLoginScreenDefaultSpokenFeedbackEnabled,
548 POLICY_LEVEL_MANDATORY,
549 POLICY_SCOPE_MACHINE,
550 new base::FundamentalValue(
551 container.login_screen_default_spoken_feedback_enabled()),
552 NULL);
555 if (container.has_login_screen_default_high_contrast_enabled()) {
556 policies->Set(
557 key::kDeviceLoginScreenDefaultHighContrastEnabled,
558 POLICY_LEVEL_MANDATORY,
559 POLICY_SCOPE_MACHINE,
560 new base::FundamentalValue(
561 container.login_screen_default_high_contrast_enabled()),
562 NULL);
565 if (container.has_login_screen_default_screen_magnifier_type()) {
566 policies->Set(
567 key::kDeviceLoginScreenDefaultScreenMagnifierType,
568 POLICY_LEVEL_MANDATORY,
569 POLICY_SCOPE_MACHINE,
570 DecodeIntegerValue(
571 container.login_screen_default_screen_magnifier_type()).release(),
572 NULL);
575 if (container.has_login_screen_default_virtual_keyboard_enabled()) {
576 policies->Set(
577 key::kDeviceLoginScreenDefaultVirtualKeyboardEnabled,
578 POLICY_LEVEL_MANDATORY,
579 POLICY_SCOPE_MACHINE,
580 new base::FundamentalValue(
581 container.login_screen_default_virtual_keyboard_enabled()),
582 NULL);
587 void DecodeGenericPolicies(const em::ChromeDeviceSettingsProto& policy,
588 PolicyMap* policies) {
589 if (policy.has_device_policy_refresh_rate()) {
590 const em::DevicePolicyRefreshRateProto& container(
591 policy.device_policy_refresh_rate());
592 if (container.has_device_policy_refresh_rate()) {
593 policies->Set(
594 key::kDevicePolicyRefreshRate,
595 POLICY_LEVEL_MANDATORY,
596 POLICY_SCOPE_MACHINE,
597 DecodeIntegerValue(container.device_policy_refresh_rate()).release(),
598 NULL);
602 if (policy.has_metrics_enabled()) {
603 const em::MetricsEnabledProto& container(policy.metrics_enabled());
604 if (container.has_metrics_enabled()) {
605 policies->Set(key::kDeviceMetricsReportingEnabled,
606 POLICY_LEVEL_MANDATORY,
607 POLICY_SCOPE_MACHINE,
608 new base::FundamentalValue(
609 container.metrics_enabled()),
610 NULL);
614 if (policy.has_system_timezone()) {
615 if (policy.system_timezone().has_timezone()) {
616 policies->Set(key::kSystemTimezone,
617 POLICY_LEVEL_MANDATORY,
618 POLICY_SCOPE_MACHINE,
619 new base::StringValue(
620 policy.system_timezone().timezone()),
621 NULL);
625 if (policy.has_use_24hour_clock()) {
626 if (policy.use_24hour_clock().has_use_24hour_clock()) {
627 policies->Set(key::kSystemUse24HourClock,
628 POLICY_LEVEL_MANDATORY,
629 POLICY_SCOPE_MACHINE,
630 new base::FundamentalValue(
631 policy.use_24hour_clock().use_24hour_clock()),
632 NULL);
636 if (policy.has_allow_redeem_offers()) {
637 const em::AllowRedeemChromeOsRegistrationOffersProto& container(
638 policy.allow_redeem_offers());
639 if (container.has_allow_redeem_offers()) {
640 policies->Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers,
641 POLICY_LEVEL_MANDATORY,
642 POLICY_SCOPE_MACHINE,
643 new base::FundamentalValue(
644 container.allow_redeem_offers()),
645 NULL);
649 if (policy.has_uptime_limit()) {
650 const em::UptimeLimitProto& container(policy.uptime_limit());
651 if (container.has_uptime_limit()) {
652 policies->Set(key::kUptimeLimit,
653 POLICY_LEVEL_MANDATORY,
654 POLICY_SCOPE_MACHINE,
655 DecodeIntegerValue(container.uptime_limit()).release(),
656 NULL);
660 if (policy.has_start_up_flags()) {
661 const em::StartUpFlagsProto& container(policy.start_up_flags());
662 base::ListValue* flags = new base::ListValue();
663 RepeatedPtrField<std::string>::const_iterator entry;
664 for (entry = container.flags().begin();
665 entry != container.flags().end();
666 ++entry) {
667 flags->Append(new base::StringValue(*entry));
669 policies->Set(key::kDeviceStartUpFlags,
670 POLICY_LEVEL_MANDATORY,
671 POLICY_SCOPE_MACHINE,
672 flags,
673 NULL);
676 if (policy.has_variations_parameter()) {
677 if (policy.variations_parameter().has_parameter()) {
678 policies->Set(key::kDeviceVariationsRestrictParameter,
679 POLICY_LEVEL_MANDATORY,
680 POLICY_SCOPE_MACHINE,
681 new base::StringValue(
682 policy.variations_parameter().parameter()),
683 NULL);
687 if (policy.has_attestation_settings()) {
688 if (policy.attestation_settings().has_attestation_enabled()) {
689 policies->Set(key::kAttestationEnabledForDevice,
690 POLICY_LEVEL_MANDATORY,
691 POLICY_SCOPE_MACHINE,
692 new base::FundamentalValue(
693 policy.attestation_settings().attestation_enabled()),
694 NULL);
696 if (policy.attestation_settings().has_content_protection_enabled()) {
697 policies->Set(
698 key::kAttestationForContentProtectionEnabled,
699 POLICY_LEVEL_MANDATORY,
700 POLICY_SCOPE_MACHINE,
701 new base::FundamentalValue(
702 policy.attestation_settings().content_protection_enabled()),
703 NULL);
707 if (policy.has_login_screen_power_management()) {
708 const em::LoginScreenPowerManagementProto& container(
709 policy.login_screen_power_management());
710 if (container.has_login_screen_power_management()) {
711 scoped_ptr<base::Value> decoded_json;
712 decoded_json = DecodeJsonStringAndDropUnknownBySchema(
713 container.login_screen_power_management(),
714 key::kDeviceLoginScreenPowerManagement);
715 if (decoded_json) {
716 policies->Set(key::kDeviceLoginScreenPowerManagement,
717 POLICY_LEVEL_MANDATORY,
718 POLICY_SCOPE_MACHINE,
719 decoded_json.release(),
720 NULL);
725 if (policy.has_system_settings()) {
726 const em::SystemSettingsProto& container(policy.system_settings());
727 if (container.has_block_devmode()) {
728 policies->Set(
729 key::kDeviceBlockDevmode,
730 POLICY_LEVEL_MANDATORY,
731 POLICY_SCOPE_MACHINE,
732 new base::FundamentalValue(container.block_devmode()),
733 NULL);
737 if (policy.has_extension_cache_size()) {
738 const em::ExtensionCacheSizeProto& container(policy.extension_cache_size());
739 if (container.has_extension_cache_size()) {
740 policies->Set(
741 key::kExtensionCacheSize, POLICY_LEVEL_MANDATORY,
742 POLICY_SCOPE_MACHINE,
743 DecodeIntegerValue(container.extension_cache_size()).release(),
744 nullptr);
748 if (policy.has_login_screen_domain_auto_complete()) {
749 const em::LoginScreenDomainAutoCompleteProto& container(
750 policy.login_screen_domain_auto_complete());
751 policies->Set(
752 key::kDeviceLoginScreenDomainAutoComplete, POLICY_LEVEL_MANDATORY,
753 POLICY_SCOPE_MACHINE,
754 new base::StringValue(container.login_screen_domain_auto_complete()),
755 nullptr);
759 } // namespace
761 void DecodeDevicePolicy(const em::ChromeDeviceSettingsProto& policy,
762 PolicyMap* policies) {
763 // Decode the various groups of policies.
764 DecodeLoginPolicies(policy, policies);
765 DecodeNetworkPolicies(policy, policies);
766 DecodeReportingPolicies(policy, policies);
767 DecodeAutoUpdatePolicies(policy, policies);
768 DecodeAccessibilityPolicies(policy, policies);
769 DecodeGenericPolicies(policy, policies);
772 } // namespace policy