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

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

Issue 12728008: Revert 186837 "Move pref backing up flags from local state to de..." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
14 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
15 #include "base/string_util.h" 14 #include "base/string_util.h"
16 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
17 #include "base/values.h" 16 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 18 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/cros/network_library.h" 19 #include "chrome/browser/chromeos/cros/network_library.h"
21 #include "chrome/browser/chromeos/settings/cros_settings.h" 20 #include "chrome/browser/chromeos/settings/cros_settings.h"
22 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 21 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
23 #include "chrome/browser/chromeos/settings/device_settings_cache.h" 22 #include "chrome/browser/chromeos/settings/device_settings_cache.h"
24 #include "chrome/browser/policy/app_pack_updater.h" 23 #include "chrome/browser/policy/app_pack_updater.h"
25 #include "chrome/browser/policy/browser_policy_connector.h" 24 #include "chrome/browser/policy/browser_policy_connector.h"
26 #include "chrome/browser/policy/cloud_policy_constants.h" 25 #include "chrome/browser/policy/cloud_policy_constants.h"
27 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 26 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
28 #include "chrome/browser/ui/options/options_util.h" 27 #include "chrome/browser/ui/options/options_util.h"
29 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h"
31 #include "chrome/installer/util/google_update_settings.h" 29 #include "chrome/installer/util/google_update_settings.h"
32 30
33 using google::protobuf::RepeatedPtrField; 31 using google::protobuf::RepeatedPtrField;
34 32
35 namespace em = enterprise_management; 33 namespace em = enterprise_management;
36 34
37 namespace chromeos { 35 namespace chromeos {
38 36
39 namespace { 37 namespace {
40 38
(...skipping 17 matching lines...) Expand all
58 kReportDeviceBootMode, 56 kReportDeviceBootMode,
59 kReportDeviceLocation, 57 kReportDeviceLocation,
60 kReportDeviceVersionInfo, 58 kReportDeviceVersionInfo,
61 kScreenSaverExtensionId, 59 kScreenSaverExtensionId,
62 kScreenSaverTimeout, 60 kScreenSaverTimeout,
63 kSettingProxyEverywhere, 61 kSettingProxyEverywhere,
64 kSignedDataRoamingEnabled, 62 kSignedDataRoamingEnabled,
65 kStartUpUrls, 63 kStartUpUrls,
66 kStatsReportingPref, 64 kStatsReportingPref,
67 kSystemTimezonePolicy, 65 kSystemTimezonePolicy,
68 kStartUpFlags,
69 }; 66 };
70 67
71 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS. 68 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS.
72 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences"; 69 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences";
73 70
74 bool HasOldMetricsFile() { 71 bool HasOldMetricsFile() {
75 // TODO(pastarmovj): Remove this once migration is not needed anymore. 72 // TODO(pastarmovj): Remove this once migration is not needed anymore.
76 // If the value is not set we should try to migrate legacy consent file. 73 // If the value is not set we should try to migrate legacy consent file.
77 // Loading consent file state causes us to do blocking IO on UI thread. 74 // Loading consent file state causes us to do blocking IO on UI thread.
78 // Temporarily allow it until we fix http://crbug.com/62626 75 // Temporarily allow it until we fix http://crbug.com/62626
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 bool metrics_value = false; 267 bool metrics_value = false;
271 if (value->GetAsBoolean(&metrics_value)) 268 if (value->GetAsBoolean(&metrics_value))
272 metrics->set_metrics_enabled(metrics_value); 269 metrics->set_metrics_enabled(metrics_value);
273 else 270 else
274 NOTREACHED(); 271 NOTREACHED();
275 ApplyMetricsSetting(false, metrics_value); 272 ApplyMetricsSetting(false, metrics_value);
276 } else if (prop == kAccountsPrefUsers) { 273 } else if (prop == kAccountsPrefUsers) {
277 em::UserWhitelistProto* whitelist_proto = 274 em::UserWhitelistProto* whitelist_proto =
278 device_settings_.mutable_user_whitelist(); 275 device_settings_.mutable_user_whitelist();
279 whitelist_proto->clear_user_whitelist(); 276 whitelist_proto->clear_user_whitelist();
280 const base::ListValue* users; 277 base::ListValue& users = static_cast<base::ListValue&>(*value);
281 if (value->GetAsList(&users)) { 278 for (base::ListValue::const_iterator i = users.begin();
282 for (base::ListValue::const_iterator i = users->begin(); 279 i != users.end(); ++i) {
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);
287 }
288 } 283 }
289 } else if (prop == kAccountsPrefEphemeralUsersEnabled) { 284 } else if (prop == kAccountsPrefEphemeralUsersEnabled) {
290 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = 285 em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
291 device_settings_.mutable_ephemeral_users_enabled(); 286 device_settings_.mutable_ephemeral_users_enabled();
292 bool ephemeral_users_enabled_value = false; 287 bool ephemeral_users_enabled_value = false;
293 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) { 288 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) {
294 ephemeral_users_enabled->set_ephemeral_users_enabled( 289 ephemeral_users_enabled->set_ephemeral_users_enabled(
295 ephemeral_users_enabled_value); 290 ephemeral_users_enabled_value);
296 } else { 291 } else {
297 NOTREACHED(); 292 NOTREACHED();
298 } 293 }
299 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) { 294 } else if (prop == kAllowRedeemChromeOsRegistrationOffers) {
300 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers = 295 em::AllowRedeemChromeOsRegistrationOffersProto* allow_redeem_offers =
301 device_settings_.mutable_allow_redeem_offers(); 296 device_settings_.mutable_allow_redeem_offers();
302 bool allow_redeem_offers_value = true; 297 bool allow_redeem_offers_value = true;
303 if (value->GetAsBoolean(&allow_redeem_offers_value)) { 298 if (value->GetAsBoolean(&allow_redeem_offers_value)) {
304 allow_redeem_offers->set_allow_redeem_offers( 299 allow_redeem_offers->set_allow_redeem_offers(
305 allow_redeem_offers_value); 300 allow_redeem_offers_value);
306 } else { 301 } else {
307 NOTREACHED(); 302 NOTREACHED();
308 } 303 }
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 }
322 } else { 304 } else {
323 // The remaining settings don't support Set(), since they are not 305 // The remaining settings don't support Set(), since they are not
324 // intended to be customizable by the user: 306 // intended to be customizable by the user:
325 // kAppPack 307 // kAppPack
326 // kDeviceOwner 308 // kDeviceOwner
327 // kIdleLogoutTimeout 309 // kIdleLogoutTimeout
328 // kIdleLogoutWarningDuration 310 // kIdleLogoutWarningDuration
329 // kReleaseChannelDelegated 311 // kReleaseChannelDelegated
330 // kReportDeviceVersionInfo 312 // kReportDeviceVersionInfo
331 // kReportDeviceActivityTimes 313 // kReportDeviceActivityTimes
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { 399 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) {
418 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = 400 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts =
419 policy.device_local_accounts().account(); 401 policy.device_local_accounts().account();
420 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; 402 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry;
421 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { 403 for (entry = accounts.begin(); entry != accounts.end(); ++entry) {
422 if (entry->has_id()) 404 if (entry->has_id())
423 account_list->AppendString(entry->id()); 405 account_list->AppendString(entry->id());
424 } 406 }
425 } 407 }
426 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list); 408 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 }
438 } 409 }
439 410
440 void DeviceSettingsProvider::DecodeKioskPolicies( 411 void DeviceSettingsProvider::DecodeKioskPolicies(
441 const em::ChromeDeviceSettingsProto& policy, 412 const em::ChromeDeviceSettingsProto& policy,
442 PrefValueMap* new_values_cache) const { 413 PrefValueMap* new_values_cache) const {
443 if (policy.has_forced_logout_timeouts()) { 414 if (policy.has_forced_logout_timeouts()) {
444 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) { 415 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) {
445 new_values_cache->SetInteger( 416 new_values_cache->SetInteger(
446 kIdleLogoutTimeout, 417 kIdleLogoutTimeout,
447 policy.forced_logout_timeouts().idle_logout_timeout()); 418 policy.forced_logout_timeouts().idle_logout_timeout());
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 trusted_status_ = trusted_status; 597 trusted_status_ = trusted_status;
627 for (size_t i = 0; i < notifications.size(); ++i) 598 for (size_t i = 0; i < notifications.size(); ++i)
628 NotifyObservers(notifications[i]); 599 NotifyObservers(notifications[i]);
629 } 600 }
630 601
631 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file, 602 void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file,
632 bool new_value) { 603 bool new_value) {
633 // TODO(pastarmovj): Remove this once migration is not needed anymore. 604 // TODO(pastarmovj): Remove this once migration is not needed anymore.
634 // If the value is not set we should try to migrate legacy consent file. 605 // If the value is not set we should try to migrate legacy consent file.
635 if (use_file) { 606 if (use_file) {
636 UMA_HISTOGRAM_COUNTS("DeviceSettings.MetricsMigrated", 1);
637 new_value = HasOldMetricsFile(); 607 new_value = HasOldMetricsFile();
638 // Make sure the values will get eventually written to the policy file. 608 // Make sure the values will get eventually written to the policy file.
639 migration_values_.SetValue(kStatsReportingPref, 609 migration_values_.SetValue(kStatsReportingPref,
640 base::Value::CreateBooleanValue(new_value)); 610 base::Value::CreateBooleanValue(new_value));
641 AttemptMigration(); 611 AttemptMigration();
642 LOG(INFO) << "No metrics policy set will revert to checking " 612 LOG(INFO) << "No metrics policy set will revert to checking "
643 << "consent file which is " 613 << "consent file which is "
644 << (new_value ? "on." : "off."); 614 << (new_value ? "on." : "off.");
645 } 615 }
646 VLOG(1) << "Metrics policy is being set to : " << new_value 616 VLOG(1) << "Metrics policy is being set to : " << new_value
(...skipping 19 matching lines...) Expand all
666 } 636 }
667 637
668 void DeviceSettingsProvider::ApplySideEffects( 638 void DeviceSettingsProvider::ApplySideEffects(
669 const em::ChromeDeviceSettingsProto& settings) { 639 const em::ChromeDeviceSettingsProto& settings) {
670 // First migrate metrics settings as needed. 640 // First migrate metrics settings as needed.
671 if (settings.has_metrics_enabled()) 641 if (settings.has_metrics_enabled())
672 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled()); 642 ApplyMetricsSetting(false, settings.metrics_enabled().metrics_enabled());
673 else 643 else
674 ApplyMetricsSetting(true, false); 644 ApplyMetricsSetting(true, false);
675 645
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
694 // Next set the roaming setting as needed. 646 // Next set the roaming setting as needed.
695 ApplyRoamingSetting( 647 ApplyRoamingSetting(
696 settings.has_data_roaming_enabled() ? 648 settings.has_data_roaming_enabled() ?
697 settings.data_roaming_enabled().data_roaming_enabled() : 649 settings.data_roaming_enabled().data_roaming_enabled() :
698 false); 650 false);
699 } 651 }
700 652
701 bool DeviceSettingsProvider::MitigateMissingPolicy() { 653 bool DeviceSettingsProvider::MitigateMissingPolicy() {
702 // First check if the device has been owned already and if not exit 654 // First check if the device has been owned already and if not exit
703 // immediately. 655 // immediately.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 void DeviceSettingsProvider::AttemptMigration() { 794 void DeviceSettingsProvider::AttemptMigration() {
843 if (device_settings_service_->HasPrivateOwnerKey()) { 795 if (device_settings_service_->HasPrivateOwnerKey()) {
844 PrefValueMap::const_iterator i; 796 PrefValueMap::const_iterator i;
845 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) 797 for (i = migration_values_.begin(); i != migration_values_.end(); ++i)
846 DoSet(i->first, *i->second); 798 DoSet(i->first, *i->second);
847 migration_values_.Clear(); 799 migration_values_.Clear();
848 } 800 }
849 } 801 }
850 802
851 } // namespace chromeos 803 } // 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