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

[Signin][Android] Stop repopulating account list for profile data update

This CL stops repopulating the whole account list for one specific
profile data update in account picker.

Bug: 1110874c
Change-Id: Ie3346eb0d9b2b6b3c5363f0ede24044bae24ac8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2324848Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793536}
parent bd4f88b5
...@@ -42,7 +42,7 @@ class AccountPickerMediator { ...@@ -42,7 +42,7 @@ class AccountPickerMediator {
private final AccountManagerFacade mAccountManagerFacade; private final AccountManagerFacade mAccountManagerFacade;
private final AccountsChangeObserver mAccountsChangeObserver = this::updateAccounts; private final AccountsChangeObserver mAccountsChangeObserver = this::updateAccounts;
private final ProfileDataCache.Observer mProfileDataObserver = accountId -> updateProfileData(); private final ProfileDataCache.Observer mProfileDataObserver = this::updateProfileData;
private List<String> mAccountNames; private List<String> mAccountNames;
@MainThread @MainThread
...@@ -76,13 +76,13 @@ class AccountPickerMediator { ...@@ -76,13 +76,13 @@ class AccountPickerMediator {
} }
} }
/**
* Implements {@link AccountsChangeObserver}.
*/
private void updateAccounts() { private void updateAccounts() {
mAccountNames = AccountUtils.toAccountNames(mAccountManagerFacade.tryGetGoogleAccounts()); mAccountNames = AccountUtils.toAccountNames(mAccountManagerFacade.tryGetGoogleAccounts());
mProfileDataCache.update(mAccountNames); mProfileDataCache.update(mAccountNames);
updateProfileData();
}
private void updateProfileData() {
mListModel.clear(); mListModel.clear();
// Add an "existing account" row for each account // Add an "existing account" row for each account
if (mAccountNames.size() > 0) { if (mAccountNames.size() > 0) {
...@@ -128,4 +128,22 @@ class AccountPickerMediator { ...@@ -128,4 +128,22 @@ class AccountPickerMediator {
} }
} }
} }
/**
* Implements {@link ProfileDataCache.Observer}
*/
private void updateProfileData(String accountName) {
for (MVCListAdapter.ListItem item : mListModel) {
if (item.type == AccountPickerProperties.ItemType.EXISTING_ACCOUNT_ROW) {
PropertyModel model = item.model;
boolean isProfileDataUpdated = TextUtils.equals(accountName,
model.get(ExistingAccountRowProperties.PROFILE_DATA).getAccountName());
if (isProfileDataUpdated) {
model.set(ExistingAccountRowProperties.PROFILE_DATA,
mProfileDataCache.getProfileDataOrDefault(accountName));
break;
}
}
}
}
} }
...@@ -60,8 +60,8 @@ class AccountPickerProperties { ...@@ -60,8 +60,8 @@ class AccountPickerProperties {
* Properties for account row in account picker. * Properties for account row in account picker.
*/ */
static class ExistingAccountRowProperties { static class ExistingAccountRowProperties {
static final PropertyModel.ReadableObjectPropertyKey<DisplayableProfileData> PROFILE_DATA = static final PropertyModel.WritableObjectPropertyKey<DisplayableProfileData> PROFILE_DATA =
new PropertyModel.ReadableObjectPropertyKey<>("profile_data"); new PropertyModel.WritableObjectPropertyKey<>("profile_data");
static final PropertyModel.WritableBooleanPropertyKey IS_SELECTED_ACCOUNT = static final PropertyModel.WritableBooleanPropertyKey IS_SELECTED_ACCOUNT =
new PropertyModel.WritableBooleanPropertyKey("is_selected_account"); new PropertyModel.WritableBooleanPropertyKey("is_selected_account");
static final PropertyModel static final PropertyModel
......
...@@ -26,6 +26,7 @@ import org.chromium.chrome.test.util.browser.Features; ...@@ -26,6 +26,7 @@ import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule; import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.signin.ProfileDataSource; import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.test.util.FakeProfileDataSource; import org.chromium.components.signin.test.util.FakeProfileDataSource;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.modelutil.MVCListAdapter; import org.chromium.ui.modelutil.MVCListAdapter;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -38,12 +39,14 @@ public class AccountPickerMediatorTest { ...@@ -38,12 +39,14 @@ public class AccountPickerMediatorTest {
private static final String ACCOUNT_NAME1 = "test.account1@gmail.com"; private static final String ACCOUNT_NAME1 = "test.account1@gmail.com";
private static final String ACCOUNT_NAME2 = "test.account2@gmail.com"; private static final String ACCOUNT_NAME2 = "test.account2@gmail.com";
private final FakeProfileDataSource mFakeProfileDataSource = new FakeProfileDataSource();
@Rule @Rule
public TestRule mProcessor = new Features.JUnitProcessor(); public TestRule mProcessor = new Features.JUnitProcessor();
@Rule @Rule
public final AccountManagerTestRule mAccountManagerTestRule = public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(new FakeProfileDataSource()); new AccountManagerTestRule(mFakeProfileDataSource);
@Mock @Mock
private AccountPickerCoordinator.Listener mListenerMock; private AccountPickerCoordinator.Listener mListenerMock;
...@@ -124,6 +127,25 @@ public class AccountPickerMediatorTest { ...@@ -124,6 +127,25 @@ public class AccountPickerMediatorTest {
checkItemForAddAccountRow(2); checkItemForAddAccountRow(2);
} }
@Test
@Features.DisableFeatures(ChromeFeatureList.MOBILE_IDENTITY_CONSISTENCY)
public void testProfileDataUpdateWhenAccountPickerIsShown() {
addAccount(ACCOUNT_NAME1, FULL_NAME1);
addAccount(ACCOUNT_NAME2, "");
mMediator = new AccountPickerMediator(
RuntimeEnvironment.application, mModelList, mListenerMock, ACCOUNT_NAME1);
String fullName2 = "Full Name2";
TestThreadUtils.runOnUiThreadBlocking(() -> {
mFakeProfileDataSource.setProfileData(ACCOUNT_NAME2,
new ProfileDataSource.ProfileData(ACCOUNT_NAME2, null, fullName2, null));
});
// ACCOUNT_NAME1, ACCOUNT_NAME2, ADD_ACCOUNT
Assert.assertEquals(3, mModelList.size());
checkItemForExistingAccountRow(0, ACCOUNT_NAME1, FULL_NAME1, /* isSelectedAccount= */ true);
checkItemForExistingAccountRow(1, ACCOUNT_NAME2, fullName2, /* isSelectedAccount= */ false);
checkItemForAddAccountRow(2);
}
private void checkItemForExistingAccountRow( private void checkItemForExistingAccountRow(
int position, String accountEmail, String fullName, boolean isSelectedAccount) { int position, String accountEmail, String fullName, boolean isSelectedAccount) {
MVCListAdapter.ListItem item = mModelList.get(position); MVCListAdapter.ListItem item = mModelList.get(position);
......
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