| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 kServiceAccountIdentity, | 80 kServiceAccountIdentity, |
| 81 kSignedDataRoamingEnabled, | 81 kSignedDataRoamingEnabled, |
| 82 kStartUpFlags, | 82 kStartUpFlags, |
| 83 kStatsReportingPref, | 83 kStatsReportingPref, |
| 84 kSystemTimezonePolicy, | 84 kSystemTimezonePolicy, |
| 85 kSystemUse24HourClock, | 85 kSystemUse24HourClock, |
| 86 kUpdateDisabled, | 86 kUpdateDisabled, |
| 87 kVariationsRestrictParameter, | 87 kVariationsRestrictParameter, |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 bool HasOldMetricsFile() { | |
| 91 // TODO(pastarmovj): Remove this once migration is not needed anymore. | |
| 92 // If the value is not set we should try to migrate legacy consent file. | |
| 93 // Loading consent file state causes us to do blocking IO on UI thread. | |
| 94 // Temporarily allow it until we fix http://crbug.com/62626 | |
| 95 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 96 return GoogleUpdateSettings::GetCollectStatsConsent(); | |
| 97 } | |
| 98 | |
| 99 void DecodeLoginPolicies( | 90 void DecodeLoginPolicies( |
| 100 const em::ChromeDeviceSettingsProto& policy, | 91 const em::ChromeDeviceSettingsProto& policy, |
| 101 PrefValueMap* new_values_cache) { | 92 PrefValueMap* new_values_cache) { |
| 102 // For all our boolean settings the following is applicable: | 93 // For all our boolean settings the following is applicable: |
| 103 // true is default permissive value and false is safe prohibitive value. | 94 // true is default permissive value and false is safe prohibitive value. |
| 104 // Exceptions: | 95 // Exceptions: |
| 105 // kAccountsPrefEphemeralUsersEnabled has a default value of false. | 96 // kAccountsPrefEphemeralUsersEnabled has a default value of false. |
| 106 // kAccountsPrefSupervisedUsersEnabled has a default value of false | 97 // kAccountsPrefSupervisedUsersEnabled has a default value of false |
| 107 // for enterprise devices and true for consumer devices. | 98 // for enterprise devices and true for consumer devices. |
| 108 // kAccountsPrefTransferSAMLCookies has a default value of false. | 99 // kAccountsPrefTransferSAMLCookies has a default value of false. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 357 } |
| 367 } | 358 } |
| 368 | 359 |
| 369 void DecodeGenericPolicies( | 360 void DecodeGenericPolicies( |
| 370 const em::ChromeDeviceSettingsProto& policy, | 361 const em::ChromeDeviceSettingsProto& policy, |
| 371 PrefValueMap* new_values_cache) { | 362 PrefValueMap* new_values_cache) { |
| 372 if (policy.has_metrics_enabled()) { | 363 if (policy.has_metrics_enabled()) { |
| 373 new_values_cache->SetBoolean(kStatsReportingPref, | 364 new_values_cache->SetBoolean(kStatsReportingPref, |
| 374 policy.metrics_enabled().metrics_enabled()); | 365 policy.metrics_enabled().metrics_enabled()); |
| 375 } else { | 366 } else { |
| 376 new_values_cache->SetBoolean(kStatsReportingPref, HasOldMetricsFile()); | 367 new_values_cache->SetBoolean(kStatsReportingPref, false); |
| 377 } | 368 } |
| 378 | 369 |
| 379 if (!policy.has_release_channel() || | 370 if (!policy.has_release_channel() || |
| 380 !policy.release_channel().has_release_channel()) { | 371 !policy.release_channel().has_release_channel()) { |
| 381 // Default to an invalid channel (will be ignored). | 372 // Default to an invalid channel (will be ignored). |
| 382 new_values_cache->SetString(kReleaseChannel, ""); | 373 new_values_cache->SetString(kReleaseChannel, ""); |
| 383 } else { | 374 } else { |
| 384 new_values_cache->SetString(kReleaseChannel, | 375 new_values_cache->SetString(kReleaseChannel, |
| 385 policy.release_channel().release_channel()); | 376 policy.release_channel().release_channel()); |
| 386 } | 377 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 // Set the cache to the updated value. | 538 // Set the cache to the updated value. |
| 548 UpdateValuesCache(data, device_settings_, TEMPORARILY_UNTRUSTED); | 539 UpdateValuesCache(data, device_settings_, TEMPORARILY_UNTRUSTED); |
| 549 | 540 |
| 550 if (!device_settings_cache::Store(data, g_browser_process->local_state())) { | 541 if (!device_settings_cache::Store(data, g_browser_process->local_state())) { |
| 551 LOG(ERROR) << "Couldn't store to the temp storage."; | 542 LOG(ERROR) << "Couldn't store to the temp storage."; |
| 552 NotifyObservers(path); | 543 NotifyObservers(path); |
| 553 return; | 544 return; |
| 554 } | 545 } |
| 555 } | 546 } |
| 556 | 547 |
| 557 bool metrics_value; | |
| 558 if (path == kStatsReportingPref && in_value.GetAsBoolean(&metrics_value)) | |
| 559 ApplyMetricsSetting(false, metrics_value); | |
| 560 } | 548 } |
| 561 | 549 |
| 562 void DeviceSettingsProvider::OwnershipStatusChanged() { | 550 void DeviceSettingsProvider::OwnershipStatusChanged() { |
| 563 DeviceSettingsService::OwnershipStatus new_ownership_status = | 551 DeviceSettingsService::OwnershipStatus new_ownership_status = |
| 564 device_settings_service_->GetOwnershipStatus(); | 552 device_settings_service_->GetOwnershipStatus(); |
| 565 | 553 |
| 566 if (device_settings_service_->GetOwnerSettingsService()) | 554 if (device_settings_service_->GetOwnerSettingsService()) |
| 567 device_settings_service_->GetOwnerSettingsService()->AddObserver(this); | 555 device_settings_service_->GetOwnerSettingsService()->AddObserver(this); |
| 568 | 556 |
| 569 // If the device just became owned, write the settings accumulated in the | 557 // If the device just became owned, write the settings accumulated in the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 589 | 577 |
| 590 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); | 578 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); |
| 591 policy->set_username(device_settings_service_->GetUsername()); | 579 policy->set_username(device_settings_service_->GetUsername()); |
| 592 CHECK(device_settings_.SerializeToString(policy->mutable_policy_value())); | 580 CHECK(device_settings_.SerializeToString(policy->mutable_policy_value())); |
| 593 if (!device_settings_service_->GetOwnerSettingsService() | 581 if (!device_settings_service_->GetOwnerSettingsService() |
| 594 ->CommitTentativeDeviceSettings(policy.Pass())) { | 582 ->CommitTentativeDeviceSettings(policy.Pass())) { |
| 595 LOG(ERROR) << "Can't store policy"; | 583 LOG(ERROR) << "Can't store policy"; |
| 596 } | 584 } |
| 597 } | 585 } |
| 598 | 586 |
| 599 // The owner key might have become available, allowing migration to happen. | |
| 600 AttemptMigration(); | |
| 601 | |
| 602 ownership_status_ = new_ownership_status; | 587 ownership_status_ = new_ownership_status; |
| 603 } | 588 } |
| 604 | 589 |
| 605 void DeviceSettingsProvider::DeviceSettingsUpdated() { | 590 void DeviceSettingsProvider::DeviceSettingsUpdated() { |
| 606 if (!store_callback_factory_.HasWeakPtrs()) | 591 if (!store_callback_factory_.HasWeakPtrs()) |
| 607 UpdateAndProceedStoring(); | 592 UpdateAndProceedStoring(); |
| 608 } | 593 } |
| 609 | 594 |
| 610 void DeviceSettingsProvider::OnDeviceSettingsServiceShutdown() { | 595 void DeviceSettingsProvider::OnDeviceSettingsServiceShutdown() { |
| 611 device_settings_service_ = nullptr; | 596 device_settings_service_ = nullptr; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 if (!new_values_cache.GetValue(iter->first, &value)) | 662 if (!new_values_cache.GetValue(iter->first, &value)) |
| 678 notifications.push_back(iter->first); | 663 notifications.push_back(iter->first); |
| 679 } | 664 } |
| 680 // Swap and notify. | 665 // Swap and notify. |
| 681 values_cache_.Swap(&new_values_cache); | 666 values_cache_.Swap(&new_values_cache); |
| 682 trusted_status_ = trusted_status; | 667 trusted_status_ = trusted_status; |
| 683 for (size_t i = 0; i < notifications.size(); ++i) | 668 for (size_t i = 0; i < notifications.size(); ++i) |
| 684 NotifyObservers(notifications[i]); | 669 NotifyObservers(notifications[i]); |
| 685 } | 670 } |
| 686 | 671 |
| 687 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file, | |
| 688 bool new_value) { | |
| 689 // TODO(pastarmovj): Remove this once migration is not needed anymore. | |
| 690 // If the value is not set we should try to migrate legacy consent file. | |
| 691 if (use_file) { | |
| 692 new_value = HasOldMetricsFile(); | |
| 693 // Make sure the values will get eventually written to the policy file. | |
| 694 migration_values_.SetBoolean(kStatsReportingPref, new_value); | |
| 695 AttemptMigration(); | |
| 696 VLOG(1) << "No metrics policy set will revert to checking " | |
| 697 << "consent file which is " | |
| 698 << (new_value ? "on." : "off."); | |
| 699 UMA_HISTOGRAM_COUNTS("DeviceSettings.MetricsMigrated", 1); | |
| 700 } | |
| 701 VLOG(1) << "Metrics policy is being set to : " << new_value | |
| 702 << "(use file : " << use_file << ")"; | |
| 703 // TODO(pastarmovj): Remove this once we don't need to regenerate the | |
| 704 // consent file for the GUID anymore. | |
| 705 InitiateMetricsReportingChange(new_value, OnMetricsReportingCallbackType()); | |
| 706 } | |
| 707 | |
| 708 void DeviceSettingsProvider::ApplySideEffects( | |
| 709 const em::ChromeDeviceSettingsProto& settings) { | |
| 710 // First migrate metrics settings as needed. | |
| 711 if (settings.has_metrics_enabled()) | |
| 712 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled()); | |
| 713 else | |
| 714 ApplyMetricsSetting(true, false); | |
| 715 } | |
| 716 | |
| 717 bool DeviceSettingsProvider::MitigateMissingPolicy() { | 672 bool DeviceSettingsProvider::MitigateMissingPolicy() { |
| 718 // First check if the device has been owned already and if not exit | 673 // First check if the device has been owned already and if not exit |
| 719 // immediately. | 674 // immediately. |
| 720 policy::BrowserPolicyConnectorChromeOS* connector = | 675 policy::BrowserPolicyConnectorChromeOS* connector = |
| 721 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 676 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 722 if (connector->GetDeviceMode() != policy::DEVICE_MODE_CONSUMER) | 677 if (connector->GetDeviceMode() != policy::DEVICE_MODE_CONSUMER) |
| 723 return false; | 678 return false; |
| 724 | 679 |
| 725 // If we are here the policy file were corrupted or missing. This can happen | 680 // If we are here the policy file were corrupted or missing. This can happen |
| 726 // because we are migrating Pre R11 device to the new secure policies or there | 681 // because we are migrating Pre R11 device to the new secure policies or there |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 const em::ChromeDeviceSettingsProto* device_settings = | 742 const em::ChromeDeviceSettingsProto* device_settings = |
| 788 device_settings_service_->device_settings(); | 743 device_settings_service_->device_settings(); |
| 789 if (policy_data && device_settings) { | 744 if (policy_data && device_settings) { |
| 790 if (!device_settings_cache::Store(*policy_data, | 745 if (!device_settings_cache::Store(*policy_data, |
| 791 g_browser_process->local_state())) { | 746 g_browser_process->local_state())) { |
| 792 LOG(ERROR) << "Couldn't update the local state cache."; | 747 LOG(ERROR) << "Couldn't update the local state cache."; |
| 793 } | 748 } |
| 794 UpdateValuesCache(*policy_data, *device_settings, TRUSTED); | 749 UpdateValuesCache(*policy_data, *device_settings, TRUSTED); |
| 795 device_settings_ = *device_settings; | 750 device_settings_ = *device_settings; |
| 796 | 751 |
| 797 // TODO(pastarmovj): Make those side effects responsibility of the | |
| 798 // respective subsystems. | |
| 799 ApplySideEffects(*device_settings); | |
| 800 | |
| 801 settings_loaded = true; | 752 settings_loaded = true; |
| 802 } else { | 753 } else { |
| 803 // Initial policy load is still pending. | 754 // Initial policy load is still pending. |
| 804 trusted_status_ = TEMPORARILY_UNTRUSTED; | 755 trusted_status_ = TEMPORARILY_UNTRUSTED; |
| 805 } | 756 } |
| 806 break; | 757 break; |
| 807 } | 758 } |
| 808 case DeviceSettingsService::STORE_NO_POLICY: | 759 case DeviceSettingsService::STORE_NO_POLICY: |
| 809 if (MitigateMissingPolicy()) | 760 if (MitigateMissingPolicy()) |
| 810 break; | 761 break; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 832 | 783 |
| 833 // Notify the observers we are done. | 784 // Notify the observers we are done. |
| 834 std::vector<base::Closure> callbacks; | 785 std::vector<base::Closure> callbacks; |
| 835 callbacks.swap(callbacks_); | 786 callbacks.swap(callbacks_); |
| 836 for (size_t i = 0; i < callbacks.size(); ++i) | 787 for (size_t i = 0; i < callbacks.size(); ++i) |
| 837 callbacks[i].Run(); | 788 callbacks[i].Run(); |
| 838 | 789 |
| 839 return settings_loaded; | 790 return settings_loaded; |
| 840 } | 791 } |
| 841 | 792 |
| 842 void DeviceSettingsProvider::AttemptMigration() { | |
| 843 if (device_settings_service_->HasPrivateOwnerKey()) { | |
| 844 PrefValueMap::const_iterator i; | |
| 845 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) | |
| 846 DoSet(i->first, *i->second); | |
| 847 migration_values_.Clear(); | |
| 848 } | |
| 849 } | |
| 850 | |
| 851 } // namespace chromeos | 793 } // namespace chromeos |
| OLD | NEW |