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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
17 #include "chrome/browser/chromeos/policy/device_local_account.h" | 18 #include "chrome/browser/chromeos/policy/device_local_account.h" |
18 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 19 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
20 #include "chrome/browser/chromeos/settings/device_settings_cache.h" | 21 #include "chrome/browser/chromeos/settings/device_settings_cache.h" |
21 #include "chrome/browser/metrics/metrics_reporting_state.h" | 22 #include "chrome/browser/metrics/metrics_reporting_state.h" |
22 #include "chrome/installer/util/google_update_settings.h" | 23 #include "chrome/installer/util/google_update_settings.h" |
23 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
24 #include "chromeos/dbus/cryptohome_client.h" | 25 #include "chromeos/dbus/cryptohome_client.h" |
25 #include "chromeos/dbus/dbus_thread_manager.h" | 26 #include "chromeos/dbus/dbus_thread_manager.h" |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 ownership_status_(device_settings_service_->GetOwnershipStatus()), | 443 ownership_status_(device_settings_service_->GetOwnershipStatus()), |
443 store_callback_factory_(this) { | 444 store_callback_factory_(this) { |
444 device_settings_service_->AddObserver(this); | 445 device_settings_service_->AddObserver(this); |
445 if (!UpdateFromService()) { | 446 if (!UpdateFromService()) { |
446 // Make sure we have at least the cache data immediately. | 447 // Make sure we have at least the cache data immediately. |
447 RetrieveCachedData(); | 448 RetrieveCachedData(); |
448 } | 449 } |
449 } | 450 } |
450 | 451 |
451 DeviceSettingsProvider::~DeviceSettingsProvider() { | 452 DeviceSettingsProvider::~DeviceSettingsProvider() { |
| 453 if (device_settings_service_->GetOwnerSettingsService()) |
| 454 device_settings_service_->GetOwnerSettingsService()->RemoveObserver(this); |
452 device_settings_service_->RemoveObserver(this); | 455 device_settings_service_->RemoveObserver(this); |
453 } | 456 } |
454 | 457 |
455 // static | 458 // static |
456 bool DeviceSettingsProvider::IsDeviceSetting(const std::string& name) { | 459 bool DeviceSettingsProvider::IsDeviceSetting(const std::string& name) { |
457 const char** end = kKnownSettings + arraysize(kKnownSettings); | 460 const char** end = kKnownSettings + arraysize(kKnownSettings); |
458 return std::find(kKnownSettings, end, name) != end; | 461 return std::find(kKnownSettings, end, name) != end; |
459 } | 462 } |
460 | 463 |
461 void DeviceSettingsProvider::DoSet(const std::string& path, | 464 void DeviceSettingsProvider::DoSet(const std::string& path, |
462 const base::Value& in_value) { | 465 const base::Value& in_value) { |
463 // Make sure that either the current user is the device owner or the | 466 // Make sure that either the current user is the device owner or the |
464 // device doesn't have an owner yet. | 467 // device doesn't have an owner yet. |
465 if (!(device_settings_service_->HasPrivateOwnerKey() || | 468 if (!(device_settings_service_->HasPrivateOwnerKey() || |
466 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)) { | 469 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)) { |
467 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; | 470 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; |
468 | 471 |
469 // Revert UI change. | 472 // Revert UI change. |
470 NotifyObservers(path); | 473 NotifyObservers(path); |
471 return; | 474 return; |
472 } | 475 } |
473 | 476 |
474 if (IsDeviceSetting(path)) { | 477 if (!IsDeviceSetting(path)) { |
475 pending_changes_.push_back(PendingQueueElement(path, in_value.DeepCopy())); | |
476 if (!store_callback_factory_.HasWeakPtrs()) | |
477 SetInPolicy(); | |
478 } else { | |
479 NOTREACHED() << "Try to set unhandled cros setting " << path; | 478 NOTREACHED() << "Try to set unhandled cros setting " << path; |
| 479 return; |
480 } | 480 } |
| 481 |
| 482 // TODO (ygorshenin@, crbug.com/230018)): use OwnerSettingsService::Set() |
| 483 // here. |
| 484 pending_changes_.push_back(PendingQueueElement(path, in_value.DeepCopy())); |
| 485 if (!store_callback_factory_.HasWeakPtrs()) |
| 486 SetInPolicy(); |
481 } | 487 } |
482 | 488 |
483 void DeviceSettingsProvider::OwnershipStatusChanged() { | 489 void DeviceSettingsProvider::OwnershipStatusChanged() { |
484 DeviceSettingsService::OwnershipStatus new_ownership_status = | 490 DeviceSettingsService::OwnershipStatus new_ownership_status = |
485 device_settings_service_->GetOwnershipStatus(); | 491 device_settings_service_->GetOwnershipStatus(); |
486 | 492 |
| 493 if (device_settings_service_->GetOwnerSettingsService()) |
| 494 device_settings_service_->GetOwnerSettingsService()->AddObserver(this); |
| 495 |
487 // If the device just became owned, write the settings accumulated in the | 496 // If the device just became owned, write the settings accumulated in the |
488 // cache to device settings proper. It is important that writing only happens | 497 // cache to device settings proper. It is important that writing only happens |
489 // in this case, as during normal operation, the contents of the cache should | 498 // in this case, as during normal operation, the contents of the cache should |
490 // never overwrite actual device settings. | 499 // never overwrite actual device settings. |
491 if (new_ownership_status == DeviceSettingsService::OWNERSHIP_TAKEN && | 500 if (new_ownership_status == DeviceSettingsService::OWNERSHIP_TAKEN && |
492 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE && | 501 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE && |
493 device_settings_service_->HasPrivateOwnerKey()) { | 502 device_settings_service_->HasPrivateOwnerKey()) { |
494 // There shouldn't be any pending writes, since the cache writes are all | 503 // There shouldn't be any pending writes, since the cache writes are all |
495 // immediate. | 504 // immediate. |
496 DCHECK(!store_callback_factory_.HasWeakPtrs()); | 505 DCHECK(!store_callback_factory_.HasWeakPtrs()); |
(...skipping 14 matching lines...) Expand all Loading... |
511 AttemptMigration(); | 520 AttemptMigration(); |
512 | 521 |
513 ownership_status_ = new_ownership_status; | 522 ownership_status_ = new_ownership_status; |
514 } | 523 } |
515 | 524 |
516 void DeviceSettingsProvider::DeviceSettingsUpdated() { | 525 void DeviceSettingsProvider::DeviceSettingsUpdated() { |
517 if (!store_callback_factory_.HasWeakPtrs()) | 526 if (!store_callback_factory_.HasWeakPtrs()) |
518 UpdateAndProceedStoring(); | 527 UpdateAndProceedStoring(); |
519 } | 528 } |
520 | 529 |
| 530 void DeviceSettingsProvider::OnTentativeChangesInPolicy( |
| 531 const em::PolicyData& policy_data) { |
| 532 em::ChromeDeviceSettingsProto device_settings; |
| 533 CHECK(device_settings.ParseFromString(policy_data.policy_value())); |
| 534 UpdateValuesCache(policy_data, device_settings, TEMPORARILY_UNTRUSTED); |
| 535 } |
| 536 |
521 void DeviceSettingsProvider::RetrieveCachedData() { | 537 void DeviceSettingsProvider::RetrieveCachedData() { |
522 em::PolicyData policy_data; | 538 em::PolicyData policy_data; |
523 if (!device_settings_cache::Retrieve(&policy_data, | 539 if (!device_settings_cache::Retrieve(&policy_data, |
524 g_browser_process->local_state()) || | 540 g_browser_process->local_state()) || |
525 !device_settings_.ParseFromString(policy_data.policy_value())) { | 541 !device_settings_.ParseFromString(policy_data.policy_value())) { |
526 VLOG(1) << "Can't retrieve temp store, possibly not created yet."; | 542 VLOG(1) << "Can't retrieve temp store, possibly not created yet."; |
527 } | 543 } |
528 | 544 |
529 UpdateValuesCache(policy_data, device_settings_, trusted_status_); | 545 UpdateValuesCache(policy_data, device_settings_, trusted_status_); |
530 } | 546 } |
531 | 547 |
532 void DeviceSettingsProvider::SetInPolicy() { | 548 void DeviceSettingsProvider::SetInPolicy() { |
533 if (pending_changes_.empty()) { | 549 if (pending_changes_.empty()) { |
534 NOTREACHED(); | 550 NOTREACHED(); |
535 return; | 551 return; |
536 } | 552 } |
537 | 553 |
538 if (RequestTrustedEntity() != TRUSTED) { | 554 if (RequestTrustedEntity() != TRUSTED) { |
539 // Re-sync device settings before proceeding. | 555 // Re-sync device settings before proceeding. |
540 device_settings_service_->Load(); | 556 device_settings_service_->Load(); |
541 return; | 557 return; |
542 } | 558 } |
543 | 559 |
544 std::string prop(pending_changes_.front().first); | 560 std::string prop(pending_changes_.front().first); |
545 scoped_ptr<base::Value> value(pending_changes_.front().second); | 561 scoped_ptr<base::Value> value(pending_changes_.front().second); |
546 pending_changes_.pop_front(); | 562 pending_changes_.pop_front(); |
547 | 563 |
548 trusted_status_ = TEMPORARILY_UNTRUSTED; | 564 trusted_status_ = TEMPORARILY_UNTRUSTED; |
549 if (prop == kAccountsPrefAllowNewUser) { | 565 OwnerSettingsServiceChromeOS::UpdateDeviceSettings( |
550 em::AllowNewUsersProto* allow = | 566 prop, *value, device_settings_); |
551 device_settings_.mutable_allow_new_users(); | 567 |
552 bool allow_value; | 568 bool metrics_value; |
553 if (value->GetAsBoolean(&allow_value)) | 569 if (prop == kStatsReportingPref && value->GetAsBoolean(&metrics_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); | 570 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 | 571 |
767 em::PolicyData data; | 572 em::PolicyData data; |
768 data.set_username(device_settings_service_->GetUsername()); | 573 data.set_username(device_settings_service_->GetUsername()); |
769 CHECK(device_settings_.SerializeToString(data.mutable_policy_value())); | 574 CHECK(device_settings_.SerializeToString(data.mutable_policy_value())); |
770 | 575 |
771 // Set the cache to the updated value. | 576 // Set the cache to the updated value. |
772 UpdateValuesCache(data, device_settings_, trusted_status_); | 577 UpdateValuesCache(data, device_settings_, trusted_status_); |
773 | 578 |
774 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_TAKEN) { | 579 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_TAKEN) { |
775 StoreDeviceSettings(); | 580 StoreDeviceSettings(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 void DeviceSettingsProvider::AttemptMigration() { | 814 void DeviceSettingsProvider::AttemptMigration() { |
1010 if (device_settings_service_->HasPrivateOwnerKey()) { | 815 if (device_settings_service_->HasPrivateOwnerKey()) { |
1011 PrefValueMap::const_iterator i; | 816 PrefValueMap::const_iterator i; |
1012 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) | 817 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) |
1013 DoSet(i->first, *i->second); | 818 DoSet(i->first, *i->second); |
1014 migration_values_.Clear(); | 819 migration_values_.Clear(); |
1015 } | 820 } |
1016 } | 821 } |
1017 | 822 |
1018 } // namespace chromeos | 823 } // namespace chromeos |
OLD | NEW |