Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_provider.cc

Issue 12452003: Move pref backing up flags from local state to device settings on ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some more comments addressed. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 bool metrics_value = false; 270 bool metrics_value = false;
268 if (value->GetAsBoolean(&metrics_value)) 271 if (value->GetAsBoolean(&metrics_value))
269 metrics->set_metrics_enabled(metrics_value); 272 metrics->set_metrics_enabled(metrics_value);
270 else 273 else
271 NOTREACHED(); 274 NOTREACHED();
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 const base::ListValue* users;
278 for (base::ListValue::const_iterator i = users.begin(); 281 value->GetAsList(&users);
279 i != users.end(); ++i) { 282 for (base::ListValue::const_iterator i = users->begin();
283 i != users->end(); ++i) {
280 std::string email; 284 std::string email;
281 if ((*i)->GetAsString(&email)) 285 if ((*i)->GetAsString(&email))
282 whitelist_proto->add_user_whitelist(email.c_str()); 286 whitelist_proto->add_user_whitelist(email);
283 } 287 }
284 } else if (prop == kAccountsPrefEphemeralUsersEnabled) { 288 } else if (prop == kAccountsPrefEphemeralUsersEnabled) {
285 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = 289 em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
286 device_settings_.mutable_ephemeral_users_enabled(); 290 device_settings_.mutable_ephemeral_users_enabled();
287 bool ephemeral_users_enabled_value = false; 291 bool ephemeral_users_enabled_value = false;
288 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) { 292 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) {
289 ephemeral_users_enabled->set_ephemeral_users_enabled( 293 ephemeral_users_enabled->set_ephemeral_users_enabled(
290 ephemeral_users_enabled_value); 294 ephemeral_users_enabled_value);
291 } else { 295 } else {
292 NOTREACHED(); 296 NOTREACHED();
293 } 297 }
294 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) { 298 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) {
295 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers = 299 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers =
296 device_settings_.mutable_allow_redeem_offers(); 300 device_settings_.mutable_allow_redeem_offers();
297 bool allow_redeem_offers_value = true; 301 bool allow_redeem_offers_value = true;
298 if (value->GetAsBoolean(&allow_redeem_offers_value)) { 302 if (value->GetAsBoolean(&allow_redeem_offers_value)) {
299 allow_redeem_offers->set_allow_redeem_offers( 303 allow_redeem_offers->set_allow_redeem_offers(
300 allow_redeem_offers_value); 304 allow_redeem_offers_value);
301 } else { 305 } else {
302 NOTREACHED(); 306 NOTREACHED();
303 } 307 }
308 } else if (prop == kStartUpFlags) {
309 em::StartUpFlagsProto* flags_proto =
310 device_settings_.mutable_start_up_flags();
311 flags_proto->Clear();
312 const base::ListValue* flags;
313 value->GetAsList(&flags);
Joao da Silva 2013/03/07 07:50:07 This needs to be tested (same for the whitelist ab
pastarmovj 2013/03/07 13:40:59 Done.
314 for (base::ListValue::const_iterator i = flags->begin();
315 i != flags->end(); ++i) {
316 std::string flag;
317 if ((*i)->GetAsString(&flag))
318 flags_proto->add_flags(flag);
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
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 trusted_status_ = trusted_status; 624 trusted_status_ = trusted_status;
598 for (size_t i = 0; i < notifications.size(); ++i) 625 for (size_t i = 0; i < notifications.size(); ++i)
599 NotifyObservers(notifications[i]); 626 NotifyObservers(notifications[i]);
600 } 627 }
601 628
602 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file, 629 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file,
603 bool new_value) { 630 bool new_value) {
604 // TODO(pastarmovj): Remove this once migration is not needed anymore. 631 // 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. 632 // If the value is not set we should try to migrate legacy consent file.
606 if (use_file) { 633 if (use_file) {
634 UMA_HISTOGRAM_COUNTS("DeviceSettings.MetricsMigrated", 1);
607 new_value = HasOldMetricsFile(); 635 new_value = HasOldMetricsFile();
608 // Make sure the values will get eventually written to the policy file. 636 // Make sure the values will get eventually written to the policy file.
609 migration_values_.SetValue(kStatsReportingPref, 637 migration_values_.SetValue(kStatsReportingPref,
610 base::Value::CreateBooleanValue(new_value)); 638 base::Value::CreateBooleanValue(new_value));
611 AttemptMigration(); 639 AttemptMigration();
612 LOG(INFO) << "No metrics policy set will revert to checking " 640 LOG(INFO) << "No metrics policy set will revert to checking "
613 << "consent file which is " 641 << "consent file which is "
614 << (new_value ? "on." : "off."); 642 << (new_value ? "on." : "off.");
615 } 643 }
616 VLOG(1) << "Metrics policy is being set to : " << new_value 644 VLOG(1) << "Metrics policy is being set to : " << new_value
(...skipping 19 matching lines...) Expand all
636 } 664 }
637 665
638 void DeviceSettingsProvider::ApplySideEffects( 666 void DeviceSettingsProvider::ApplySideEffects(
639 const em::ChromeDeviceSettingsProto& settings) { 667 const em::ChromeDeviceSettingsProto& settings) {
640 // First migrate metrics settings as needed. 668 // First migrate metrics settings as needed.
641 if (settings.has_metrics_enabled()) 669 if (settings.has_metrics_enabled())
642 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled()); 670 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled());
643 else 671 else
644 ApplyMetricsSetting(true, false); 672 ApplyMetricsSetting(true, false);
645 673
674 // TODO(pastarmovj): Remove this after we don't need it anymore.
675 // See: http://crosbug.com/39553
676 // Migrate flags to device settings.
677 PrefService* local_state = g_browser_process->local_state();
678 if (local_state->HasPrefPath(prefs::kEnabledLabsExperiments)) {
679 if (!settings.has_start_up_flags()) {
680 const base::ListValue* flags =
681 local_state->GetList(prefs::kEnabledLabsExperiments);
682 migration_values_.SetValue(kStartUpFlags, flags->DeepCopy());
683 AttemptMigration();
Joao da Silva 2013/03/07 07:50:07 indent
pastarmovj 2013/03/07 13:40:59 Done.
684 } else {
685 // Either it has been properly migrated or the user already specified new
686 // flags in the device policy.
687 UMA_HISTOGRAM_COUNTS("DeviceSettings.FlagsMigrated", 1);
688 local_state->ClearPref(prefs::kEnabledLabsExperiments);
689 }
690 }
691
646 // Next set the roaming setting as needed. 692 // Next set the roaming setting as needed.
647 ApplyRoamingSetting( 693 ApplyRoamingSetting(
648 settings.has_data_roaming_enabled() ? 694 settings.has_data_roaming_enabled() ?
649 settings.data_roaming_enabled().data_roaming_enabled() : 695 settings.data_roaming_enabled().data_roaming_enabled() :
650 false); 696 false);
651 } 697 }
652 698
653 bool DeviceSettingsProvider::MitigateMissingPolicy() { 699 bool DeviceSettingsProvider::MitigateMissingPolicy() {
654 // First check if the device has been owned already and if not exit 700 // First check if the device has been owned already and if not exit
655 // immediately. 701 // immediately.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 void DeviceSettingsProvider::AttemptMigration() { 840 void DeviceSettingsProvider::AttemptMigration() {
795 if (device_settings_service_->HasPrivateOwnerKey()) { 841 if (device_settings_service_->HasPrivateOwnerKey()) {
796 PrefValueMap::const_iterator i; 842 PrefValueMap::const_iterator i;
797 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) 843 for (i = migration_values_.begin(); i != migration_values_.end(); ++i)
798 DoSet(i->first, *i->second); 844 DoSet(i->first, *i->second);
799 migration_values_.Clear(); 845 migration_values_.Clear();
800 } 846 }
801 } 847 }
802 848
803 } // namespace chromeos 849 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/cros_settings_names.cc ('k') | chrome/browser/policy/proto/chrome_device_policy.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698