Commit 07dca140 authored by Henrique Grandinetti's avatar Henrique Grandinetti Committed by Commit Bot

Sync Parent Access Code config to known user storage.

Bug: 946802
Change-Id: I2154c3499924af299a9a52bad52b86abe473ec75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1542154
Commit-Queue: Henrique Grandinetti <hgrandinetti@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#648320}
parent 157fe9aa
...@@ -595,6 +595,7 @@ void Preferences::InitUserPrefs(sync_preferences::PrefServiceSyncable* prefs) { ...@@ -595,6 +595,7 @@ void Preferences::InitUserPrefs(sync_preferences::PrefServiceSyncable* prefs) {
pref_change_registrar_.Add(prefs::kResolveTimezoneByGeolocationMethod, pref_change_registrar_.Add(prefs::kResolveTimezoneByGeolocationMethod,
callback); callback);
pref_change_registrar_.Add(prefs::kUse24HourClock, callback); pref_change_registrar_.Add(prefs::kUse24HourClock, callback);
pref_change_registrar_.Add(prefs::kParentAccessCodeConfig, callback);
for (auto* remap_pref : kLanguageRemapPrefs) for (auto* remap_pref : kLanguageRemapPrefs)
pref_change_registrar_.Add(remap_pref, callback); pref_change_registrar_.Add(remap_pref, callback);
} }
...@@ -950,6 +951,20 @@ void Preferences::ApplyPreferences(ApplyReason reason, ...@@ -950,6 +951,20 @@ void Preferences::ApplyPreferences(ApplyReason reason,
prefs::kUse24HourClock, value); prefs::kUse24HourClock, value);
} }
if (pref_name == prefs::kParentAccessCodeConfig ||
reason != REASON_PREF_CHANGED) {
const base::Value* value =
prefs_->GetDictionary(prefs::kParentAccessCodeConfig);
if (value && prefs_->IsManagedPreference(prefs::kParentAccessCodeConfig)) {
user_manager::known_user::SetPref(user_->GetAccountId(),
prefs::kKnownUserParentAccessCodeConfig,
value->Clone());
} else {
user_manager::known_user::RemovePref(
user_->GetAccountId(), prefs::kKnownUserParentAccessCodeConfig);
}
}
for (auto* remap_pref : kLanguageRemapPrefs) { for (auto* remap_pref : kLanguageRemapPrefs) {
if (pref_name == remap_pref || reason != REASON_ACTIVE_USER_CHANGED) { if (pref_name == remap_pref || reason != REASON_ACTIVE_USER_CHANGED) {
const int value = prefs_->GetInteger(remap_pref); const int value = prefs_->GetInteger(remap_pref);
......
...@@ -1977,6 +1977,12 @@ const char kAutoScreenBrightnessMetricsSupportedAlsUserAdjustmentCount[] = ...@@ -1977,6 +1977,12 @@ const char kAutoScreenBrightnessMetricsSupportedAlsUserAdjustmentCount[] =
"auto_screen_brightness.metrics.supported_als_user_adjustment_count"; "auto_screen_brightness.metrics.supported_als_user_adjustment_count";
const char kAutoScreenBrightnessMetricsUnsupportedAlsUserAdjustmentCount[] = const char kAutoScreenBrightnessMetricsUnsupportedAlsUserAdjustmentCount[] =
"auto_screen_brightness.metrics.unsupported_als_user_adjustment_count"; "auto_screen_brightness.metrics.unsupported_als_user_adjustment_count";
// Dictionary pref containing the configuration used to verify Parent Access
// Code. The data is sent through the ParentAccessCodeConfig policy, which is
// set for child users only, and kept on the known user storage.
const char kKnownUserParentAccessCodeConfig[] =
"child_user.parent_access_code.config";
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
// Whether there is a Flash version installed that supports clearing LSO data. // Whether there is a Flash version installed that supports clearing LSO data.
......
...@@ -655,6 +655,7 @@ extern const char kAutoScreenBrightnessMetricsNoAlsUserAdjustmentCount[]; ...@@ -655,6 +655,7 @@ extern const char kAutoScreenBrightnessMetricsNoAlsUserAdjustmentCount[];
extern const char kAutoScreenBrightnessMetricsSupportedAlsUserAdjustmentCount[]; extern const char kAutoScreenBrightnessMetricsSupportedAlsUserAdjustmentCount[];
extern const char extern const char
kAutoScreenBrightnessMetricsUnsupportedAlsUserAdjustmentCount[]; kAutoScreenBrightnessMetricsUnsupportedAlsUserAdjustmentCount[];
extern const char kKnownUserParentAccessCodeConfig[];
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
extern const char kClearPluginLSODataEnabled[]; extern const char kClearPluginLSODataEnabled[];
......
...@@ -25,7 +25,8 @@ namespace { ...@@ -25,7 +25,8 @@ namespace {
// placed in this list. // placed in this list.
const char kKnownUsers[] = "KnownUsers"; const char kKnownUsers[] = "KnownUsers";
// Known user preferences keys (stored in Local State). // Known user preferences keys (stored in Local State). All keys should be
// listed in kReservedKeys below.
// Key of canonical e-mail value. // Key of canonical e-mail value.
const char kCanonicalEmail[] = "email"; const char kCanonicalEmail[] = "email";
...@@ -65,6 +66,20 @@ const char kProfileRequiresPolicy[] = "profile_requires_policy"; ...@@ -65,6 +66,20 @@ const char kProfileRequiresPolicy[] = "profile_requires_policy";
// from the local state on logout. // from the local state on logout.
const char kIsEphemeral[] = "is_ephemeral"; const char kIsEphemeral[] = "is_ephemeral";
// List containing all the known user preferences keys.
const char* kReservedKeys[] = {kCanonicalEmail,
kGAIAIdKey,
kObjGuidKey,
kAccountTypeKey,
kUsingSAMLKey,
kDeviceId,
kGAPSCookie,
kReauthReasonKey,
kGaiaIdMigration,
kMinimalMigrationAttempted,
kProfileRequiresPolicy,
kIsEphemeral};
PrefService* GetLocalState() { PrefService* GetLocalState() {
if (!UserManager::IsInitialized()) if (!UserManager::IsInitialized())
return nullptr; return nullptr;
...@@ -206,13 +221,6 @@ bool GetStringPref(const AccountId& account_id, ...@@ -206,13 +221,6 @@ bool GetStringPref(const AccountId& account_id,
void SetStringPref(const AccountId& account_id, void SetStringPref(const AccountId& account_id,
const std::string& path, const std::string& path,
const std::string& in_value) { const std::string& in_value) {
PrefService* local_state = GetLocalState();
// Local State may not be initialized in tests.
if (!local_state)
return;
ListPrefUpdate update(local_state, kKnownUsers);
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetString(path, in_value); dict.SetString(path, in_value);
UpdatePrefs(account_id, dict, false); UpdatePrefs(account_id, dict, false);
...@@ -231,13 +239,6 @@ bool GetBooleanPref(const AccountId& account_id, ...@@ -231,13 +239,6 @@ bool GetBooleanPref(const AccountId& account_id,
void SetBooleanPref(const AccountId& account_id, void SetBooleanPref(const AccountId& account_id,
const std::string& path, const std::string& path,
const bool in_value) { const bool in_value) {
PrefService* local_state = GetLocalState();
// Local State may not be initialized in tests.
if (!local_state)
return;
ListPrefUpdate update(local_state, kKnownUsers);
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetBoolean(path, in_value); dict.SetBoolean(path, in_value);
UpdatePrefs(account_id, dict, false); UpdatePrefs(account_id, dict, false);
...@@ -255,18 +256,47 @@ bool GetIntegerPref(const AccountId& account_id, ...@@ -255,18 +256,47 @@ bool GetIntegerPref(const AccountId& account_id,
void SetIntegerPref(const AccountId& account_id, void SetIntegerPref(const AccountId& account_id,
const std::string& path, const std::string& path,
const int in_value) { const int in_value) {
PrefService* local_state = GetLocalState(); base::DictionaryValue dict;
dict.SetInteger(path, in_value);
UpdatePrefs(account_id, dict, false);
}
// Local State may not be initialized in tests. bool GetPref(const AccountId& account_id,
if (!local_state) const std::string& path,
return; const base::Value** out_value) {
const base::DictionaryValue* user_pref_dict = nullptr;
if (!FindPrefs(account_id, &user_pref_dict))
return false;
ListPrefUpdate update(local_state, kKnownUsers); *out_value = user_pref_dict->FindPath(path);
return *out_value != nullptr;
}
void SetPref(const AccountId& account_id,
const std::string& path,
base::Value in_value) {
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetInteger(path, in_value); dict.SetPath(path, std::move(in_value));
UpdatePrefs(account_id, dict, false); UpdatePrefs(account_id, dict, false);
} }
void RemovePref(const AccountId& account_id, const std::string& path) {
// Prevent removing keys that are used internally.
for (const std::string& key : kReservedKeys)
CHECK_NE(path, key);
const base::DictionaryValue* user_pref_dict = nullptr;
if (!FindPrefs(account_id, &user_pref_dict))
return;
base::Value updated_user_pref = user_pref_dict->Clone();
base::DictionaryValue* updated_user_pref_dict;
updated_user_pref.GetAsDictionary(&updated_user_pref_dict);
updated_user_pref_dict->RemovePath(path);
UpdatePrefs(account_id, *updated_user_pref_dict, true);
}
AccountId GetAccountId(const std::string& user_email, AccountId GetAccountId(const std::string& user_email,
const std::string& id, const std::string& id,
const AccountType& account_type) { const AccountType& account_type) {
......
...@@ -16,6 +16,7 @@ class PrefRegistrySimple; ...@@ -16,6 +16,7 @@ class PrefRegistrySimple;
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
class Value;
} }
namespace user_manager { namespace user_manager {
...@@ -68,6 +69,21 @@ void USER_MANAGER_EXPORT SetIntegerPref(const AccountId& account_id, ...@@ -68,6 +69,21 @@ void USER_MANAGER_EXPORT SetIntegerPref(const AccountId& account_id,
const std::string& path, const std::string& path,
const int in_value); const int in_value);
// Returns true if |account_id| preference by |path| does exist,
// fills in |out_value|. Otherwise returns false.
bool USER_MANAGER_EXPORT GetPref(const AccountId& account_id,
const std::string& path,
const base::Value** out_value);
// Updates user's identified by |account_id| value preference |path|.
void USER_MANAGER_EXPORT SetPref(const AccountId& account_id,
const std::string& path,
base::Value in_value);
// Removes user's identified by |account_id| preference |path|.
void USER_MANAGER_EXPORT RemovePref(const AccountId& account_id,
const std::string& path);
// Returns the list of known AccountIds. // Returns the list of known AccountIds.
std::vector<AccountId> USER_MANAGER_EXPORT GetKnownAccountIds(); std::vector<AccountId> USER_MANAGER_EXPORT GetKnownAccountIds();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment