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