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