Commit d82d88e8 authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[ProfileInfoCache]: Remove SetAuthInfoOfProfileAtIndex & GetUserNameOfProfileAtIndex.

As part of the ProfileInfoInterface deprecation, we remove
|SetAuthInfoOfProfileAtIndex| and |GetUserNameOfProfileAtIndex|.
Afterwards, setting the auth info and getting the username should be
done through |ProfileAttributesEntry::SetAuthInfo| and
|ProfileAttributesEntry::GetUserName|.

Change-Id: I2ccfc2260127546984f7ed4aa058b5f0cd28e9fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1892773Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Monica Basta <msalama@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711204}
parent 05787070
......@@ -51,6 +51,7 @@ const char ProfileAttributesEntry::kAvatarIconKey[] = "avatar_icon";
const char ProfileAttributesEntry::kBackgroundAppsKey[] = "background_apps";
const char ProfileAttributesEntry::kProfileIsEphemeral[] = "is_ephemeral";
const char ProfileAttributesEntry::kUserNameKey[] = "user_name";
const char ProfileAttributesEntry::kGAIAIdKey[] = "gaia_id";
const char ProfileAttributesEntry::kIsConsentedPrimaryAccountKey[] =
"is_consented_primary_account";
......@@ -490,8 +491,23 @@ void ProfileAttributesEntry::SetAvatarIconIndex(size_t icon_index) {
void ProfileAttributesEntry::SetAuthInfo(const std::string& gaia_id,
const base::string16& user_name,
bool is_consented_primary_account) {
profile_info_cache_->SetAuthInfoOfProfileAtIndex(
profile_index(), gaia_id, user_name, is_consented_primary_account);
// If gaia_id, username and consent state are unchanged, abort early.
if (GetBool(kIsConsentedPrimaryAccountKey) == is_consented_primary_account &&
gaia_id == GetGAIAId() && user_name == GetUserName()) {
return;
}
const base::Value* old_data = GetEntryData();
base::Value new_data = old_data ? GetEntryData()->Clone()
: base::Value(base::Value::Type::DICTIONARY);
new_data.SetStringKey(kGAIAIdKey, gaia_id);
new_data.SetStringKey(kUserNameKey, user_name);
DCHECK(!is_consented_primary_account || !gaia_id.empty() ||
!user_name.empty());
new_data.SetBoolKey(kIsConsentedPrimaryAccountKey,
is_consented_primary_account);
SetEntryData(std::move(new_data));
profile_info_cache_->NotifyProfileAuthInfoChanged(profile_path_);
}
size_t ProfileAttributesEntry::profile_index() const {
......
......@@ -155,6 +155,7 @@ class ProfileAttributesEntry {
static const char kBackgroundAppsKey[];
static const char kProfileIsEphemeral[];
static const char kUserNameKey[];
static const char kGAIAIdKey[];
static const char kIsConsentedPrimaryAccountKey[];
private:
......
......@@ -40,7 +40,6 @@
namespace {
const char kGAIAIdKey[] = "gaia_id";
const char kIsUsingDefaultNameKey[] = "is_using_default_name";
const char kIsUsingDefaultAvatarKey[] = "is_using_default_avatar";
const char kUseGAIAPictureKey[] = "use_gaia_picture";
......@@ -153,7 +152,7 @@ void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path,
std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue);
info->SetString(kNameKey, name);
info->SetString(kGAIAIdKey, gaia_id);
info->SetString(ProfileAttributesEntry::kGAIAIdKey, gaia_id);
info->SetString(ProfileAttributesEntry::kUserNameKey, user_name);
DCHECK(!is_consented_primary_account || !gaia_id.empty() ||
!user_name.empty());
......@@ -273,14 +272,6 @@ base::FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const {
return user_data_dir_.AppendASCII(keys_[index]);
}
base::string16 ProfileInfoCache::GetUserNameOfProfileAtIndex(
size_t index) const {
base::string16 user_name;
GetInfoForProfileAtIndex(index)->GetString(
ProfileAttributesEntry::kUserNameKey, &user_name);
return user_name;
}
base::string16 ProfileInfoCache::GetGAIANameOfProfileAtIndex(
size_t index) const {
base::string16 name;
......@@ -298,7 +289,8 @@ base::string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex(
std::string ProfileInfoCache::GetGAIAIdOfProfileAtIndex(
size_t index) const {
std::string gaia_id;
GetInfoForProfileAtIndex(index)->GetString(kGAIAIdKey, &gaia_id);
GetInfoForProfileAtIndex(index)->GetString(ProfileAttributesEntry::kGAIAIdKey,
&gaia_id);
return gaia_id;
}
......@@ -412,36 +404,8 @@ void ProfileInfoCache::SetLocalProfileNameOfProfileAtIndex(
NotifyIfProfileNamesHaveChanged();
}
void ProfileInfoCache::SetAuthInfoOfProfileAtIndex(
size_t index,
const std::string& gaia_id,
const base::string16& user_name,
bool is_consented_primary_account) {
bool is_consented_primary_account_state;
GetInfoForProfileAtIndex(index)->GetBoolean(
ProfileAttributesEntry::kIsConsentedPrimaryAccountKey,
&is_consented_primary_account_state);
// If gaia_id, username and consent state are unchanged, abort early.
if (is_consented_primary_account_state == is_consented_primary_account &&
gaia_id == GetGAIAIdOfProfileAtIndex(index) &&
user_name == GetUserNameOfProfileAtIndex(index)) {
return;
}
std::unique_ptr<base::DictionaryValue> info(
GetInfoForProfileAtIndex(index)->DeepCopy());
info->SetString(kGAIAIdKey, gaia_id);
info->SetString(ProfileAttributesEntry::kUserNameKey, user_name);
DCHECK(!is_consented_primary_account || !gaia_id.empty() ||
!user_name.empty());
info->SetBoolean(ProfileAttributesEntry::kIsConsentedPrimaryAccountKey,
is_consented_primary_account);
SetInfoForProfileAtIndex(index, std::move(info));
base::FilePath profile_path = GetPathOfProfileAtIndex(index);
void ProfileInfoCache::NotifyProfileAuthInfoChanged(
const base::FilePath& profile_path) {
for (auto& observer : observer_list_)
observer.OnProfileAuthInfoChanged(profile_path);
}
......@@ -763,8 +727,8 @@ void ProfileInfoCache::RemoveProfileByAccountId(const AccountId& account_id) {
if ((account_id.HasAccountIdKey() &&
info->GetString(kAccountIdKey, &account_id_key) &&
account_id_key == account_id.GetAccountIdKey()) ||
(info->GetString(kGAIAIdKey, &gaia_id) && !gaia_id.empty() &&
account_id.GetGaiaId() == gaia_id) ||
(info->GetString(ProfileAttributesEntry::kGAIAIdKey, &gaia_id) &&
!gaia_id.empty() && account_id.GetGaiaId() == gaia_id) ||
(info->GetString(ProfileAttributesEntry::kUserNameKey, &user_name) &&
!user_name.empty() && account_id.GetUserEmail() == user_name)) {
RemoveProfile(GetPathOfProfileAtIndex(i));
......
......@@ -79,8 +79,6 @@ class ProfileInfoCache : public ProfileInfoInterface,
base::string16 GetNameOfProfileAtIndex(size_t index) const override;
// Will be removed SOON with ProfileInfoCache tests. Do not use!
base::FilePath GetPathOfProfileAtIndex(size_t index) const override;
// Will be removed SOON with ProfileInfoCache tests. Do not use!
base::string16 GetUserNameOfProfileAtIndex(size_t index) const override;
base::string16 GetGAIANameOfProfileAtIndex(size_t index) const override;
base::string16 GetGAIAGivenNameOfProfileAtIndex(size_t index) const override;
std::string GetGAIAIdOfProfileAtIndex(size_t index) const override;
......@@ -104,13 +102,8 @@ class ProfileInfoCache : public ProfileInfoInterface,
// Will be removed SOON with ProfileInfoCache tests. Do not use!
size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const;
// Warning: This will re-sort profiles and thus may change indices!
void SetLocalProfileNameOfProfileAtIndex(size_t index,
const base::string16& name);
void SetAuthInfoOfProfileAtIndex(size_t index,
const std::string& gaia_id,
const base::string16& user_name,
bool is_consented_primary_account);
// Will be removed SOON with ProfileInfoCache tests. Do not use!
void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index);
void SetIsOmittedProfileAtIndex(size_t index, bool is_omitted);
......@@ -152,6 +145,8 @@ class ProfileInfoCache : public ProfileInfoInterface,
bool GetProfileAttributesWithPath(const base::FilePath& path,
ProfileAttributesEntry** entry) override;
void NotifyProfileAuthInfoChanged(const base::FilePath& profile_path);
static const char kNameKey[];
static const char kGAIANameKey[];
static const char kGAIAGivenNameKey[];
......
......@@ -433,12 +433,19 @@ TEST_F(ProfileInfoCacheTest, DeleteProfile) {
}
TEST_F(ProfileInfoCacheTest, MutateProfile) {
GetCache()->AddProfileToCache(
GetProfilePath("path_1"), ASCIIToUTF16("name_1"), std::string(),
base::string16(), false, 0, std::string(), EmptyAccountId());
GetCache()->AddProfileToCache(
GetProfilePath("path_2"), ASCIIToUTF16("name_2"), std::string(),
base::string16(), false, 0, std::string(), EmptyAccountId());
base::FilePath profile_path_1 = GetProfilePath("path_1");
GetCache()->AddProfileToCache(profile_path_1, ASCIIToUTF16("name_1"),
std::string(), base::string16(), false, 0,
std::string(), EmptyAccountId());
base::FilePath profile_path_2 = GetProfilePath("path_2");
GetCache()->AddProfileToCache(profile_path_2, ASCIIToUTF16("name_2"),
std::string(), base::string16(), false, 0,
std::string(), EmptyAccountId());
ProfileAttributesEntry* entry1;
GetCache()->GetProfileAttributesWithPath(profile_path_1, &entry1);
ProfileAttributesEntry* entry2;
GetCache()->GetProfileAttributesWithPath(profile_path_2, &entry2);
base::string16 new_name = ASCIIToUTF16("new_name");
GetCache()->SetLocalProfileNameOfProfileAtIndex(1, new_name);
......@@ -447,10 +454,10 @@ TEST_F(ProfileInfoCacheTest, MutateProfile) {
base::string16 new_user_name = ASCIIToUTF16("user_name");
std::string new_gaia_id = "12345";
GetCache()->SetAuthInfoOfProfileAtIndex(1, new_gaia_id, new_user_name, true);
EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1));
entry2->SetAuthInfo(new_gaia_id, new_user_name, true);
EXPECT_EQ(new_user_name, entry2->GetUserName());
EXPECT_EQ(new_gaia_id, GetCache()->GetGAIAIdOfProfileAtIndex(1));
EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0));
EXPECT_NE(new_user_name, entry1->GetUserName());
// Avatar icons not used on Android.
#if !defined(OS_ANDROID)
......
......@@ -30,8 +30,6 @@ class ProfileInfoInterface {
virtual base::FilePath GetPathOfProfileAtIndex(size_t index) const = 0;
virtual base::string16 GetUserNameOfProfileAtIndex(size_t index) const = 0;
virtual base::string16 GetGAIANameOfProfileAtIndex(size_t index) const = 0;
virtual base::string16 GetGAIAGivenNameOfProfileAtIndex(
......
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