Commit 31901806 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Signin] Rename accountName to accountEmail for profile data

This CL renames accountName to accountEmail for profile data related
code.

Bug: 1131344
Change-Id: I8651cd5759c38844444fbbe199391baa3f4f9d5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2552392Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829668}
parent 338f8bb8
......@@ -36,7 +36,7 @@ public class AssistantHeaderCoordinator implements ProfileDataCache.Observer {
private final ProfileDataCache mProfileCache;
private final ViewGroup mView;
private final ImageView mProfileView;
private final String mSignedInAccountName;
private final String mSignedInAccountEmail;
private final ViewHolder mViewHolder;
private final RecyclerView mChipsContainer;
......@@ -59,7 +59,7 @@ public class AssistantHeaderCoordinator implements ProfileDataCache.Observer {
mProfileView = mView.findViewById(R.id.profile_image);
IdentityManager identityManager = IdentityServicesProvider.get().getIdentityManager(
AutofillAssistantUiController.getProfile());
mSignedInAccountName = CoreAccountInfo.getEmailFrom(
mSignedInAccountEmail = CoreAccountInfo.getEmailFrom(
identityManager.getPrimaryAccountInfo(ConsentLevel.SYNC));
setupProfileImage();
......@@ -115,10 +115,10 @@ public class AssistantHeaderCoordinator implements ProfileDataCache.Observer {
@Override
public void onProfileDataUpdated(String accountEmail) {
if (!mSignedInAccountName.equals(accountEmail)) {
if (!mSignedInAccountEmail.equals(accountEmail)) {
return;
}
setProfileImageFor(mSignedInAccountName);
setProfileImageFor(mSignedInAccountEmail);
}
/** Return the view associated to this coordinator. */
......@@ -135,7 +135,7 @@ public class AssistantHeaderCoordinator implements ProfileDataCache.Observer {
* Cleanup resources when this goes out of scope.
*/
public void destroy() {
if (mSignedInAccountName != null) {
if (mSignedInAccountEmail != null) {
mProfileCache.removeObserver(this);
}
}
......@@ -148,9 +148,9 @@ public class AssistantHeaderCoordinator implements ProfileDataCache.Observer {
// TODO(b/130415092): Use image from AGSA if chrome is not signed in.
private void setupProfileImage() {
if (mSignedInAccountName != null) {
if (mSignedInAccountEmail != null) {
mProfileCache.addObserver(this);
mProfileCache.update(Collections.singletonList(mSignedInAccountName));
mProfileCache.update(Collections.singletonList(mSignedInAccountEmail));
}
}
private void setProfileImageFor(String signedInAccountName) {
......
......@@ -12,26 +12,26 @@ import androidx.annotation.Nullable;
* Immutable holder for displayable profile data.
*/
public class DisplayableProfileData {
private final String mAccountName;
private final String mAccountEmail;
private final Drawable mImage;
private final @Nullable String mFullName;
private final @Nullable String mGivenName;
public DisplayableProfileData(String accountName, Drawable image, @Nullable String fullName,
public DisplayableProfileData(String accountEmail, Drawable image, @Nullable String fullName,
@Nullable String givenName) {
assert accountName != null;
assert accountEmail != null;
assert image != null;
mAccountName = accountName;
mAccountEmail = accountEmail;
mImage = image;
mFullName = fullName;
mGivenName = givenName;
}
/**
* @return The account name (i.e. the e-mail address).
* @return The account email.
*/
public String getAccountName() {
return mAccountName;
public String getAccountEmail() {
return mAccountEmail;
}
/**
......@@ -60,7 +60,7 @@ public class DisplayableProfileData {
*/
public String getFullNameOrEmail() {
if (mFullName == null) {
return mAccountName;
return mAccountEmail;
}
return mFullName;
}
......
......@@ -186,10 +186,10 @@ public class ProfileDataCache implements ProfileDownloader.Observer, ProfileData
* given account or a {@link DisplayableProfileData} with a placeholder image and null
* full and given name.
*/
public DisplayableProfileData getProfileDataOrDefault(String accountName) {
DisplayableProfileData profileData = mCachedProfileData.get(accountName);
public DisplayableProfileData getProfileDataOrDefault(String accountEmail) {
DisplayableProfileData profileData = mCachedProfileData.get(accountEmail);
if (profileData == null) {
return new DisplayableProfileData(accountName, mPlaceholderImage, null, null);
return new DisplayableProfileData(accountEmail, mPlaceholderImage, null, null);
}
return profileData;
}
......@@ -236,8 +236,8 @@ public class ProfileDataCache implements ProfileDownloader.Observer, ProfileData
private DisplayableProfileData createDisplayableProfileData(
ProfileDataSource.ProfileData profileData) {
return new DisplayableProfileData(profileData.getAccountName(),
prepareAvatar(profileData.getAvatar(), profileData.getAccountName()),
return new DisplayableProfileData(profileData.getAccountEmail(),
prepareAvatar(profileData.getAvatar(), profileData.getAccountEmail()),
profileData.getFullName(), profileData.getGivenName());
}
......@@ -337,8 +337,8 @@ public class ProfileDataCache implements ProfileDownloader.Observer, ProfileData
}
private void updateCachedProfileDataAndNotifyObservers(DisplayableProfileData profileData) {
mCachedProfileData.put(profileData.getAccountName(), profileData);
notifyObservers(profileData.getAccountName());
mCachedProfileData.put(profileData.getAccountEmail(), profileData);
notifyObservers(profileData.getAccountEmail());
}
private void notifyObservers(String accountEmail) {
......
......@@ -336,12 +336,12 @@ public abstract class SigninFragmentBase
if (!TextUtils.isEmpty(fullName)) {
mConsentTextTracker.setTextNonRecordable(mView.getAccountTextPrimary(), fullName);
mConsentTextTracker.setTextNonRecordable(
mView.getAccountTextSecondary(), profileData.getAccountName());
mView.getAccountTextSecondary(), profileData.getAccountEmail());
mView.getAccountTextSecondary().setVisibility(View.VISIBLE);
} else {
// Full name is not available, show the email in the primary TextView.
mConsentTextTracker.setTextNonRecordable(
mView.getAccountTextPrimary(), profileData.getAccountName());
mView.getAccountTextPrimary(), profileData.getAccountEmail());
mView.getAccountTextSecondary().setVisibility(View.GONE);
}
}
......
......@@ -317,14 +317,14 @@ public class SigninPromoController {
recordSigninButtonUsed();
RecordUserAction.record(mSigninWithDefaultUserActionName);
SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow(
context, mAccessPoint, mProfileData.getAccountName());
context, mAccessPoint, mProfileData.getAccountEmail());
}
private void signinWithNotDefaultAccount(Context context) {
recordSigninButtonUsed();
RecordUserAction.record(mSigninNotDefaultUserActionName);
SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow(
context, mAccessPoint, mProfileData.getAccountName());
context, mAccessPoint, mProfileData.getAccountEmail());
}
private void recordSigninButtonUsed() {
......
......@@ -115,9 +115,9 @@ class AccountPickerMediator {
DisplayableProfileData profileData, boolean isDefaultAccount) {
Callback<DisplayableProfileData> profileDataCallback = profileData1
-> mAccountPickerListener.onAccountSelected(
profileData1.getAccountName(), isDefaultAccount);
profileData1.getAccountEmail(), isDefaultAccount);
PropertyModel model = ExistingAccountRowProperties.createModel(profileData,
profileDataCallback, profileData.getAccountName().equals(mSelectedAccountName));
profileDataCallback, profileData.getAccountEmail().equals(mSelectedAccountName));
return new MVCListAdapter.ListItem(ItemType.EXISTING_ACCOUNT_ROW, model);
}
......@@ -126,7 +126,7 @@ class AccountPickerMediator {
if (item.type == AccountPickerProperties.ItemType.EXISTING_ACCOUNT_ROW) {
PropertyModel model = item.model;
boolean isSelectedAccount = TextUtils.equals(mSelectedAccountName,
model.get(ExistingAccountRowProperties.PROFILE_DATA).getAccountName());
model.get(ExistingAccountRowProperties.PROFILE_DATA).getAccountEmail());
model.set(ExistingAccountRowProperties.IS_SELECTED_ACCOUNT, isSelectedAccount);
}
}
......@@ -140,7 +140,7 @@ class AccountPickerMediator {
if (item.type == AccountPickerProperties.ItemType.EXISTING_ACCOUNT_ROW) {
PropertyModel model = item.model;
boolean isProfileDataUpdated = TextUtils.equals(accountName,
model.get(ExistingAccountRowProperties.PROFILE_DATA).getAccountName());
model.get(ExistingAccountRowProperties.PROFILE_DATA).getAccountEmail());
if (isProfileDataUpdated) {
model.set(ExistingAccountRowProperties.PROFILE_DATA,
mProfileDataCache.getProfileDataOrDefault(accountName));
......
......@@ -78,11 +78,11 @@ class ExistingAccountRowViewBinder {
String fullName = profileData.getFullName();
if (!TextUtils.isEmpty(fullName)) {
accountTextPrimary.setText(fullName);
accountTextSecondary.setText(profileData.getAccountName());
accountTextSecondary.setText(profileData.getAccountEmail());
accountTextSecondary.setVisibility(View.VISIBLE);
} else {
// Full name is not available, show the email in the primary TextView.
accountTextPrimary.setText(profileData.getAccountName());
accountTextPrimary.setText(profileData.getAccountEmail());
accountTextSecondary.setVisibility(View.GONE);
}
}
......
......@@ -186,7 +186,7 @@ public class AccountPickerBottomSheetRenderTest {
throws IOException {
mAccountManagerTestRule.addAccount(PROFILE_DATA1);
CoreAccountInfo coreAccountInfo =
mAccountManagerTestRule.toCoreAccountInfo(PROFILE_DATA1.getAccountName());
mAccountManagerTestRule.toCoreAccountInfo(PROFILE_DATA1.getAccountEmail());
// Throws a connection error during the sign-in action
doAnswer(invocation -> {
Callback<GoogleServiceAuthError> onSignInErrorCallback = invocation.getArgument(1);
......@@ -208,7 +208,7 @@ public class AccountPickerBottomSheetRenderTest {
public void testSigninGeneralErrorView(boolean nightModeEnabled) throws IOException {
mAccountManagerTestRule.addAccount(PROFILE_DATA1);
CoreAccountInfo coreAccountInfo =
mAccountManagerTestRule.toCoreAccountInfo(PROFILE_DATA1.getAccountName());
mAccountManagerTestRule.toCoreAccountInfo(PROFILE_DATA1.getAccountEmail());
// Throws a connection error during the sign-in action
doAnswer(invocation -> {
Callback<GoogleServiceAuthError> onSignInErrorCallback = invocation.getArgument(1);
......@@ -230,7 +230,7 @@ public class AccountPickerBottomSheetRenderTest {
public void testSigninAuthErrorView(boolean nightModeEnabled) throws IOException {
mAccountManagerTestRule.addAccount(PROFILE_DATA1);
CoreAccountInfo coreAccountInfo =
mAccountManagerTestRule.toCoreAccountInfo(PROFILE_DATA1.getAccountName());
mAccountManagerTestRule.toCoreAccountInfo(PROFILE_DATA1.getAccountEmail());
// Throws an authentication error during the sign-in action
doAnswer(invocation -> {
Callback<GoogleServiceAuthError> onSignInErrorCallback = invocation.getArgument(1);
......@@ -254,7 +254,7 @@ public class AccountPickerBottomSheetRenderTest {
throws IOException {
mAccountManagerTestRule.addAccount(PROFILE_DATA1);
CoreAccountInfo coreAccountInfo =
mAccountManagerTestRule.toCoreAccountInfo(PROFILE_DATA1.getAccountName());
mAccountManagerTestRule.toCoreAccountInfo(PROFILE_DATA1.getAccountEmail());
// Throws an auth error during the sign-in action
doAnswer(invocation -> {
Callback<GoogleServiceAuthError> onSignInErrorCallback = invocation.getArgument(1);
......@@ -273,7 +273,7 @@ public class AccountPickerBottomSheetRenderTest {
return null;
})
.when(mAccountPickerDelegateMock)
.updateCredentials(eq(PROFILE_DATA1.getAccountName()), any());
.updateCredentials(eq(PROFILE_DATA1.getAccountEmail()), any());
onView(withText(R.string.auth_error_card_button)).perform(click());
mRenderTestRule.render(
mCoordinator.getBottomSheetViewForTesting(), "collapsed_sheet_with_account");
......
......@@ -146,7 +146,7 @@ public class AccountPickerMediatorTest {
Assert.assertEquals(AccountPickerProperties.ItemType.EXISTING_ACCOUNT_ROW, item.type);
PropertyModel model = item.model;
DisplayableProfileData profileData = model.get(ExistingAccountRowProperties.PROFILE_DATA);
Assert.assertEquals(accountEmail, profileData.getAccountName());
Assert.assertEquals(accountEmail, profileData.getAccountEmail());
Assert.assertEquals(fullName, profileData.getFullName());
Assert.assertEquals(
isSelectedAccount, model.get(ExistingAccountRowProperties.IS_SELECTED_ACCOUNT));
......
......@@ -113,8 +113,8 @@ public class AccountManagerTestRule implements TestRule {
* @return The account added.
*/
public CoreAccountInfo addAccount(ProfileDataSource.ProfileData profileData) {
CoreAccountInfo coreAccountInfo = addAccount(profileData.getAccountName());
mFakeAccountManagerFacade.setProfileData(profileData.getAccountName(), profileData);
CoreAccountInfo coreAccountInfo = addAccount(profileData.getAccountEmail());
mFakeAccountManagerFacade.setProfileData(profileData.getAccountEmail(), profileData);
return coreAccountInfo;
}
......
......@@ -18,15 +18,15 @@ public interface ProfileDataSource {
* Immutable holder for profile data.
*/
class ProfileData {
private final String mAccountName;
private final String mAccountEmail;
private final @Nullable Bitmap mAvatar;
private final @Nullable String mFullName;
private final @Nullable String mGivenName;
public ProfileData(String accountName, @Nullable Bitmap avatar, @Nullable String fullName,
public ProfileData(String accountEmail, @Nullable Bitmap avatar, @Nullable String fullName,
@Nullable String givenName) {
assert accountName != null;
this.mAccountName = accountName;
assert accountEmail != null;
this.mAccountEmail = accountEmail;
this.mAvatar = avatar;
this.mFullName = fullName;
this.mGivenName = givenName;
......@@ -34,10 +34,10 @@ public interface ProfileDataSource {
/**
* Gets the account email address.
* @return the account name.
* @return the account email.
*/
public String getAccountName() {
return mAccountName;
public String getAccountEmail() {
return mAccountEmail;
}
/**
......
......@@ -58,7 +58,7 @@ public class FakeProfileDataSource implements ProfileDataSource {
if (profileData == null) {
mProfileDataMap.remove(accountId);
} else {
assert accountId.equals(profileData.getAccountName());
assert accountId.equals(profileData.getAccountEmail());
mProfileDataMap.put(accountId, profileData);
}
fireOnProfileDataUpdatedNotification(accountId);
......
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