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" | |
17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
18 #include "chrome/browser/chromeos/policy/device_local_account.h" | 17 #include "chrome/browser/chromeos/policy/device_local_account.h" |
19 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 18 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
20 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
21 #include "chrome/browser/chromeos/settings/device_settings_cache.h" | 20 #include "chrome/browser/chromeos/settings/device_settings_cache.h" |
22 #include "chrome/browser/metrics/metrics_reporting_state.h" | 21 #include "chrome/browser/metrics/metrics_reporting_state.h" |
23 #include "chrome/installer/util/google_update_settings.h" | 22 #include "chrome/installer/util/google_update_settings.h" |
24 #include "chromeos/chromeos_switches.h" | 23 #include "chromeos/chromeos_switches.h" |
25 #include "chromeos/dbus/cryptohome_client.h" | 24 #include "chromeos/dbus/cryptohome_client.h" |
26 #include "chromeos/dbus/dbus_thread_manager.h" | 25 #include "chromeos/dbus/dbus_thread_manager.h" |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 ownership_status_(device_settings_service_->GetOwnershipStatus()), | 442 ownership_status_(device_settings_service_->GetOwnershipStatus()), |
444 store_callback_factory_(this) { | 443 store_callback_factory_(this) { |
445 device_settings_service_->AddObserver(this); | 444 device_settings_service_->AddObserver(this); |
446 if (!UpdateFromService()) { | 445 if (!UpdateFromService()) { |
447 // Make sure we have at least the cache data immediately. | 446 // Make sure we have at least the cache data immediately. |
448 RetrieveCachedData(); | 447 RetrieveCachedData(); |
449 } | 448 } |
450 } | 449 } |
451 | 450 |
452 DeviceSettingsProvider::~DeviceSettingsProvider() { | 451 DeviceSettingsProvider::~DeviceSettingsProvider() { |
453 if (device_settings_service_->GetOwnerSettingsService()) | |
454 device_settings_service_->GetOwnerSettingsService()->RemoveObserver(this); | |
455 device_settings_service_->RemoveObserver(this); | 452 device_settings_service_->RemoveObserver(this); |
456 } | 453 } |
457 | 454 |
458 // static | 455 // static |
459 bool DeviceSettingsProvider::IsDeviceSetting(const std::string& name) { | 456 bool DeviceSettingsProvider::IsDeviceSetting(const std::string& name) { |
460 const char** end = kKnownSettings + arraysize(kKnownSettings); | 457 const char** end = kKnownSettings + arraysize(kKnownSettings); |
461 return std::find(kKnownSettings, end, name) != end; | 458 return std::find(kKnownSettings, end, name) != end; |
462 } | 459 } |
463 | 460 |
464 void DeviceSettingsProvider::DoSet(const std::string& path, | 461 void DeviceSettingsProvider::DoSet(const std::string& path, |
465 const base::Value& in_value) { | 462 const base::Value& in_value) { |
466 // 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 |
467 // device doesn't have an owner yet. | 464 // device doesn't have an owner yet. |
468 if (!(device_settings_service_->HasPrivateOwnerKey() || | 465 if (!(device_settings_service_->HasPrivateOwnerKey() || |
469 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)) { | 466 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE)) { |
470 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; | 467 LOG(WARNING) << "Changing settings from non-owner, setting=" << path; |
471 | 468 |
472 // Revert UI change. | 469 // Revert UI change. |
473 NotifyObservers(path); | 470 NotifyObservers(path); |
474 return; | 471 return; |
475 } | 472 } |
476 | 473 |
477 if (!IsDeviceSetting(path)) { | 474 if (IsDeviceSetting(path)) { |
| 475 pending_changes_.push_back(PendingQueueElement(path, in_value.DeepCopy())); |
| 476 if (!store_callback_factory_.HasWeakPtrs()) |
| 477 SetInPolicy(); |
| 478 } else { |
478 NOTREACHED() << "Try to set unhandled cros setting " << path; | 479 NOTREACHED() << "Try to set unhandled cros setting " << path; |
479 return; | |
480 } | 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 } | |
490 } else { | |
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 } | |
508 } | |
509 | |
510 bool metrics_value; | |
511 if (path == kStatsReportingPref && in_value.GetAsBoolean(&metrics_value)) | |
512 ApplyMetricsSetting(false, metrics_value); | |
513 } | 481 } |
514 | 482 |
515 void DeviceSettingsProvider::OwnershipStatusChanged() { | 483 void DeviceSettingsProvider::OwnershipStatusChanged() { |
516 DeviceSettingsService::OwnershipStatus new_ownership_status = | 484 DeviceSettingsService::OwnershipStatus new_ownership_status = |
517 device_settings_service_->GetOwnershipStatus(); | 485 device_settings_service_->GetOwnershipStatus(); |
518 | 486 |
519 if (device_settings_service_->GetOwnerSettingsService()) | |
520 device_settings_service_->GetOwnerSettingsService()->AddObserver(this); | |
521 | |
522 // If the device just became owned, write the settings accumulated in the | 487 // If the device just became owned, write the settings accumulated in the |
523 // cache to device settings proper. It is important that writing only happens | 488 // cache to device settings proper. It is important that writing only happens |
524 // in this case, as during normal operation, the contents of the cache should | 489 // in this case, as during normal operation, the contents of the cache should |
525 // never overwrite actual device settings. | 490 // never overwrite actual device settings. |
526 if (new_ownership_status == DeviceSettingsService::OWNERSHIP_TAKEN && | 491 if (new_ownership_status == DeviceSettingsService::OWNERSHIP_TAKEN && |
527 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE && | 492 ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE && |
528 device_settings_service_->HasPrivateOwnerKey()) { | 493 device_settings_service_->HasPrivateOwnerKey()) { |
529 // There shouldn't be any pending writes, since the cache writes are all | 494 // There shouldn't be any pending writes, since the cache writes are all |
530 // immediate. | 495 // immediate. |
531 DCHECK(!store_callback_factory_.HasWeakPtrs()); | 496 DCHECK(!store_callback_factory_.HasWeakPtrs()); |
532 | 497 |
533 trusted_status_ = TEMPORARILY_UNTRUSTED; | 498 trusted_status_ = TEMPORARILY_UNTRUSTED; |
534 // Apply the locally-accumulated device settings on top of the initial | 499 // Apply the locally-accumulated device settings on top of the initial |
535 // settings from the service and write back the result. | 500 // settings from the service and write back the result. |
536 if (device_settings_service_->device_settings()) { | 501 if (device_settings_service_->device_settings()) { |
537 em::ChromeDeviceSettingsProto new_settings( | 502 em::ChromeDeviceSettingsProto new_settings( |
538 *device_settings_service_->device_settings()); | 503 *device_settings_service_->device_settings()); |
539 new_settings.MergeFrom(device_settings_); | 504 new_settings.MergeFrom(device_settings_); |
540 device_settings_.Swap(&new_settings); | 505 device_settings_.Swap(&new_settings); |
541 } | 506 } |
542 | 507 StoreDeviceSettings(); |
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 } | |
550 } | 508 } |
551 | 509 |
552 // The owner key might have become available, allowing migration to happen. | 510 // The owner key might have become available, allowing migration to happen. |
553 AttemptMigration(); | 511 AttemptMigration(); |
554 | 512 |
555 ownership_status_ = new_ownership_status; | 513 ownership_status_ = new_ownership_status; |
556 } | 514 } |
557 | 515 |
558 void DeviceSettingsProvider::DeviceSettingsUpdated() { | 516 void DeviceSettingsProvider::DeviceSettingsUpdated() { |
559 if (!store_callback_factory_.HasWeakPtrs()) | 517 if (!store_callback_factory_.HasWeakPtrs()) |
560 UpdateAndProceedStoring(); | 518 UpdateAndProceedStoring(); |
561 } | 519 } |
562 | 520 |
563 void DeviceSettingsProvider::OnTentativeChangesInPolicy( | |
564 const em::PolicyData& policy_data) { | |
565 em::ChromeDeviceSettingsProto device_settings; | |
566 CHECK(device_settings.ParseFromString(policy_data.policy_value())); | |
567 UpdateValuesCache(policy_data, device_settings, TEMPORARILY_UNTRUSTED); | |
568 } | |
569 | |
570 void DeviceSettingsProvider::RetrieveCachedData() { | 521 void DeviceSettingsProvider::RetrieveCachedData() { |
571 em::PolicyData policy_data; | 522 em::PolicyData policy_data; |
572 if (!device_settings_cache::Retrieve(&policy_data, | 523 if (!device_settings_cache::Retrieve(&policy_data, |
573 g_browser_process->local_state()) || | 524 g_browser_process->local_state()) || |
574 !device_settings_.ParseFromString(policy_data.policy_value())) { | 525 !device_settings_.ParseFromString(policy_data.policy_value())) { |
575 VLOG(1) << "Can't retrieve temp store, possibly not created yet."; | 526 VLOG(1) << "Can't retrieve temp store, possibly not created yet."; |
576 } | 527 } |
577 | 528 |
578 UpdateValuesCache(policy_data, device_settings_, trusted_status_); | 529 UpdateValuesCache(policy_data, device_settings_, trusted_status_); |
579 } | 530 } |
580 | 531 |
| 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 |
581 void DeviceSettingsProvider::UpdateValuesCache( | 787 void DeviceSettingsProvider::UpdateValuesCache( |
582 const em::PolicyData& policy_data, | 788 const em::PolicyData& policy_data, |
583 const em::ChromeDeviceSettingsProto& settings, | 789 const em::ChromeDeviceSettingsProto& settings, |
584 TrustedStatus trusted_status) { | 790 TrustedStatus trusted_status) { |
585 PrefValueMap new_values_cache; | 791 PrefValueMap new_values_cache; |
586 | 792 |
587 // If the device is not managed, or is consumer-managed, we set the device | 793 // If the device is not managed, or is consumer-managed, we set the device |
588 // owner value. | 794 // owner value. |
589 if (policy_data.has_username() && | 795 if (policy_data.has_username() && |
590 (!policy_data.has_request_token() || | 796 (!policy_data.has_request_token() || |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 DeviceSettingsProvider::TrustedStatus | 920 DeviceSettingsProvider::TrustedStatus |
715 DeviceSettingsProvider::RequestTrustedEntity() { | 921 DeviceSettingsProvider::RequestTrustedEntity() { |
716 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE) | 922 if (ownership_status_ == DeviceSettingsService::OWNERSHIP_NONE) |
717 return TRUSTED; | 923 return TRUSTED; |
718 return trusted_status_; | 924 return trusted_status_; |
719 } | 925 } |
720 | 926 |
721 void DeviceSettingsProvider::UpdateAndProceedStoring() { | 927 void DeviceSettingsProvider::UpdateAndProceedStoring() { |
722 // Re-sync the cache from the service. | 928 // Re-sync the cache from the service. |
723 UpdateFromService(); | 929 UpdateFromService(); |
| 930 |
| 931 // Trigger the next change if necessary. |
| 932 if (trusted_status_ == TRUSTED && !pending_changes_.empty()) |
| 933 SetInPolicy(); |
724 } | 934 } |
725 | 935 |
726 bool DeviceSettingsProvider::UpdateFromService() { | 936 bool DeviceSettingsProvider::UpdateFromService() { |
727 bool settings_loaded = false; | 937 bool settings_loaded = false; |
728 switch (device_settings_service_->status()) { | 938 switch (device_settings_service_->status()) { |
729 case DeviceSettingsService::STORE_SUCCESS: { | 939 case DeviceSettingsService::STORE_SUCCESS: { |
730 const em::PolicyData* policy_data = | 940 const em::PolicyData* policy_data = |
731 device_settings_service_->policy_data(); | 941 device_settings_service_->policy_data(); |
732 const em::ChromeDeviceSettingsProto* device_settings = | 942 const em::ChromeDeviceSettingsProto* device_settings = |
733 device_settings_service_->device_settings(); | 943 device_settings_service_->device_settings(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 | 987 |
778 // Notify the observers we are done. | 988 // Notify the observers we are done. |
779 std::vector<base::Closure> callbacks; | 989 std::vector<base::Closure> callbacks; |
780 callbacks.swap(callbacks_); | 990 callbacks.swap(callbacks_); |
781 for (size_t i = 0; i < callbacks.size(); ++i) | 991 for (size_t i = 0; i < callbacks.size(); ++i) |
782 callbacks[i].Run(); | 992 callbacks[i].Run(); |
783 | 993 |
784 return settings_loaded; | 994 return settings_loaded; |
785 } | 995 } |
786 | 996 |
| 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 |
787 void DeviceSettingsProvider::AttemptMigration() { | 1009 void DeviceSettingsProvider::AttemptMigration() { |
788 if (device_settings_service_->HasPrivateOwnerKey()) { | 1010 if (device_settings_service_->HasPrivateOwnerKey()) { |
789 PrefValueMap::const_iterator i; | 1011 PrefValueMap::const_iterator i; |
790 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) | 1012 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) |
791 DoSet(i->first, *i->second); | 1013 DoSet(i->first, *i->second); |
792 migration_values_.Clear(); | 1014 migration_values_.Clear(); |
793 } | 1015 } |
794 } | 1016 } |
795 | 1017 |
796 } // namespace chromeos | 1018 } // namespace chromeos |
OLD | NEW |