Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_provider.cc

Issue 654263003: Implemented OwnerSettingsService::Set() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed crashes under asan. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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())); 478 NOTREACHED() << "Try to set unhandled cros setting " << path;
476 if (!store_callback_factory_.HasWeakPtrs()) 479 return;
477 SetInPolicy(); 480 }
481
482 if (device_settings_service_->HasPrivateOwnerKey()) {
483 // Directly set setting through OwnerSettingsService.
484 ownership::OwnerSettingsService* service =
485 device_settings_service_->GetOwnerSettingsService();
486 if (!service->Set(path, in_value)) {
487 NotifyObservers(path);
488 return;
489 }
478 } else { 490 } else {
479 NOTREACHED() << "Try to set unhandled cros setting " << path; 491 // Temporary store new setting in
492 // |device_settings_|. |device_settings_| will be stored on a disk
493 // as soon as an ownership of device the will be taken.
494 OwnerSettingsServiceChromeOS::UpdateDeviceSettings(
495 path, in_value, device_settings_);
496 em::PolicyData data;
497 data.set_username(device_settings_service_->GetUsername());
498 CHECK(device_settings_.SerializeToString(data.mutable_policy_value()));
499
500 // Set the cache to the updated value.
501 UpdateValuesCache(data, device_settings_, TEMPORARILY_UNTRUSTED);
502
503 if (!device_settings_cache::Store(data, g_browser_process->local_state())) {
504 LOG(ERROR) << "Couldn't store to the temp storage.";
505 NotifyObservers(path);
506 return;
507 }
480 } 508 }
509
510 bool metrics_value;
511 if (path == kStatsReportingPref && in_value.GetAsBoolean(&metrics_value))
512 ApplyMetricsSetting(false, metrics_value);
481 } 513 }
482 514
483 void DeviceSettingsProvider::OwnershipStatusChanged() { 515 void DeviceSettingsProvider::OwnershipStatusChanged() {
484 DeviceSettingsService::OwnershipStatus new_ownership_status = 516 DeviceSettingsService::OwnershipStatus new_ownership_status =
485 device_settings_service_->GetOwnershipStatus(); 517 device_settings_service_->GetOwnershipStatus();
486 518
519 if (device_settings_service_->GetOwnerSettingsService())
520 device_settings_service_->GetOwnerSettingsService()->AddObserver(this);
521
487 // If the device just became owned, write the settings accumulated in the 522 // 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 523 // 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 524 // in this case, as during normal operation, the contents of the cache should
490 // never overwrite actual device settings. 525 // never overwrite actual device settings.
491 if (new_ownership_status == DeviceSettingsService::OWNERSHIP_TAKEN && 526 if (new_ownership_status == DeviceSettingsService::OWNERSHIP_TAKEN &&
492 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE && 527 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE &&
493 device_settings_service_->HasPrivateOwnerKey()) { 528 device_settings_service_->HasPrivateOwnerKey()) {
494 // There shouldn't be any pending writes, since the cache writes are all 529 // There shouldn't be any pending writes, since the cache writes are all
495 // immediate. 530 // immediate.
496 DCHECK(!store_callback_factory_.HasWeakPtrs()); 531 DCHECK(!store_callback_factory_.HasWeakPtrs());
497 532
498 trusted_status_ = TEMPORARILY_UNTRUSTED; 533 trusted_status_ = TEMPORARILY_UNTRUSTED;
499 // Apply the locally-accumulated device settings on top of the initial 534 // Apply the locally-accumulated device settings on top of the initial
500 // settings from the service and write back the result. 535 // settings from the service and write back the result.
501 if (device_settings_service_->device_settings()) { 536 if (device_settings_service_->device_settings()) {
502 em::ChromeDeviceSettingsProto new_settings( 537 em::ChromeDeviceSettingsProto new_settings(
503 *device_settings_service_->device_settings()); 538 *device_settings_service_->device_settings());
504 new_settings.MergeFrom(device_settings_); 539 new_settings.MergeFrom(device_settings_);
505 device_settings_.Swap(&new_settings); 540 device_settings_.Swap(&new_settings);
506 } 541 }
507 StoreDeviceSettings(); 542
543 scoped_ptr<em::PolicyData> policy(new em::PolicyData());
544 policy->set_username(device_settings_service_->GetUsername());
545 CHECK(device_settings_.SerializeToString(policy->mutable_policy_value()));
546 if (!device_settings_service_->GetOwnerSettingsService()
547 ->CommitTentativeDeviceSettings(policy.Pass())) {
548 LOG(ERROR) << "Can't store policy";
549 }
508 } 550 }
509 551
510 // The owner key might have become available, allowing migration to happen. 552 // The owner key might have become available, allowing migration to happen.
511 AttemptMigration(); 553 AttemptMigration();
512 554
513 ownership_status_ = new_ownership_status; 555 ownership_status_ = new_ownership_status;
514 } 556 }
515 557
516 void DeviceSettingsProvider::DeviceSettingsUpdated() { 558 void DeviceSettingsProvider::DeviceSettingsUpdated() {
517 if (!store_callback_factory_.HasWeakPtrs()) 559 if (!store_callback_factory_.HasWeakPtrs())
518 UpdateAndProceedStoring(); 560 UpdateAndProceedStoring();
519 } 561 }
520 562
563 void DeviceSettingsProvider::OnDeviceSettingsServiceShutdown() {
564 device_settings_service_ = nullptr;
565 }
566
567 void DeviceSettingsProvider::OnTentativeChangesInPolicy(
568 const em::PolicyData& policy_data) {
569 em::ChromeDeviceSettingsProto device_settings;
570 CHECK(device_settings.ParseFromString(policy_data.policy_value()));
571 UpdateValuesCache(policy_data, device_settings, TEMPORARILY_UNTRUSTED);
572 }
573
521 void DeviceSettingsProvider::RetrieveCachedData() { 574 void DeviceSettingsProvider::RetrieveCachedData() {
522 em::PolicyData policy_data; 575 em::PolicyData policy_data;
523 if (!device_settings_cache::Retrieve(&policy_data, 576 if (!device_settings_cache::Retrieve(&policy_data,
524 g_browser_process->local_state()) || 577 g_browser_process->local_state()) ||
525 !device_settings_.ParseFromString(policy_data.policy_value())) { 578 !device_settings_.ParseFromString(policy_data.policy_value())) {
526 VLOG(1) << "Can't retrieve temp store, possibly not created yet."; 579 VLOG(1) << "Can't retrieve temp store, possibly not created yet.";
527 } 580 }
528 581
529 UpdateValuesCache(policy_data, device_settings_, trusted_status_); 582 UpdateValuesCache(policy_data, device_settings_, trusted_status_);
530 } 583 }
531 584
532 void DeviceSettingsProvider::SetInPolicy() {
533 if (pending_changes_.empty()) {
534 NOTREACHED();
535 return;
536 }
537
538 if (RequestTrustedEntity() != TRUSTED) {
539 // Re-sync device settings before proceeding.
540 device_settings_service_->Load();
541 return;
542 }
543
544 std::string prop(pending_changes_.front().first);
545 scoped_ptr<base::Value> value(pending_changes_.front().second);
546 pending_changes_.pop_front();
547
548 trusted_status_ = TEMPORARILY_UNTRUSTED;
549 if (prop == kAccountsPrefAllowNewUser) {
550 em::AllowNewUsersProto* allow =
551 device_settings_.mutable_allow_new_users();
552 bool allow_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);
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
767 em::PolicyData data;
768 data.set_username(device_settings_service_->GetUsername());
769 CHECK(device_settings_.SerializeToString(data.mutable_policy_value()));
770
771 // Set the cache to the updated value.
772 UpdateValuesCache(data, device_settings_, trusted_status_);
773
774 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_TAKEN) {
775 StoreDeviceSettings();
776 } else {
777 if (!device_settings_cache::Store(data, g_browser_process->local_state()))
778 LOG(ERROR) << "Couldn't store to the temp storage.";
779
780 // OnStorePolicyCompleted won't get called in this case so proceed with any
781 // pending operations immediately.
782 if (!pending_changes_.empty())
783 SetInPolicy();
784 }
785 }
786
787 void DeviceSettingsProvider::UpdateValuesCache( 585 void DeviceSettingsProvider::UpdateValuesCache(
788 const em::PolicyData& policy_data, 586 const em::PolicyData& policy_data,
789 const em::ChromeDeviceSettingsProto& settings, 587 const em::ChromeDeviceSettingsProto& settings,
790 TrustedStatus trusted_status) { 588 TrustedStatus trusted_status) {
791 PrefValueMap new_values_cache; 589 PrefValueMap new_values_cache;
792 590
793 // If the device is not managed, or is consumer-managed, we set the device 591 // If the device is not managed, or is consumer-managed, we set the device
794 // owner value. 592 // owner value.
795 if (policy_data.has_username() && 593 if (policy_data.has_username() &&
796 (!policy_data.has_request_token() || 594 (!policy_data.has_request_token() ||
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 DeviceSettingsProvider::TrustedStatus 718 DeviceSettingsProvider::TrustedStatus
921 DeviceSettingsProvider::RequestTrustedEntity() { 719 DeviceSettingsProvider::RequestTrustedEntity() {
922 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE) 720 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)
923 return TRUSTED; 721 return TRUSTED;
924 return trusted_status_; 722 return trusted_status_;
925 } 723 }
926 724
927 void DeviceSettingsProvider::UpdateAndProceedStoring() { 725 void DeviceSettingsProvider::UpdateAndProceedStoring() {
928 // Re-sync the cache from the service. 726 // Re-sync the cache from the service.
929 UpdateFromService(); 727 UpdateFromService();
930
931 // Trigger the next change if necessary.
932 if (trusted_status_ == TRUSTED && !pending_changes_.empty())
933 SetInPolicy();
934 } 728 }
935 729
936 bool DeviceSettingsProvider::UpdateFromService() { 730 bool DeviceSettingsProvider::UpdateFromService() {
937 bool settings_loaded = false; 731 bool settings_loaded = false;
938 switch (device_settings_service_->status()) { 732 switch (device_settings_service_->status()) {
939 case DeviceSettingsService::STORE_SUCCESS: { 733 case DeviceSettingsService::STORE_SUCCESS: {
940 const em::PolicyData* policy_data = 734 const em::PolicyData* policy_data =
941 device_settings_service_->policy_data(); 735 device_settings_service_->policy_data();
942 const em::ChromeDeviceSettingsProto* device_settings = 736 const em::ChromeDeviceSettingsProto* device_settings =
943 device_settings_service_->device_settings(); 737 device_settings_service_->device_settings();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 781
988 // Notify the observers we are done. 782 // Notify the observers we are done.
989 std::vector<base::Closure> callbacks; 783 std::vector<base::Closure> callbacks;
990 callbacks.swap(callbacks_); 784 callbacks.swap(callbacks_);
991 for (size_t i = 0; i < callbacks.size(); ++i) 785 for (size_t i = 0; i < callbacks.size(); ++i)
992 callbacks[i].Run(); 786 callbacks[i].Run();
993 787
994 return settings_loaded; 788 return settings_loaded;
995 } 789 }
996 790
997 void DeviceSettingsProvider::StoreDeviceSettings() {
998 // Mute all previous callbacks to guarantee the |pending_changes_| queue is
999 // processed serially.
1000 store_callback_factory_.InvalidateWeakPtrs();
1001
1002 device_settings_service_->SignAndStore(
1003 scoped_ptr<em::ChromeDeviceSettingsProto>(
1004 new em::ChromeDeviceSettingsProto(device_settings_)),
1005 base::Bind(&DeviceSettingsProvider::UpdateAndProceedStoring,
1006 store_callback_factory_.GetWeakPtr()));
1007 }
1008
1009 void DeviceSettingsProvider::AttemptMigration() { 791 void DeviceSettingsProvider::AttemptMigration() {
1010 if (device_settings_service_->HasPrivateOwnerKey()) { 792 if (device_settings_service_->HasPrivateOwnerKey()) {
1011 PrefValueMap::const_iterator i; 793 PrefValueMap::const_iterator i;
1012 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) 794 for (i = migration_values_.begin(); i != migration_values_.end(); ++i)
1013 DoSet(i->first, *i->second); 795 DoSet(i->first, *i->second);
1014 migration_values_.Clear(); 796 migration_values_.Clear();
1015 } 797 }
1016 } 798 }
1017 799
1018 } // namespace chromeos 800 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698