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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 kReportDeviceHardwareStatus, | 72 kReportDeviceHardwareStatus, |
73 kReportDeviceLocation, | 73 kReportDeviceLocation, |
74 kReportDeviceNetworkInterfaces, | 74 kReportDeviceNetworkInterfaces, |
75 kReportDeviceSessionStatus, | 75 kReportDeviceSessionStatus, |
76 kReportDeviceUsers, | 76 kReportDeviceUsers, |
77 kReportDeviceVersionInfo, | 77 kReportDeviceVersionInfo, |
78 kReportUploadFrequency, | 78 kReportUploadFrequency, |
79 kServiceAccountIdentity, | 79 kServiceAccountIdentity, |
80 kSignedDataRoamingEnabled, | 80 kSignedDataRoamingEnabled, |
81 kStartUpFlags, | 81 kStartUpFlags, |
82 kStatsReportingPref, | |
83 kSystemTimezonePolicy, | 82 kSystemTimezonePolicy, |
84 kSystemUse24HourClock, | 83 kSystemUse24HourClock, |
85 kUpdateDisabled, | 84 kUpdateDisabled, |
86 kVariationsRestrictParameter, | 85 kVariationsRestrictParameter, |
87 }; | 86 }; |
88 | 87 |
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( | 88 void DecodeLoginPolicies( |
99 const em::ChromeDeviceSettingsProto& policy, | 89 const em::ChromeDeviceSettingsProto& policy, |
100 PrefValueMap* new_values_cache) { | 90 PrefValueMap* new_values_cache) { |
101 // For all our boolean settings the following is applicable: | 91 // For all our boolean settings the following is applicable: |
102 // true is default permissive value and false is safe prohibitive value. | 92 // true is default permissive value and false is safe prohibitive value. |
103 // Exceptions: | 93 // Exceptions: |
104 // kAccountsPrefEphemeralUsersEnabled has a default value of false. | 94 // kAccountsPrefEphemeralUsersEnabled has a default value of false. |
105 // kAccountsPrefSupervisedUsersEnabled has a default value of false | 95 // kAccountsPrefSupervisedUsersEnabled has a default value of false |
106 // for enterprise devices and true for consumer devices. | 96 // for enterprise devices and true for consumer devices. |
107 // kAccountsPrefTransferSAMLCookies has a default value of false. | 97 // kAccountsPrefTransferSAMLCookies has a default value of false. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 if (heartbeat_policy.has_heartbeat_frequency()) { | 351 if (heartbeat_policy.has_heartbeat_frequency()) { |
362 new_values_cache->SetInteger( | 352 new_values_cache->SetInteger( |
363 kHeartbeatFrequency, | 353 kHeartbeatFrequency, |
364 heartbeat_policy.heartbeat_frequency()); | 354 heartbeat_policy.heartbeat_frequency()); |
365 } | 355 } |
366 } | 356 } |
367 | 357 |
368 void DecodeGenericPolicies( | 358 void DecodeGenericPolicies( |
369 const em::ChromeDeviceSettingsProto& policy, | 359 const em::ChromeDeviceSettingsProto& policy, |
370 PrefValueMap* new_values_cache) { | 360 PrefValueMap* new_values_cache) { |
371 if (policy.has_metrics_enabled()) { | |
372 new_values_cache->SetBoolean(kStatsReportingPref, | |
373 policy.metrics_enabled().metrics_enabled()); | |
374 } else { | |
375 new_values_cache->SetBoolean(kStatsReportingPref, HasOldMetricsFile()); | |
376 } | |
377 | |
378 if (!policy.has_release_channel() || | 361 if (!policy.has_release_channel() || |
379 !policy.release_channel().has_release_channel()) { | 362 !policy.release_channel().has_release_channel()) { |
380 // Default to an invalid channel (will be ignored). | 363 // Default to an invalid channel (will be ignored). |
381 new_values_cache->SetString(kReleaseChannel, ""); | 364 new_values_cache->SetString(kReleaseChannel, ""); |
382 } else { | 365 } else { |
383 new_values_cache->SetString(kReleaseChannel, | 366 new_values_cache->SetString(kReleaseChannel, |
384 policy.release_channel().release_channel()); | 367 policy.release_channel().release_channel()); |
385 } | 368 } |
386 | 369 |
387 new_values_cache->SetBoolean( | 370 new_values_cache->SetBoolean( |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 | 521 |
539 // Set the cache to the updated value. | 522 // Set the cache to the updated value. |
540 UpdateValuesCache(data, device_settings_, TEMPORARILY_UNTRUSTED); | 523 UpdateValuesCache(data, device_settings_, TEMPORARILY_UNTRUSTED); |
541 | 524 |
542 if (!device_settings_cache::Store(data, g_browser_process->local_state())) { | 525 if (!device_settings_cache::Store(data, g_browser_process->local_state())) { |
543 LOG(ERROR) << "Couldn't store to the temp storage."; | 526 LOG(ERROR) << "Couldn't store to the temp storage."; |
544 NotifyObservers(path); | 527 NotifyObservers(path); |
545 return; | 528 return; |
546 } | 529 } |
547 } | 530 } |
548 | |
549 bool metrics_value; | |
550 if (path == kStatsReportingPref && in_value.GetAsBoolean(&metrics_value)) | |
551 ApplyMetricsSetting(false, metrics_value); | |
552 } | 531 } |
553 | 532 |
554 void DeviceSettingsProvider::OwnershipStatusChanged() { | 533 void DeviceSettingsProvider::OwnershipStatusChanged() { |
555 DeviceSettingsService::OwnershipStatus new_ownership_status = | 534 DeviceSettingsService::OwnershipStatus new_ownership_status = |
556 device_settings_service_->GetOwnershipStatus(); | 535 device_settings_service_->GetOwnershipStatus(); |
557 | 536 |
558 if (device_settings_service_->GetOwnerSettingsService()) | 537 if (device_settings_service_->GetOwnerSettingsService()) |
559 device_settings_service_->GetOwnerSettingsService()->AddObserver(this); | 538 device_settings_service_->GetOwnerSettingsService()->AddObserver(this); |
560 | 539 |
561 // If the device just became owned, write the settings accumulated in the | 540 // If the device just became owned, write the settings accumulated in the |
(...skipping 18 matching lines...) Expand all Loading... |
580 } | 559 } |
581 | 560 |
582 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); | 561 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); |
583 policy->set_username(device_settings_service_->GetUsername()); | 562 policy->set_username(device_settings_service_->GetUsername()); |
584 CHECK(device_settings_.SerializeToString(policy->mutable_policy_value())); | 563 CHECK(device_settings_.SerializeToString(policy->mutable_policy_value())); |
585 if (!device_settings_service_->GetOwnerSettingsService() | 564 if (!device_settings_service_->GetOwnerSettingsService() |
586 ->CommitTentativeDeviceSettings(policy.Pass())) { | 565 ->CommitTentativeDeviceSettings(policy.Pass())) { |
587 LOG(ERROR) << "Can't store policy"; | 566 LOG(ERROR) << "Can't store policy"; |
588 } | 567 } |
589 } | 568 } |
590 | |
591 // The owner key might have become available, allowing migration to happen. | |
592 AttemptMigration(); | |
593 | |
594 ownership_status_ = new_ownership_status; | 569 ownership_status_ = new_ownership_status; |
595 } | 570 } |
596 | 571 |
597 void DeviceSettingsProvider::DeviceSettingsUpdated() { | 572 void DeviceSettingsProvider::DeviceSettingsUpdated() { |
598 if (!store_callback_factory_.HasWeakPtrs()) | 573 if (!store_callback_factory_.HasWeakPtrs()) |
599 UpdateAndProceedStoring(); | 574 UpdateAndProceedStoring(); |
600 } | 575 } |
601 | 576 |
602 void DeviceSettingsProvider::OnDeviceSettingsServiceShutdown() { | 577 void DeviceSettingsProvider::OnDeviceSettingsServiceShutdown() { |
603 device_settings_service_ = nullptr; | 578 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)) | 644 if (!new_values_cache.GetValue(iter->first, &value)) |
670 notifications.push_back(iter->first); | 645 notifications.push_back(iter->first); |
671 } | 646 } |
672 // Swap and notify. | 647 // Swap and notify. |
673 values_cache_.Swap(&new_values_cache); | 648 values_cache_.Swap(&new_values_cache); |
674 trusted_status_ = trusted_status; | 649 trusted_status_ = trusted_status; |
675 for (size_t i = 0; i < notifications.size(); ++i) | 650 for (size_t i = 0; i < notifications.size(); ++i) |
676 NotifyObservers(notifications[i]); | 651 NotifyObservers(notifications[i]); |
677 } | 652 } |
678 | 653 |
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() { | 654 bool DeviceSettingsProvider::MitigateMissingPolicy() { |
710 // First check if the device has been owned already and if not exit | 655 // First check if the device has been owned already and if not exit |
711 // immediately. | 656 // immediately. |
712 policy::BrowserPolicyConnectorChromeOS* connector = | 657 policy::BrowserPolicyConnectorChromeOS* connector = |
713 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 658 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
714 if (connector->GetDeviceMode() != policy::DEVICE_MODE_CONSUMER) | 659 if (connector->GetDeviceMode() != policy::DEVICE_MODE_CONSUMER) |
715 return false; | 660 return false; |
716 | 661 |
717 // If we are here the policy file were corrupted or missing. This can happen | 662 // 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 | 663 // because we are migrating Pre R11 device to the new secure policies or there |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 device_settings_service_->policy_data(); | 723 device_settings_service_->policy_data(); |
779 const em::ChromeDeviceSettingsProto* device_settings = | 724 const em::ChromeDeviceSettingsProto* device_settings = |
780 device_settings_service_->device_settings(); | 725 device_settings_service_->device_settings(); |
781 if (policy_data && device_settings) { | 726 if (policy_data && device_settings) { |
782 if (!device_settings_cache::Store(*policy_data, | 727 if (!device_settings_cache::Store(*policy_data, |
783 g_browser_process->local_state())) { | 728 g_browser_process->local_state())) { |
784 LOG(ERROR) << "Couldn't update the local state cache."; | 729 LOG(ERROR) << "Couldn't update the local state cache."; |
785 } | 730 } |
786 UpdateValuesCache(*policy_data, *device_settings, TRUSTED); | 731 UpdateValuesCache(*policy_data, *device_settings, TRUSTED); |
787 device_settings_ = *device_settings; | 732 device_settings_ = *device_settings; |
788 | |
789 // TODO(pastarmovj): Make those side effects responsibility of the | |
790 // respective subsystems. | |
791 ApplySideEffects(*device_settings); | |
792 | |
793 settings_loaded = true; | 733 settings_loaded = true; |
794 } else { | 734 } else { |
795 // Initial policy load is still pending. | 735 // Initial policy load is still pending. |
796 trusted_status_ = TEMPORARILY_UNTRUSTED; | 736 trusted_status_ = TEMPORARILY_UNTRUSTED; |
797 } | 737 } |
798 break; | 738 break; |
799 } | 739 } |
800 case DeviceSettingsService::STORE_NO_POLICY: | 740 case DeviceSettingsService::STORE_NO_POLICY: |
801 if (MitigateMissingPolicy()) | 741 if (MitigateMissingPolicy()) |
802 break; | 742 break; |
(...skipping 21 matching lines...) Expand all Loading... |
824 | 764 |
825 // Notify the observers we are done. | 765 // Notify the observers we are done. |
826 std::vector<base::Closure> callbacks; | 766 std::vector<base::Closure> callbacks; |
827 callbacks.swap(callbacks_); | 767 callbacks.swap(callbacks_); |
828 for (size_t i = 0; i < callbacks.size(); ++i) | 768 for (size_t i = 0; i < callbacks.size(); ++i) |
829 callbacks[i].Run(); | 769 callbacks[i].Run(); |
830 | 770 |
831 return settings_loaded; | 771 return settings_loaded; |
832 } | 772 } |
833 | 773 |
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 | 774 } // namespace chromeos |
OLD | NEW |