Commit 160927f8 authored by Alice Wang's avatar Alice Wang Committed by Chromium LUCI CQ

[Android][Signin] Clean up getProfileDataMap from ProfileDataSource interface

This CL cleans up the ProfileDataSource#getProfileDataMap usage, as
this method is not needed when we migrate to OneGoogle source for
profile data.

Bug: 1136452
Change-Id: I5fe3c13f478786a4b92755eaa989756035a80965
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602426
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840139}
parent 7c0169de
......@@ -336,7 +336,7 @@ public class AccountPickerBottomSheetTest {
});
checkZeroAccountBottomSheet();
mAccountManagerTestRule.addAccount(PROFILE_DATA1.getAccountEmail());
mAccountManagerTestRule.addAccount(PROFILE_DATA1);
checkCollapsedAccountList(PROFILE_DATA1);
}
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.signin.services;
import android.accounts.Account;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
......@@ -30,6 +31,7 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.browser_ui.util.AvatarGenerator;
import org.chromium.components.signin.AccountManagerFacadeProvider;
import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.ProfileDataSource.ProfileData;
import org.chromium.components.signin.base.AccountInfo;
import org.chromium.components.signin.identitymanager.IdentityManager;
......@@ -225,9 +227,16 @@ public class ProfileDataCache implements ProfileDataSource.Observer, IdentityMan
}
private void updateCacheFromProfileDataSource() {
for (ProfileDataSource.ProfileData profileData :
mProfileDataSource.getProfileDataMap().values()) {
updateCachedProfileDataAndNotifyObservers(createDisplayableProfileData(profileData));
AccountManagerFacadeProvider.getInstance().tryGetGoogleAccounts(this::updateAccounts);
}
private void updateAccounts(final List<Account> accounts) {
for (Account account : accounts) {
ProfileData profileData = mProfileDataSource.getProfileDataForAccount(account.name);
if (profileData != null) {
updateCachedProfileDataAndNotifyObservers(
createDisplayableProfileData(profileData));
}
}
}
......
......@@ -41,6 +41,7 @@ import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.base.AccountInfo;
import org.chromium.components.signin.base.CoreAccountId;
......@@ -80,6 +81,10 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
public ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build();
@Rule
public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(new FakeProfileDataSource());
@Rule
public final JniMocker mocker = new JniMocker();
......@@ -97,7 +102,7 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
private FrameLayout mContentView;
private ImageView mImageView;
private FakeProfileDataSource mProfileDataSource;
private ProfileDataCache mProfileDataCache;
@Before
......@@ -116,9 +121,7 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
mContentView.addView(mImageView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
activity.setContentView(mContentView);
mProfileDataSource = new FakeProfileDataSource();
mProfileDataCache =
new ProfileDataCache(getActivity(), mImageSize, null, mProfileDataSource);
mProfileDataCache = new ProfileDataCache(getActivity(), mImageSize, null);
// ProfileDataCache only populates the cache when an observer is added.
mProfileDataCache.addObserver(accountId -> {});
});
......@@ -141,7 +144,7 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
.thenReturn(new AccountInfo(
new CoreAccountId("gaia-id-test"), accountEmail, "gaia-id-test", null));
mProfileDataSource.addProfileData(
mAccountManagerTestRule.addAccount(
new ProfileDataSource.ProfileData(accountEmail, null, "Full Name", "Given Name"));
mIdentityManager.onExtendedAccountInfoUpdated(new AccountInfo(
new CoreAccountId("gaia-id-test"), accountEmail, "gaia-id-test", createAvatar()));
......@@ -166,7 +169,7 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
String accountName = "test@example.com";
ProfileDataSource.ProfileData profileData = new ProfileDataSource.ProfileData(
accountName, createAvatar(), "Full Name", "Given Name");
mProfileDataSource.addProfileData(profileData);
mAccountManagerTestRule.addAccount(profileData);
TestThreadUtils.runOnUiThreadBlocking(() -> {
checkImageIsScaled(accountName);
});
......
......@@ -33,6 +33,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.identitymanager.IdentityManager;
import org.chromium.components.signin.test.util.FakeProfileDataSource;
......@@ -50,9 +51,13 @@ import java.io.IOException;
@Batch(ProfileDataCacheRenderTest.PROFILE_DATA_BATCH_NAME)
public class ProfileDataCacheWithBadgeRenderTest extends DummyUiActivityTestCase {
@Rule
public ChromeRenderTestRule mRenderTestRule =
public final ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build();
@Rule
public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(new FakeProfileDataSource());
@Mock
private Profile mProfileMock;
......@@ -69,7 +74,6 @@ public class ProfileDataCacheWithBadgeRenderTest extends DummyUiActivityTestCase
private FrameLayout mContentView;
private ImageView mImageView;
private FakeProfileDataSource mProfileDataSource;
private ProfileDataCache mProfileDataCache;
@Before
......@@ -86,8 +90,6 @@ public class ProfileDataCacheWithBadgeRenderTest extends DummyUiActivityTestCase
mContentView.addView(mImageView, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
activity.setContentView(mContentView);
mProfileDataSource = new FakeProfileDataSource();
});
}
......@@ -124,14 +126,13 @@ public class ProfileDataCacheWithBadgeRenderTest extends DummyUiActivityTestCase
private void setUpProfileDataCache(@DrawableRes int badgeResId) {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mProfileDataCache = ProfileDataCache.createProfileDataCache(
getActivity(), badgeResId, mProfileDataSource);
mProfileDataCache = ProfileDataCache.createProfileDataCache(getActivity(), badgeResId);
// ProfileDataCache only populates the cache when an observer is added.
mProfileDataCache.addObserver(mObserver);
ProfileDataSource.ProfileData profileData = new ProfileDataSource.ProfileData(
TEST_ACCOUNT_NAME, createAvatar(), "Full Name", "Given Name");
mProfileDataSource.addProfileData(profileData);
mAccountManagerTestRule.addAccount(profileData);
mImageView.setImageDrawable(
mProfileDataCache.getProfileDataOrDefault(TEST_ACCOUNT_NAME).getImage());
});
......
......@@ -84,8 +84,11 @@ public interface ProfileDataSource {
* Gets ProfileData for all accounts. There must be at least one active observer when this
* method is invoked (see {@link #addObserver}).
* @return unmodifiable map of ProfileData for all accounts (keyed by account name).
* TODO(crbug/1136452): Remove this method after removing the downstream implementation.
*/
Map<String, ProfileData> getProfileDataMap();
default Map<String, ProfileData> getProfileDataMap() {
return null;
}
/**
* Gets ProfileData for single account. There must be at least one active observer when this
......
......@@ -10,7 +10,6 @@ import org.chromium.base.ObserverList;
import org.chromium.base.ThreadUtils;
import org.chromium.components.signin.ProfileDataSource;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
......@@ -24,12 +23,6 @@ public class FakeProfileDataSource implements ProfileDataSource {
public FakeProfileDataSource() {}
@Override
public Map<String, ProfileData> getProfileDataMap() {
ThreadUtils.assertOnUiThread();
return Collections.unmodifiableMap(mProfileDataMap);
}
@Override
public @Nullable ProfileData getProfileDataForAccount(String accountEmail) {
ThreadUtils.assertOnUiThread();
......
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