Chromium Code Reviews| 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/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | |
| 13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/cros/network_library.h" | 20 #include "chrome/browser/chromeos/cros/network_library.h" |
| 20 #include "chrome/browser/chromeos/settings/cros_settings.h" | 21 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 21 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 22 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 22 #include "chrome/browser/chromeos/settings/device_settings_cache.h" | 23 #include "chrome/browser/chromeos/settings/device_settings_cache.h" |
| 23 #include "chrome/browser/policy/app_pack_updater.h" | 24 #include "chrome/browser/policy/app_pack_updater.h" |
| 24 #include "chrome/browser/policy/browser_policy_connector.h" | 25 #include "chrome/browser/policy/browser_policy_connector.h" |
| 25 #include "chrome/browser/policy/cloud_policy_constants.h" | 26 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 26 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 27 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 27 #include "chrome/browser/ui/options/options_util.h" | 28 #include "chrome/browser/ui/options/options_util.h" |
| 28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | |
| 29 #include "chrome/installer/util/google_update_settings.h" | 31 #include "chrome/installer/util/google_update_settings.h" |
| 30 | 32 |
| 31 using google::protobuf::RepeatedPtrField; | 33 using google::protobuf::RepeatedPtrField; |
| 32 | 34 |
| 33 namespace em = enterprise_management; | 35 namespace em = enterprise_management; |
| 34 | 36 |
| 35 namespace chromeos { | 37 namespace chromeos { |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 56 kReportDeviceBootMode, | 58 kReportDeviceBootMode, |
| 57 kReportDeviceLocation, | 59 kReportDeviceLocation, |
| 58 kReportDeviceVersionInfo, | 60 kReportDeviceVersionInfo, |
| 59 kScreenSaverExtensionId, | 61 kScreenSaverExtensionId, |
| 60 kScreenSaverTimeout, | 62 kScreenSaverTimeout, |
| 61 kSettingProxyEverywhere, | 63 kSettingProxyEverywhere, |
| 62 kSignedDataRoamingEnabled, | 64 kSignedDataRoamingEnabled, |
| 63 kStartUpUrls, | 65 kStartUpUrls, |
| 64 kStatsReportingPref, | 66 kStatsReportingPref, |
| 65 kSystemTimezonePolicy, | 67 kSystemTimezonePolicy, |
| 68 kStartUpFlags, | |
| 66 }; | 69 }; |
| 67 | 70 |
| 68 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS. | 71 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS. |
| 69 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences"; | 72 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences"; |
| 70 | 73 |
| 71 bool HasOldMetricsFile() { | 74 bool HasOldMetricsFile() { |
| 72 // TODO(pastarmovj): Remove this once migration is not needed anymore. | 75 // TODO(pastarmovj): Remove this once migration is not needed anymore. |
| 73 // If the value is not set we should try to migrate legacy consent file. | 76 // If the value is not set we should try to migrate legacy consent file. |
| 74 // Loading consent file state causes us to do blocking IO on UI thread. | 77 // Loading consent file state causes us to do blocking IO on UI thread. |
| 75 // Temporarily allow it until we fix http://crbug.com/62626 | 78 // Temporarily allow it until we fix http://crbug.com/62626 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 ApplyMetricsSetting(false, metrics_value); | 275 ApplyMetricsSetting(false, metrics_value); |
| 273 } else if (prop == kAccountsPrefUsers) { | 276 } else if (prop == kAccountsPrefUsers) { |
| 274 em::UserWhitelistProto* whitelist_proto = | 277 em::UserWhitelistProto* whitelist_proto = |
| 275 device_settings_.mutable_user_whitelist(); | 278 device_settings_.mutable_user_whitelist(); |
| 276 whitelist_proto->clear_user_whitelist(); | 279 whitelist_proto->clear_user_whitelist(); |
| 277 base::ListValue& users = static_cast<base::ListValue&>(*value); | 280 base::ListValue& users = static_cast<base::ListValue&>(*value); |
| 278 for (base::ListValue::const_iterator i = users.begin(); | 281 for (base::ListValue::const_iterator i = users.begin(); |
| 279 i != users.end(); ++i) { | 282 i != users.end(); ++i) { |
| 280 std::string email; | 283 std::string email; |
| 281 if ((*i)->GetAsString(&email)) | 284 if ((*i)->GetAsString(&email)) |
| 282 whitelist_proto->add_user_whitelist(email.c_str()); | 285 whitelist_proto->add_user_whitelist(email); |
| 283 } | 286 } |
| 284 } else if (prop == kAccountsPrefEphemeralUsersEnabled) { | 287 } else if (prop == kAccountsPrefEphemeralUsersEnabled) { |
| 285 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = | 288 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = |
| 286 device_settings_.mutable_ephemeral_users_enabled(); | 289 device_settings_.mutable_ephemeral_users_enabled(); |
| 287 bool ephemeral_users_enabled_value = false; | 290 bool ephemeral_users_enabled_value = false; |
| 288 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) { | 291 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) { |
| 289 ephemeral_users_enabled->set_ephemeral_users_enabled( | 292 ephemeral_users_enabled->set_ephemeral_users_enabled( |
| 290 ephemeral_users_enabled_value); | 293 ephemeral_users_enabled_value); |
| 291 } else { | 294 } else { |
| 292 NOTREACHED(); | 295 NOTREACHED(); |
| 293 } | 296 } |
| 294 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) { | 297 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) { |
| 295 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers = | 298 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers = |
| 296 device_settings_.mutable_allow_redeem_offers(); | 299 device_settings_.mutable_allow_redeem_offers(); |
| 297 bool allow_redeem_offers_value = true; | 300 bool allow_redeem_offers_value = true; |
| 298 if (value->GetAsBoolean(&allow_redeem_offers_value)) { | 301 if (value->GetAsBoolean(&allow_redeem_offers_value)) { |
| 299 allow_redeem_offers->set_allow_redeem_offers( | 302 allow_redeem_offers->set_allow_redeem_offers( |
| 300 allow_redeem_offers_value); | 303 allow_redeem_offers_value); |
| 301 } else { | 304 } else { |
| 302 NOTREACHED(); | 305 NOTREACHED(); |
| 303 } | 306 } |
| 307 } else if (prop == kStartUpFlags) { | |
| 308 em::StartUpFlagsProto* flags_proto = | |
| 309 device_settings_.mutable_start_up_flags(); | |
| 310 flags_proto->Clear(); | |
| 311 base::ListValue& flags = static_cast<base::ListValue&>(*value); | |
|
Joao da Silva
2013/03/05 17:46:30
Use value->GetAsList (same for kAccountsPrefUsers
pastarmovj
2013/03/06 17:28:31
Done.
| |
| 312 for (base::ListValue::const_iterator i = flags.begin(); | |
| 313 i != flags.end(); ++i) { | |
| 314 std::string flag; | |
| 315 if ((*i)->GetAsString(&flag)) | |
| 316 flags_proto->add_flags(flag); | |
| 317 } | |
| 304 } else { | 318 } else { |
| 305 // The remaining settings don't support Set(), since they are not | 319 // The remaining settings don't support Set(), since they are not |
| 306 // intended to be customizable by the user: | 320 // intended to be customizable by the user: |
| 307 // kAppPack | 321 // kAppPack |
| 308 // kDeviceOwner | 322 // kDeviceOwner |
| 309 // kIdleLogoutTimeout | 323 // kIdleLogoutTimeout |
| 310 // kIdleLogoutWarningDuration | 324 // kIdleLogoutWarningDuration |
| 311 // kReleaseChannelDelegated | 325 // kReleaseChannelDelegated |
| 312 // kReportDeviceVersionInfo | 326 // kReportDeviceVersionInfo |
| 313 // kReportDeviceActivityTimes | 327 // kReportDeviceActivityTimes |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { | 413 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { |
| 400 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = | 414 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = |
| 401 policy.device_local_accounts().account(); | 415 policy.device_local_accounts().account(); |
| 402 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; | 416 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; |
| 403 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { | 417 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { |
| 404 if (entry->has_id()) | 418 if (entry->has_id()) |
| 405 account_list->AppendString(entry->id()); | 419 account_list->AppendString(entry->id()); |
| 406 } | 420 } |
| 407 } | 421 } |
| 408 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list); | 422 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list); |
| 423 | |
| 424 if (policy.has_start_up_flags()) { | |
| 425 base::ListValue* list = new base::ListValue(); | |
| 426 const em::StartUpFlagsProto& flags_proto = policy.start_up_flags(); | |
| 427 const RepeatedPtrField<std::string>& flags = flags_proto.flags(); | |
| 428 for (RepeatedPtrField<std::string>::const_iterator it = flags.begin(); | |
| 429 it != flags.end(); ++it) { | |
| 430 list->Append(new base::StringValue(*it)); | |
| 431 } | |
| 432 new_values_cache->SetValue(kStartUpFlags, list); | |
| 433 } | |
| 409 } | 434 } |
| 410 | 435 |
| 411 void DeviceSettingsProvider::DecodeKioskPolicies( | 436 void DeviceSettingsProvider::DecodeKioskPolicies( |
| 412 const em::ChromeDeviceSettingsProto& policy, | 437 const em::ChromeDeviceSettingsProto& policy, |
| 413 PrefValueMap* new_values_cache) const { | 438 PrefValueMap* new_values_cache) const { |
| 414 if (policy.has_forced_logout_timeouts()) { | 439 if (policy.has_forced_logout_timeouts()) { |
| 415 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) { | 440 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) { |
| 416 new_values_cache->SetInteger( | 441 new_values_cache->SetInteger( |
| 417 kIdleLogoutTimeout, | 442 kIdleLogoutTimeout, |
| 418 policy.forced_logout_timeouts().idle_logout_timeout()); | 443 policy.forced_logout_timeouts().idle_logout_timeout()); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 trusted_status_ = trusted_status; | 622 trusted_status_ = trusted_status; |
| 598 for (size_t i = 0; i < notifications.size(); ++i) | 623 for (size_t i = 0; i < notifications.size(); ++i) |
| 599 NotifyObservers(notifications[i]); | 624 NotifyObservers(notifications[i]); |
| 600 } | 625 } |
| 601 | 626 |
| 602 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file, | 627 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file, |
| 603 bool new_value) { | 628 bool new_value) { |
| 604 // TODO(pastarmovj): Remove this once migration is not needed anymore. | 629 // TODO(pastarmovj): Remove this once migration is not needed anymore. |
| 605 // If the value is not set we should try to migrate legacy consent file. | 630 // If the value is not set we should try to migrate legacy consent file. |
| 606 if (use_file) { | 631 if (use_file) { |
| 632 UMA_HISTOGRAM_COUNTS("DeviceSettings.MetricsMigrated", 1); | |
| 607 new_value = HasOldMetricsFile(); | 633 new_value = HasOldMetricsFile(); |
| 608 // Make sure the values will get eventually written to the policy file. | 634 // Make sure the values will get eventually written to the policy file. |
| 609 migration_values_.SetValue(kStatsReportingPref, | 635 migration_values_.SetValue(kStatsReportingPref, |
| 610 base::Value::CreateBooleanValue(new_value)); | 636 base::Value::CreateBooleanValue(new_value)); |
| 611 AttemptMigration(); | 637 AttemptMigration(); |
| 612 LOG(INFO) << "No metrics policy set will revert to checking " | 638 LOG(INFO) << "No metrics policy set will revert to checking " |
| 613 << "consent file which is " | 639 << "consent file which is " |
| 614 << (new_value ? "on." : "off."); | 640 << (new_value ? "on." : "off."); |
| 615 } | 641 } |
| 616 VLOG(1) << "Metrics policy is being set to : " << new_value | 642 VLOG(1) << "Metrics policy is being set to : " << new_value |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 636 } | 662 } |
| 637 | 663 |
| 638 void DeviceSettingsProvider::ApplySideEffects( | 664 void DeviceSettingsProvider::ApplySideEffects( |
| 639 const em::ChromeDeviceSettingsProto& settings) { | 665 const em::ChromeDeviceSettingsProto& settings) { |
| 640 // First migrate metrics settings as needed. | 666 // First migrate metrics settings as needed. |
| 641 if (settings.has_metrics_enabled()) | 667 if (settings.has_metrics_enabled()) |
| 642 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled()); | 668 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled()); |
| 643 else | 669 else |
| 644 ApplyMetricsSetting(true, false); | 670 ApplyMetricsSetting(true, false); |
| 645 | 671 |
| 672 // TODO(pastarmovj): Remove this after we don't need it anymore. | |
| 673 // See: http://crosbug.com/39553 | |
| 674 // Migrate flags to device settings. | |
| 675 if (!settings.has_start_up_flags()) { | |
| 676 PrefService* local_state = g_browser_process->local_state(); | |
| 677 if (local_state->HasPrefPath(prefs::kEnabledLabsExperiments)) { | |
| 678 UMA_HISTOGRAM_COUNTS("DeviceSettings.FlagsMigrated", 1); | |
| 679 const base::ListValue* flags = | |
| 680 local_state->GetList(prefs::kEnabledLabsExperiments); | |
| 681 migration_values_.SetValue(kStartUpFlags, flags->DeepCopy()); | |
| 682 AttemptMigration(); | |
|
Joao da Silva
2013/03/05 17:46:30
What happens if that fails (i.e. there is no priva
pastarmovj
2013/03/06 17:28:31
I changed the logic to avoid clearing the pref bef
| |
| 683 local_state->ClearPref(prefs::kEnabledLabsExperiments); | |
| 684 } | |
| 685 } | |
| 686 | |
| 646 // Next set the roaming setting as needed. | 687 // Next set the roaming setting as needed. |
| 647 ApplyRoamingSetting( | 688 ApplyRoamingSetting( |
| 648 settings.has_data_roaming_enabled() ? | 689 settings.has_data_roaming_enabled() ? |
| 649 settings.data_roaming_enabled().data_roaming_enabled() : | 690 settings.data_roaming_enabled().data_roaming_enabled() : |
| 650 false); | 691 false); |
| 651 } | 692 } |
| 652 | 693 |
| 653 bool DeviceSettingsProvider::MitigateMissingPolicy() { | 694 bool DeviceSettingsProvider::MitigateMissingPolicy() { |
| 654 // First check if the device has been owned already and if not exit | 695 // First check if the device has been owned already and if not exit |
| 655 // immediately. | 696 // immediately. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 void DeviceSettingsProvider::AttemptMigration() { | 835 void DeviceSettingsProvider::AttemptMigration() { |
| 795 if (device_settings_service_->HasPrivateOwnerKey()) { | 836 if (device_settings_service_->HasPrivateOwnerKey()) { |
| 796 PrefValueMap::const_iterator i; | 837 PrefValueMap::const_iterator i; |
| 797 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) | 838 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) |
| 798 DoSet(i->first, *i->second); | 839 DoSet(i->first, *i->second); |
| 799 migration_values_.Clear(); | 840 migration_values_.Clear(); |
| 800 } | 841 } |
| 801 } | 842 } |
| 802 | 843 |
| 803 } // namespace chromeos | 844 } // namespace chromeos |
| OLD | NEW |