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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/settings/device_settings_provider.cc
diff --git a/chrome/browser/chromeos/settings/device_settings_provider.cc b/chrome/browser/chromeos/settings/device_settings_provider.cc
index 44a253483f2d3526fcd75a3ebf92865684ebd655..e150055854177d46198b822819e80f7df07a92b5 100644
--- a/chrome/browser/chromeos/settings/device_settings_provider.cc
+++ b/chrome/browser/chromeos/settings/device_settings_provider.cc
@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
#include "base/string_util.h"
#include "base/threading/thread_restrictions.h"
@@ -26,6 +27,7 @@
#include "chrome/browser/policy/proto/device_management_backend.pb.h"
#include "chrome/browser/ui/options/options_util.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
#include "chrome/installer/util/google_update_settings.h"
using google::protobuf::RepeatedPtrField;
@@ -63,6 +65,7 @@ const char* kKnownSettings[] = {
kStartUpUrls,
kStatsReportingPref,
kSystemTimezonePolicy,
+ kStartUpFlags,
};
// Legacy policy file location. Used to detect migration from pre v12 ChromeOS.
@@ -274,12 +277,14 @@ void DeviceSettingsProvider::SetInPolicy() {
em::UserWhitelistProto* whitelist_proto =
device_settings_.mutable_user_whitelist();
whitelist_proto->clear_user_whitelist();
- base::ListValue& users = static_cast<base::ListValue&>(*value);
- for (base::ListValue::const_iterator i = users.begin();
- i != users.end(); ++i) {
- std::string email;
- if ((*i)->GetAsString(&email))
- whitelist_proto->add_user_whitelist(email.c_str());
+ const base::ListValue* users;
+ if (value->GetAsList(&users)) {
+ for (base::ListValue::const_iterator i = users->begin();
+ i != users->end(); ++i) {
+ std::string email;
+ if ((*i)->GetAsString(&email))
+ whitelist_proto->add_user_whitelist(email);
+ }
}
} else if (prop == kAccountsPrefEphemeralUsersEnabled) {
em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
@@ -301,6 +306,19 @@ void DeviceSettingsProvider::SetInPolicy() {
} else {
NOTREACHED();
}
+ } else if (prop == kStartUpFlags) {
+ em::StartUpFlagsProto* flags_proto =
+ device_settings_.mutable_start_up_flags();
+ flags_proto->Clear();
+ const base::ListValue* flags;
+ if (value->GetAsList(&flags)) {
+ for (base::ListValue::const_iterator i = flags->begin();
+ i != flags->end(); ++i) {
+ std::string flag;
+ if ((*i)->GetAsString(&flag))
+ flags_proto->add_flags(flag);
+ }
+ }
} else {
// The remaining settings don't support Set(), since they are not
// intended to be customizable by the user:
@@ -406,6 +424,17 @@ void DeviceSettingsProvider::DecodeLoginPolicies(
}
}
new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list);
+
+ if (policy.has_start_up_flags()) {
+ base::ListValue* list = new base::ListValue();
+ const em::StartUpFlagsProto& flags_proto = policy.start_up_flags();
+ const RepeatedPtrField<std::string>& flags = flags_proto.flags();
+ for (RepeatedPtrField<std::string>::const_iterator it = flags.begin();
+ it != flags.end(); ++it) {
+ list->Append(new base::StringValue(*it));
+ }
+ new_values_cache->SetValue(kStartUpFlags, list);
+ }
}
void DeviceSettingsProvider::DecodeKioskPolicies(
@@ -604,6 +633,7 @@ void DeviceSettingsProvider::ApplyMetricsSetting(bool use_file,
// TODO(pastarmovj): Remove this once migration is not needed anymore.
// If the value is not set we should try to migrate legacy consent file.
if (use_file) {
+ UMA_HISTOGRAM_COUNTS("DeviceSettings.MetricsMigrated", 1);
new_value = HasOldMetricsFile();
// Make sure the values will get eventually written to the policy file.
migration_values_.SetValue(kStatsReportingPref,
@@ -643,6 +673,24 @@ void DeviceSettingsProvider::ApplySideEffects(
else
ApplyMetricsSetting(true, false);
+ // TODO(pastarmovj): Remove this after we don't need it anymore.
+ // See: http://crosbug.com/39553
+ // Migrate flags to device settings.
+ PrefService* local_state = g_browser_process->local_state();
+ if (local_state->HasPrefPath(prefs::kEnabledLabsExperiments)) {
+ if (!settings.has_start_up_flags()) {
+ const base::ListValue* flags =
+ local_state->GetList(prefs::kEnabledLabsExperiments);
+ migration_values_.SetValue(kStartUpFlags, flags->DeepCopy());
+ AttemptMigration();
+ } else {
+ // Either it has been properly migrated or the user already specified new
+ // flags in the device policy.
+ UMA_HISTOGRAM_COUNTS("DeviceSettings.FlagsMigrated", 1);
+ local_state->ClearPref(prefs::kEnabledLabsExperiments);
+ }
+ }
+
// Next set the roaming setting as needed.
ApplyRoamingSetting(
settings.has_data_roaming_enabled() ?
« 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