| 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" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 kReportDeviceBootMode, | 56 kReportDeviceBootMode, |
| 57 kReportDeviceLocation, | 57 kReportDeviceLocation, |
| 58 kReportDeviceVersionInfo, | 58 kReportDeviceVersionInfo, |
| 59 kScreenSaverExtensionId, | 59 kScreenSaverExtensionId, |
| 60 kScreenSaverTimeout, | 60 kScreenSaverTimeout, |
| 61 kSettingProxyEverywhere, | 61 kSettingProxyEverywhere, |
| 62 kSignedDataRoamingEnabled, | 62 kSignedDataRoamingEnabled, |
| 63 kStartUpUrls, | 63 kStartUpUrls, |
| 64 kStatsReportingPref, | 64 kStatsReportingPref, |
| 65 kSystemTimezonePolicy, | 65 kSystemTimezonePolicy, |
| 66 kStartUpFlags, |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS. | 69 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS. |
| 69 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences"; | 70 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences"; |
| 70 | 71 |
| 71 bool HasOldMetricsFile() { | 72 bool HasOldMetricsFile() { |
| 72 // TODO(pastarmovj): Remove this once migration is not needed anymore. | 73 // 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. | 74 // 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. | 75 // Loading consent file state causes us to do blocking IO on UI thread. |
| 75 // Temporarily allow it until we fix http://crbug.com/62626 | 76 // Temporarily allow it until we fix http://crbug.com/62626 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 bool metrics_value = false; | 268 bool metrics_value = false; |
| 268 if (value->GetAsBoolean(&metrics_value)) | 269 if (value->GetAsBoolean(&metrics_value)) |
| 269 metrics->set_metrics_enabled(metrics_value); | 270 metrics->set_metrics_enabled(metrics_value); |
| 270 else | 271 else |
| 271 NOTREACHED(); | 272 NOTREACHED(); |
| 272 ApplyMetricsSetting(false, metrics_value); | 273 ApplyMetricsSetting(false, metrics_value); |
| 273 } else if (prop == kAccountsPrefUsers) { | 274 } else if (prop == kAccountsPrefUsers) { |
| 274 em::UserWhitelistProto* whitelist_proto = | 275 em::UserWhitelistProto* whitelist_proto = |
| 275 device_settings_.mutable_user_whitelist(); | 276 device_settings_.mutable_user_whitelist(); |
| 276 whitelist_proto->clear_user_whitelist(); | 277 whitelist_proto->clear_user_whitelist(); |
| 277 base::ListValue& users = static_cast<base::ListValue&>(*value); | 278 const base::ListValue* users; |
| 278 for (base::ListValue::const_iterator i = users.begin(); | 279 if (value->GetAsList(&users)) { |
| 279 i != users.end(); ++i) { | 280 for (base::ListValue::const_iterator i = users->begin(); |
| 280 std::string email; | 281 i != users->end(); ++i) { |
| 281 if ((*i)->GetAsString(&email)) | 282 std::string email; |
| 282 whitelist_proto->add_user_whitelist(email.c_str()); | 283 if ((*i)->GetAsString(&email)) |
| 284 whitelist_proto->add_user_whitelist(email); |
| 285 } |
| 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 const base::ListValue* flags; |
| 312 if (value->GetAsList(&flags)) { |
| 313 for (base::ListValue::const_iterator i = flags->begin(); |
| 314 i != flags->end(); ++i) { |
| 315 std::string flag; |
| 316 if ((*i)->GetAsString(&flag)) |
| 317 flags_proto->add_flags(flag); |
| 318 } |
| 319 } |
| 304 } else { | 320 } else { |
| 305 // The remaining settings don't support Set(), since they are not | 321 // The remaining settings don't support Set(), since they are not |
| 306 // intended to be customizable by the user: | 322 // intended to be customizable by the user: |
| 307 // kAppPack | 323 // kAppPack |
| 308 // kDeviceOwner | 324 // kDeviceOwner |
| 309 // kIdleLogoutTimeout | 325 // kIdleLogoutTimeout |
| 310 // kIdleLogoutWarningDuration | 326 // kIdleLogoutWarningDuration |
| 311 // kReleaseChannelDelegated | 327 // kReleaseChannelDelegated |
| 312 // kReportDeviceVersionInfo | 328 // kReportDeviceVersionInfo |
| 313 // kReportDeviceActivityTimes | 329 // kReportDeviceActivityTimes |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { | 415 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { |
| 400 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = | 416 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = |
| 401 policy.device_local_accounts().account(); | 417 policy.device_local_accounts().account(); |
| 402 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; | 418 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; |
| 403 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { | 419 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { |
| 404 if (entry->has_id()) | 420 if (entry->has_id()) |
| 405 account_list->AppendString(entry->id()); | 421 account_list->AppendString(entry->id()); |
| 406 } | 422 } |
| 407 } | 423 } |
| 408 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list); | 424 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list); |
| 425 |
| 426 if (policy.has_start_up_flags()) { |
| 427 base::ListValue* list = new base::ListValue(); |
| 428 const em::StartUpFlagsProto& flags_proto = policy.start_up_flags(); |
| 429 const RepeatedPtrField<std::string>& flags = flags_proto.flags(); |
| 430 for (RepeatedPtrField<std::string>::const_iterator it = flags.begin(); |
| 431 it != flags.end(); ++it) { |
| 432 list->Append(new base::StringValue(*it)); |
| 433 } |
| 434 new_values_cache->SetValue(kStartUpFlags, list); |
| 435 } |
| 409 } | 436 } |
| 410 | 437 |
| 411 void DeviceSettingsProvider::DecodeKioskPolicies( | 438 void DeviceSettingsProvider::DecodeKioskPolicies( |
| 412 const em::ChromeDeviceSettingsProto& policy, | 439 const em::ChromeDeviceSettingsProto& policy, |
| 413 PrefValueMap* new_values_cache) const { | 440 PrefValueMap* new_values_cache) const { |
| 414 if (policy.has_forced_logout_timeouts()) { | 441 if (policy.has_forced_logout_timeouts()) { |
| 415 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) { | 442 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) { |
| 416 new_values_cache->SetInteger( | 443 new_values_cache->SetInteger( |
| 417 kIdleLogoutTimeout, | 444 kIdleLogoutTimeout, |
| 418 policy.forced_logout_timeouts().idle_logout_timeout()); | 445 policy.forced_logout_timeouts().idle_logout_timeout()); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 void DeviceSettingsProvider::AttemptMigration() { | 821 void DeviceSettingsProvider::AttemptMigration() { |
| 795 if (device_settings_service_->HasPrivateOwnerKey()) { | 822 if (device_settings_service_->HasPrivateOwnerKey()) { |
| 796 PrefValueMap::const_iterator i; | 823 PrefValueMap::const_iterator i; |
| 797 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) | 824 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) |
| 798 DoSet(i->first, *i->second); | 825 DoSet(i->first, *i->second); |
| 799 migration_values_.Clear(); | 826 migration_values_.Clear(); |
| 800 } | 827 } |
| 801 } | 828 } |
| 802 | 829 |
| 803 } // namespace chromeos | 830 } // namespace chromeos |
| OLD | NEW |