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

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: Addressed comments. 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 if (value->GetAsList(&users)) {
279 i != users.end(); ++i) { 282 for (base::ListValue::const_iterator i = users->begin();
280 std::string email; 283 i != users->end(); ++i) {
281 if ((*i)->GetAsString(&email)) 284 std::string email;
282 whitelist_proto->add_user_whitelist(email.c_str()); 285 if ((*i)->GetAsString(&email))
286 whitelist_proto->add_user_whitelist(email);
287 }
283 } 288 }
284 } else if (prop == kAccountsPrefEphemeralUsersEnabled) { 289 } else if (prop == kAccountsPrefEphemeralUsersEnabled) {
285 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = 290 em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
286 device_settings_.mutable_ephemeral_users_enabled(); 291 device_settings_.mutable_ephemeral_users_enabled();
287 bool ephemeral_users_enabled_value = false; 292 bool ephemeral_users_enabled_value = false;
288 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) { 293 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) {
289 ephemeral_users_enabled->set_ephemeral_users_enabled( 294 ephemeral_users_enabled->set_ephemeral_users_enabled(
290 ephemeral_users_enabled_value); 295 ephemeral_users_enabled_value);
291 } else { 296 } else {
292 NOTREACHED(); 297 NOTREACHED();
293 } 298 }
294 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) { 299 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) {
295 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers = 300 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers =
296 device_settings_.mutable_allow_redeem_offers(); 301 device_settings_.mutable_allow_redeem_offers();
297 bool allow_redeem_offers_value = true; 302 bool allow_redeem_offers_value = true;
298 if (value->GetAsBoolean(&allow_redeem_offers_value)) { 303 if (value->GetAsBoolean(&allow_redeem_offers_value)) {
299 allow_redeem_offers->set_allow_redeem_offers( 304 allow_redeem_offers->set_allow_redeem_offers(
300 allow_redeem_offers_value); 305 allow_redeem_offers_value);
301 } else { 306 } else {
302 NOTREACHED(); 307 NOTREACHED();
303 } 308 }
309 } else if (prop == kStartUpFlags) {
310 em::StartUpFlagsProto* flags_proto =
311 device_settings_.mutable_start_up_flags();
312 flags_proto->Clear();
313 const base::ListValue* flags;
314 if (value->GetAsList(&flags)) {
315 for (base::ListValue::const_iterator i = flags->begin();
316 i != flags->end(); ++i) {
317 std::string flag;
318 if ((*i)->GetAsString(&flag))
319 flags_proto->add_flags(flag);
320 }
321 }
304 } else { 322 } else {
305 // The remaining settings don't support Set(), since they are not 323 // The remaining settings don't support Set(), since they are not
306 // intended to be customizable by the user: 324 // intended to be customizable by the user:
307 // kAppPack 325 // kAppPack
308 // kDeviceOwner 326 // kDeviceOwner
309 // kIdleLogoutTimeout 327 // kIdleLogoutTimeout
310 // kIdleLogoutWarningDuration 328 // kIdleLogoutWarningDuration
311 // kReleaseChannelDelegated 329 // kReleaseChannelDelegated
312 // kReportDeviceVersionInfo 330 // kReportDeviceVersionInfo
313 // kReportDeviceActivityTimes 331 // kReportDeviceActivityTimes
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { 417 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) {
400 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = 418 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts =
401 policy.device_local_accounts().account(); 419 policy.device_local_accounts().account();
402 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; 420 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry;
403 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { 421 for (entry = accounts.begin(); entry != accounts.end(); ++entry) {
404 if (entry->has_id()) 422 if (entry->has_id())
405 account_list->AppendString(entry->id()); 423 account_list->AppendString(entry->id());
406 } 424 }
407 } 425 }
408 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list); 426 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list);
427
428 if (policy.has_start_up_flags()) {
429 base::ListValue* list = new base::ListValue();
430 const em::StartUpFlagsProto& flags_proto = policy.start_up_flags();
431 const RepeatedPtrField<std::string>& flags = flags_proto.flags();
432 for (RepeatedPtrField<std::string>::const_iterator it = flags.begin();
433 it != flags.end(); ++it) {
434 list->Append(new base::StringValue(*it));
435 }
436 new_values_cache->SetValue(kStartUpFlags, list);
437 }
409 } 438 }
410 439
411 void DeviceSettingsProvider::DecodeKioskPolicies( 440 void DeviceSettingsProvider::DecodeKioskPolicies(
412 const em::ChromeDeviceSettingsProto& policy, 441 const em::ChromeDeviceSettingsProto& policy,
413 PrefValueMap* new_values_cache) const { 442 PrefValueMap* new_values_cache) const {
414 if (policy.has_forced_logout_timeouts()) { 443 if (policy.has_forced_logout_timeouts()) {
415 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) { 444 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) {
416 new_values_cache->SetInteger( 445 new_values_cache->SetInteger(
417 kIdleLogoutTimeout, 446 kIdleLogoutTimeout,
418 policy.forced_logout_timeouts().idle_logout_timeout()); 447 policy.forced_logout_timeouts().idle_logout_timeout());
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 trusted_status_ = trusted_status; 626 trusted_status_ = trusted_status;
598 for (size_t i = 0; i < notifications.size(); ++i) 627 for (size_t i = 0; i < notifications.size(); ++i)
599 NotifyObservers(notifications[i]); 628 NotifyObservers(notifications[i]);
600 } 629 }
601 630
602 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file, 631 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file,
603 bool new_value) { 632 bool new_value) {
604 // TODO(pastarmovj): Remove this once migration is not needed anymore. 633 // 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. 634 // If the value is not set we should try to migrate legacy consent file.
606 if (use_file) { 635 if (use_file) {
636 UMA_HISTOGRAM_COUNTS("DeviceSettings.MetricsMigrated", 1);
607 new_value = HasOldMetricsFile(); 637 new_value = HasOldMetricsFile();
608 // Make sure the values will get eventually written to the policy file. 638 // Make sure the values will get eventually written to the policy file.
609 migration_values_.SetValue(kStatsReportingPref, 639 migration_values_.SetValue(kStatsReportingPref,
610 base::Value::CreateBooleanValue(new_value)); 640 base::Value::CreateBooleanValue(new_value));
611 AttemptMigration(); 641 AttemptMigration();
612 LOG(INFO) << "No metrics policy set will revert to checking " 642 LOG(INFO) << "No metrics policy set will revert to checking "
613 << "consent file which is " 643 << "consent file which is "
614 << (new_value ? "on." : "off."); 644 << (new_value ? "on." : "off.");
615 } 645 }
616 VLOG(1) << "Metrics policy is being set to : " << new_value 646 VLOG(1) << "Metrics policy is being set to : " << new_value
(...skipping 19 matching lines...) Expand all
636 } 666 }
637 667
638 void DeviceSettingsProvider::ApplySideEffects( 668 void DeviceSettingsProvider::ApplySideEffects(
639 const em::ChromeDeviceSettingsProto& settings) { 669 const em::ChromeDeviceSettingsProto& settings) {
640 // First migrate metrics settings as needed. 670 // First migrate metrics settings as needed.
641 if (settings.has_metrics_enabled()) 671 if (settings.has_metrics_enabled())
642 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled()); 672 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled());
643 else 673 else
644 ApplyMetricsSetting(true, false); 674 ApplyMetricsSetting(true, false);
645 675
676 // TODO(pastarmovj): Remove this after we don't need it anymore.
677 // See: http://crosbug.com/39553
678 // Migrate flags to device settings.
679 PrefService* local_state = g_browser_process->local_state();
680 if (local_state->HasPrefPath(prefs::kEnabledLabsExperiments)) {
681 if (!settings.has_start_up_flags()) {
682 const base::ListValue* flags =
683 local_state->GetList(prefs::kEnabledLabsExperiments);
684 migration_values_.SetValue(kStartUpFlags, flags->DeepCopy());
685 AttemptMigration();
686 } else {
687 // Either it has been properly migrated or the user already specified new
688 // flags in the device policy.
689 UMA_HISTOGRAM_COUNTS("DeviceSettings.FlagsMigrated", 1);
690 local_state->ClearPref(prefs::kEnabledLabsExperiments);
691 }
692 }
693
646 // Next set the roaming setting as needed. 694 // Next set the roaming setting as needed.
647 ApplyRoamingSetting( 695 ApplyRoamingSetting(
648 settings.has_data_roaming_enabled() ? 696 settings.has_data_roaming_enabled() ?
649 settings.data_roaming_enabled().data_roaming_enabled() : 697 settings.data_roaming_enabled().data_roaming_enabled() :
650 false); 698 false);
651 } 699 }
652 700
653 bool DeviceSettingsProvider::MitigateMissingPolicy() { 701 bool DeviceSettingsProvider::MitigateMissingPolicy() {
654 // First check if the device has been owned already and if not exit 702 // First check if the device has been owned already and if not exit
655 // immediately. 703 // immediately.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 void DeviceSettingsProvider::AttemptMigration() { 842 void DeviceSettingsProvider::AttemptMigration() {
795 if (device_settings_service_->HasPrivateOwnerKey()) { 843 if (device_settings_service_->HasPrivateOwnerKey()) {
796 PrefValueMap::const_iterator i; 844 PrefValueMap::const_iterator i;
797 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) 845 for (i = migration_values_.begin(); i != migration_values_.end(); ++i)
798 DoSet(i->first, *i->second); 846 DoSet(i->first, *i->second);
799 migration_values_.Clear(); 847 migration_values_.Clear();
800 } 848 }
801 } 849 }
802 850
803 } // namespace chromeos 851 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/cros_settings_names.cc ('k') | chrome/browser/policy/device_policy_decoder_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698