Commit d965119e authored by Aga Wronska's avatar Aga Wronska Committed by Commit Bot

Clear information about profile policy requirements

Clear information about profile policy requirements from known user
database when account type is changed. It will enforce establishing
the information again and fix problems resulting from incorrect
information being cached.

It fixes problem when policy is not fetched for account that changed
type to child when DMServerOAuthForChildUser is turned on.

Bug: 951238
Test: Manually changing account type and regular child user sign in
Change-Id: Iaab25af95d7f4dd818001aae1e2acab7cd0135e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1558901Reviewed-by: default avatarDrew Wilson <atwilson@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Commit-Queue: Aga Wronska <agawronska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649675}
parent 80c9cda9
...@@ -143,6 +143,19 @@ void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) { ...@@ -143,6 +143,19 @@ void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) {
AccountId::AccountTypeToString(account_id.GetAccountType())); AccountId::AccountTypeToString(account_id.GetAccountType()));
} }
void ClearPref(const AccountId& account_id, const std::string& path) {
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);
}
} // namespace } // namespace
bool FindPrefs(const AccountId& account_id, bool FindPrefs(const AccountId& account_id,
...@@ -285,16 +298,7 @@ void RemovePref(const AccountId& account_id, const std::string& path) { ...@@ -285,16 +298,7 @@ void RemovePref(const AccountId& account_id, const std::string& path) {
for (const std::string& key : kReservedKeys) for (const std::string& key : kReservedKeys)
CHECK_NE(path, key); CHECK_NE(path, key);
const base::DictionaryValue* user_pref_dict = nullptr; ClearPref(account_id, path);
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,
...@@ -531,6 +535,10 @@ ProfileRequiresPolicy GetProfileRequiresPolicy(const AccountId& account_id) { ...@@ -531,6 +535,10 @@ ProfileRequiresPolicy GetProfileRequiresPolicy(const AccountId& account_id) {
return ProfileRequiresPolicy::kUnknown; return ProfileRequiresPolicy::kUnknown;
} }
void ClearProfileRequiresPolicy(const AccountId& account_id) {
ClearPref(account_id, kProfileRequiresPolicy);
}
void UpdateReauthReason(const AccountId& account_id, const int reauth_reason) { void UpdateReauthReason(const AccountId& account_id, const int reauth_reason) {
SetIntegerPref(account_id, kReauthReasonKey, reauth_reason); SetIntegerPref(account_id, kReauthReasonKey, reauth_reason);
} }
......
...@@ -172,6 +172,10 @@ void USER_MANAGER_EXPORT ...@@ -172,6 +172,10 @@ void USER_MANAGER_EXPORT
SetProfileRequiresPolicy(const AccountId& account_id, SetProfileRequiresPolicy(const AccountId& account_id,
ProfileRequiresPolicy policy_required); ProfileRequiresPolicy policy_required);
// Clears information whether profile requires policy.
void USER_MANAGER_EXPORT
ClearProfileRequiresPolicy(const AccountId& account_id);
// Saves why the user has to go through re-auth flow. // Saves why the user has to go through re-auth flow.
void USER_MANAGER_EXPORT UpdateReauthReason(const AccountId& account_id, void USER_MANAGER_EXPORT UpdateReauthReason(const AccountId& account_id,
const int reauth_reason); const int reauth_reason);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/user_manager/known_user.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "google_apis/gaia/gaia_auth_util.h" #include "google_apis/gaia/gaia_auth_util.h"
...@@ -382,6 +383,11 @@ void RegularUser::UpdateType(UserType user_type) { ...@@ -382,6 +383,11 @@ void RegularUser::UpdateType(UserType user_type) {
return; return;
const bool old_is_child = is_child_; const bool old_is_child = is_child_;
is_child_ = user_type == user_manager::USER_TYPE_CHILD; is_child_ = user_type == user_manager::USER_TYPE_CHILD;
// Clear information about profile policy requirements to enforce setting it
// again for the new account type.
user_manager::known_user::ClearProfileRequiresPolicy(GetAccountId());
LOG(WARNING) << "User type has changed: " << current_type LOG(WARNING) << "User type has changed: " << current_type
<< " (is_child=" << old_is_child << ") => " << user_type << " (is_child=" << old_is_child << ") => " << user_type
<< " (is_child=" << is_child_ << ")"; << " (is_child=" << is_child_ << ")";
......
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