Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/settings/device_settings_provider.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 device_settings_service_->RemoveObserver(this); | 452 device_settings_service_->RemoveObserver(this); |
| 453 } | 453 } |
| 454 | 454 |
| 455 // static | 455 // static |
| 456 bool DeviceSettingsProvider::IsDeviceSetting(const std::string& name) { | 456 bool DeviceSettingsProvider::IsDeviceSetting(const std::string& name) { |
| 457 const char** end = kKnownSettings + arraysize(kKnownSettings); | 457 const char** end = kKnownSettings + arraysize(kKnownSettings); |
| 458 return std::find(kKnownSettings, end, name) != end; | 458 return std::find(kKnownSettings, end, name) != end; |
| 459 } | 459 } |
| 460 | 460 |
| 461 void DeviceSettingsProvider::DoSet(const std::string& path, | 461 void DeviceSettingsProvider::DoSet(const std::string& path, |
| 462 const base::Value& in_value) { | 462 const base::Value& in_value) { |
|
Mattias Nissler (ping if slow)
2014/10/17 12:05:27
Can we perhaps re-wire this function to go through
ygorshenin1
2014/10/20 11:36:10
Good idea, but I have a question to you: what is t
Mattias Nissler (ping if slow)
2014/10/20 12:41:30
Hm, I'm trying to remember why we need that actual
ygorshenin1
2014/10/22 09:20:11
I'd prefer to make the change you're proposing in
| |
| 463 // Make sure that either the current user is the device owner or the | 463 // Make sure that either the current user is the device owner or the |
| 464 // device doesn't have an owner yet. | 464 // device doesn't have an owner yet. |
| 465 if (!(device_settings_service_->HasPrivateOwnerKey() || | 465 if (!(device_settings_service_->HasPrivateOwnerKey() || |
| 466 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)) { | 466 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)) { |
| 467 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; | 467 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; |
| 468 | 468 |
| 469 // Revert UI change. | 469 // Revert UI change. |
| 470 NotifyObservers(path); | 470 NotifyObservers(path); |
| 471 return; | 471 return; |
| 472 } | 472 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 // Re-sync device settings before proceeding. | 539 // Re-sync device settings before proceeding. |
| 540 device_settings_service_->Load(); | 540 device_settings_service_->Load(); |
| 541 return; | 541 return; |
| 542 } | 542 } |
| 543 | 543 |
| 544 std::string prop(pending_changes_.front().first); | 544 std::string prop(pending_changes_.front().first); |
| 545 scoped_ptr<base::Value> value(pending_changes_.front().second); | 545 scoped_ptr<base::Value> value(pending_changes_.front().second); |
| 546 pending_changes_.pop_front(); | 546 pending_changes_.pop_front(); |
| 547 | 547 |
| 548 trusted_status_ = TEMPORARILY_UNTRUSTED; | 548 trusted_status_ = TEMPORARILY_UNTRUSTED; |
| 549 if (prop == kAccountsPrefAllowNewUser) { | 549 DeviceSettingsService::UpdateDeviceSettings(prop, *value, device_settings_); |
|
Mattias Nissler (ping if slow)
2014/10/17 12:05:27
We should probably put a comment somewhere in this
ygorshenin1
2014/10/20 11:36:10
Done.
| |
| 550 em::AllowNewUsersProto* allow = | 550 |
| 551 device_settings_.mutable_allow_new_users(); | 551 bool metrics_value; |
| 552 bool allow_value; | 552 if (prop == kStatsReportingPref && value->GetAsBoolean(&metrics_value)) |
| 553 if (value->GetAsBoolean(&allow_value)) | |
| 554 allow->set_allow_new_users(allow_value); | |
| 555 else | |
| 556 NOTREACHED(); | |
| 557 } else if (prop == kAccountsPrefAllowGuest) { | |
| 558 em::GuestModeEnabledProto* guest = | |
| 559 device_settings_.mutable_guest_mode_enabled(); | |
| 560 bool guest_value; | |
| 561 if (value->GetAsBoolean(&guest_value)) | |
| 562 guest->set_guest_mode_enabled(guest_value); | |
| 563 else | |
| 564 NOTREACHED(); | |
| 565 } else if (prop == kAccountsPrefSupervisedUsersEnabled) { | |
| 566 em::SupervisedUsersSettingsProto* supervised = | |
| 567 device_settings_.mutable_supervised_users_settings(); | |
| 568 bool supervised_value; | |
| 569 if (value->GetAsBoolean(&supervised_value)) | |
| 570 supervised->set_supervised_users_enabled(supervised_value); | |
| 571 else | |
| 572 NOTREACHED(); | |
| 573 } else if (prop == kAccountsPrefShowUserNamesOnSignIn) { | |
| 574 em::ShowUserNamesOnSigninProto* show = | |
| 575 device_settings_.mutable_show_user_names(); | |
| 576 bool show_value; | |
| 577 if (value->GetAsBoolean(&show_value)) | |
| 578 show->set_show_user_names(show_value); | |
| 579 else | |
| 580 NOTREACHED(); | |
| 581 } else if (prop == kAccountsPrefDeviceLocalAccounts) { | |
| 582 em::DeviceLocalAccountsProto* device_local_accounts = | |
| 583 device_settings_.mutable_device_local_accounts(); | |
| 584 device_local_accounts->clear_account(); | |
| 585 const base::ListValue* accounts_list = NULL; | |
| 586 if (value->GetAsList(&accounts_list)) { | |
| 587 for (base::ListValue::const_iterator entry(accounts_list->begin()); | |
| 588 entry != accounts_list->end(); ++entry) { | |
| 589 const base::DictionaryValue* entry_dict = NULL; | |
| 590 if ((*entry)->GetAsDictionary(&entry_dict)) { | |
| 591 em::DeviceLocalAccountInfoProto* account = | |
| 592 device_local_accounts->add_account(); | |
| 593 std::string account_id; | |
| 594 if (entry_dict->GetStringWithoutPathExpansion( | |
| 595 kAccountsPrefDeviceLocalAccountsKeyId, &account_id)) { | |
| 596 account->set_account_id(account_id); | |
| 597 } | |
| 598 int type; | |
| 599 if (entry_dict->GetIntegerWithoutPathExpansion( | |
| 600 kAccountsPrefDeviceLocalAccountsKeyType, &type)) { | |
| 601 account->set_type( | |
| 602 static_cast<em::DeviceLocalAccountInfoProto::AccountType>( | |
| 603 type)); | |
| 604 } | |
| 605 std::string kiosk_app_id; | |
| 606 if (entry_dict->GetStringWithoutPathExpansion( | |
| 607 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | |
| 608 &kiosk_app_id)) { | |
| 609 account->mutable_kiosk_app()->set_app_id(kiosk_app_id); | |
| 610 } | |
| 611 } else { | |
| 612 NOTREACHED(); | |
| 613 } | |
| 614 } | |
| 615 } else { | |
| 616 NOTREACHED(); | |
| 617 } | |
| 618 } else if (prop == kAccountsPrefDeviceLocalAccountAutoLoginId) { | |
| 619 em::DeviceLocalAccountsProto* device_local_accounts = | |
| 620 device_settings_.mutable_device_local_accounts(); | |
| 621 std::string id; | |
| 622 if (value->GetAsString(&id)) | |
| 623 device_local_accounts->set_auto_login_id(id); | |
| 624 else | |
| 625 NOTREACHED(); | |
| 626 } else if (prop == kAccountsPrefDeviceLocalAccountAutoLoginDelay) { | |
| 627 em::DeviceLocalAccountsProto* device_local_accounts = | |
| 628 device_settings_.mutable_device_local_accounts(); | |
| 629 int delay; | |
| 630 if (value->GetAsInteger(&delay)) | |
| 631 device_local_accounts->set_auto_login_delay(delay); | |
| 632 else | |
| 633 NOTREACHED(); | |
| 634 } else if (prop == kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled) { | |
| 635 em::DeviceLocalAccountsProto* device_local_accounts = | |
| 636 device_settings_.mutable_device_local_accounts(); | |
| 637 bool enabled; | |
| 638 if (value->GetAsBoolean(&enabled)) | |
| 639 device_local_accounts->set_enable_auto_login_bailout(enabled); | |
| 640 else | |
| 641 NOTREACHED(); | |
| 642 } else if (prop == | |
| 643 kAccountsPrefDeviceLocalAccountPromptForNetworkWhenOffline) { | |
| 644 em::DeviceLocalAccountsProto* device_local_accounts = | |
| 645 device_settings_.mutable_device_local_accounts(); | |
| 646 bool should_prompt; | |
| 647 if (value->GetAsBoolean(&should_prompt)) | |
| 648 device_local_accounts->set_prompt_for_network_when_offline(should_prompt); | |
| 649 else | |
| 650 NOTREACHED(); | |
| 651 } else if (prop == kSignedDataRoamingEnabled) { | |
| 652 em::DataRoamingEnabledProto* roam = | |
| 653 device_settings_.mutable_data_roaming_enabled(); | |
| 654 bool roaming_value = false; | |
| 655 if (value->GetAsBoolean(&roaming_value)) | |
| 656 roam->set_data_roaming_enabled(roaming_value); | |
| 657 else | |
| 658 NOTREACHED(); | |
| 659 } else if (prop == kReleaseChannel) { | |
| 660 em::ReleaseChannelProto* release_channel = | |
| 661 device_settings_.mutable_release_channel(); | |
| 662 std::string channel_value; | |
| 663 if (value->GetAsString(&channel_value)) | |
| 664 release_channel->set_release_channel(channel_value); | |
| 665 else | |
| 666 NOTREACHED(); | |
| 667 } else if (prop == kStatsReportingPref) { | |
| 668 em::MetricsEnabledProto* metrics = | |
| 669 device_settings_.mutable_metrics_enabled(); | |
| 670 bool metrics_value = false; | |
| 671 if (value->GetAsBoolean(&metrics_value)) | |
| 672 metrics->set_metrics_enabled(metrics_value); | |
| 673 else | |
| 674 NOTREACHED(); | |
| 675 ApplyMetricsSetting(false, metrics_value); | 553 ApplyMetricsSetting(false, metrics_value); |
| 676 } else if (prop == kAccountsPrefUsers) { | |
| 677 em::UserWhitelistProto* whitelist_proto = | |
| 678 device_settings_.mutable_user_whitelist(); | |
| 679 whitelist_proto->clear_user_whitelist(); | |
| 680 const base::ListValue* users; | |
| 681 if (value->GetAsList(&users)) { | |
| 682 for (base::ListValue::const_iterator i = users->begin(); | |
| 683 i != users->end(); ++i) { | |
| 684 std::string email; | |
| 685 if ((*i)->GetAsString(&email)) | |
| 686 whitelist_proto->add_user_whitelist(email); | |
| 687 } | |
| 688 } | |
| 689 } else if (prop == kAccountsPrefEphemeralUsersEnabled) { | |
| 690 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = | |
| 691 device_settings_.mutable_ephemeral_users_enabled(); | |
| 692 bool ephemeral_users_enabled_value = false; | |
| 693 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) { | |
| 694 ephemeral_users_enabled->set_ephemeral_users_enabled( | |
| 695 ephemeral_users_enabled_value); | |
| 696 } else { | |
| 697 NOTREACHED(); | |
| 698 } | |
| 699 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) { | |
| 700 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers = | |
| 701 device_settings_.mutable_allow_redeem_offers(); | |
| 702 bool allow_redeem_offers_value; | |
| 703 if (value->GetAsBoolean(&allow_redeem_offers_value)) { | |
| 704 allow_redeem_offers->set_allow_redeem_offers( | |
| 705 allow_redeem_offers_value); | |
| 706 } else { | |
| 707 NOTREACHED(); | |
| 708 } | |
| 709 } else if (prop == kStartUpFlags) { | |
| 710 em::StartUpFlagsProto* flags_proto = | |
| 711 device_settings_.mutable_start_up_flags(); | |
| 712 flags_proto->Clear(); | |
| 713 const base::ListValue* flags; | |
| 714 if (value->GetAsList(&flags)) { | |
| 715 for (base::ListValue::const_iterator i = flags->begin(); | |
| 716 i != flags->end(); ++i) { | |
| 717 std::string flag; | |
| 718 if ((*i)->GetAsString(&flag)) | |
| 719 flags_proto->add_flags(flag); | |
| 720 } | |
| 721 } | |
| 722 } else if (prop == kSystemUse24HourClock) { | |
| 723 em::SystemUse24HourClockProto* use_24hour_clock_proto = | |
| 724 device_settings_.mutable_use_24hour_clock(); | |
| 725 use_24hour_clock_proto->Clear(); | |
| 726 bool use_24hour_clock_value; | |
| 727 if (value->GetAsBoolean(&use_24hour_clock_value)) { | |
| 728 use_24hour_clock_proto->set_use_24hour_clock(use_24hour_clock_value); | |
| 729 } else { | |
| 730 NOTREACHED(); | |
| 731 } | |
| 732 } else if (prop == kAttestationForContentProtectionEnabled) { | |
| 733 em::AttestationSettingsProto* attestation_settings = | |
| 734 device_settings_.mutable_attestation_settings(); | |
| 735 bool setting_enabled; | |
| 736 if (value->GetAsBoolean(&setting_enabled)) { | |
| 737 attestation_settings->set_content_protection_enabled(setting_enabled); | |
| 738 } else { | |
| 739 NOTREACHED(); | |
| 740 } | |
| 741 } else { | |
| 742 // The remaining settings don't support Set(), since they are not | |
| 743 // intended to be customizable by the user: | |
| 744 // kAccountsPrefTransferSAMLCookies | |
| 745 // kAppPack | |
| 746 // kDeviceAttestationEnabled | |
| 747 // kDeviceOwner | |
| 748 // kIdleLogoutTimeout | |
| 749 // kIdleLogoutWarningDuration | |
| 750 // kReleaseChannelDelegated | |
| 751 // kReportDeviceActivityTimes | |
| 752 // kReportDeviceBootMode | |
| 753 // kReportDeviceLocation | |
| 754 // kReportDeviceVersionInfo | |
| 755 // kReportDeviceNetworkInterfaces | |
| 756 // kReportDeviceUsers | |
| 757 // kScreenSaverExtensionId | |
| 758 // kScreenSaverTimeout | |
| 759 // kServiceAccountIdentity | |
| 760 // kStartUpUrls | |
| 761 // kSystemTimezonePolicy | |
| 762 // kVariationsRestrictParameter | |
| 763 | |
| 764 LOG(FATAL) << "Device setting " << prop << " is read-only."; | |
| 765 } | |
| 766 | 554 |
| 767 em::PolicyData data; | 555 em::PolicyData data; |
| 768 data.set_username(device_settings_service_->GetUsername()); | 556 data.set_username(device_settings_service_->GetUsername()); |
| 769 CHECK(device_settings_.SerializeToString(data.mutable_policy_value())); | 557 CHECK(device_settings_.SerializeToString(data.mutable_policy_value())); |
| 770 | 558 |
| 771 // Set the cache to the updated value. | 559 // Set the cache to the updated value. |
| 772 UpdateValuesCache(data, device_settings_, trusted_status_); | 560 UpdateValuesCache(data, device_settings_, trusted_status_); |
| 773 | 561 |
| 774 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_TAKEN) { | 562 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_TAKEN) { |
| 775 StoreDeviceSettings(); | 563 StoreDeviceSettings(); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 void DeviceSettingsProvider::AttemptMigration() { | 797 void DeviceSettingsProvider::AttemptMigration() { |
| 1010 if (device_settings_service_->HasPrivateOwnerKey()) { | 798 if (device_settings_service_->HasPrivateOwnerKey()) { |
| 1011 PrefValueMap::const_iterator i; | 799 PrefValueMap::const_iterator i; |
| 1012 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) | 800 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) |
| 1013 DoSet(i->first, *i->second); | 801 DoSet(i->first, *i->second); |
| 1014 migration_values_.Clear(); | 802 migration_values_.Clear(); |
| 1015 } | 803 } |
| 1016 } | 804 } |
| 1017 | 805 |
| 1018 } // namespace chromeos | 806 } // namespace chromeos |
| OLD | NEW |