Commit 29beb10a authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Signin][Android] Remove Profile from ProfileDataCache constructor

This CL moves Profile instance obtaining from ProfileDataCache clients
to ProfileDownloader. It improves testability of ProfileDataCache and
dependent code by removing requirement for Profile object and allowing
simple faking with FakeProfileDataSource.

Bug: 746519
Change-Id: Ia81ef9c429384f2b9ec5e04ecb220f9aba90358a
Reviewed-on: https://chromium-review.googlesource.com/824662
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524134}
parent e2c706ef
......@@ -19,7 +19,6 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.DisplayableProfileData;
import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView;
import org.chromium.chrome.browser.signin.ProfileDataCache;
......@@ -93,8 +92,7 @@ class BookmarkPromoHeader implements AndroidSyncSettingsObserver, SignInStateObs
SigninAccessPoint.BOOKMARK_MANAGER)) {
int imageSize =
mContext.getResources().getDimensionPixelSize(R.dimen.user_picture_size);
mProfileDataCache =
new ProfileDataCache(mContext, Profile.getLastUsedProfile(), imageSize);
mProfileDataCache = new ProfileDataCache(mContext, imageSize);
mProfileDataCache.addObserver(this);
mSigninPromoController = new SigninPromoController(SigninAccessPoint.BOOKMARK_MANAGER);
AccountManagerFacade.get().addObserver(this);
......
......@@ -108,7 +108,7 @@ public class RecentTabsManager implements AndroidSyncSettingsObserver, SignInSta
if (SigninPromoController.arePersonalizedPromosEnabled()) {
int imageSize = context.getResources().getDimensionPixelSize(R.dimen.user_picture_size);
mProfileDataCache = new ProfileDataCache(mContext, profile, imageSize);
mProfileDataCache = new ProfileDataCache(mContext, imageSize);
mSigninPromoController = new SigninPromoController(SigninAccessPoint.RECENT_TABS);
} else {
mProfileDataCache = null;
......
......@@ -22,7 +22,6 @@ import org.chromium.chrome.browser.ntp.snippets.CategoryStatus;
import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.AccountSigninActivity;
import org.chromium.chrome.browser.signin.DisplayableProfileData;
import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView;
......@@ -116,8 +115,7 @@ public class SignInPromo extends OptionalLeaf {
if (mArePersonalizedPromosEnabled) {
int imageSize = context.getResources().getDimensionPixelSize(R.dimen.user_picture_size);
mProfileDataCache =
new ProfileDataCache(context, Profile.getLastUsedProfile(), imageSize);
mProfileDataCache = new ProfileDataCache(context, imageSize);
mSigninPromoController =
new SigninPromoController(SigninAccessPoint.NTP_CONTENT_SUGGESTIONS);
mGenericPromoData = null;
......
......@@ -16,7 +16,6 @@ import android.view.View;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.AccountManagementFragment;
import org.chromium.chrome.browser.signin.AccountSigninActivity;
import org.chromium.chrome.browser.signin.DisplayableProfileData;
......@@ -57,7 +56,7 @@ public class SignInPreference
super(context, attrs);
int imageSize = context.getResources().getDimensionPixelSize(R.dimen.user_picture_size);
mProfileDataCache = new ProfileDataCache(context, Profile.getLastUsedProfile(), imageSize);
mProfileDataCache = new ProfileDataCache(context, imageSize);
setOnPreferenceClickListener(preference
-> AccountSigninActivity.startIfAllowed(getContext(), SigninAccessPoint.SETTINGS));
......
......@@ -114,13 +114,13 @@ public class ProfileDownloader {
/**
* Starts fetching the account information for a given account.
* @param context context associated with the request
* @param profile Profile associated with the request
* @param accountId Account name to fetch the information for
* @param imageSidePixels Request image side (in pixels)
*/
public static void startFetchingAccountInfoFor(Context context, Profile profile,
String accountId, int imageSidePixels, boolean isPreSignin) {
public static void startFetchingAccountInfoFor(
Context context, String accountId, int imageSidePixels, boolean isPreSignin) {
ThreadUtils.assertOnUiThread();
Profile profile = Profile.getLastUsedProfile().getOriginalProfile();
if (!AccountTrackerService.get().checkAndSeedSystemAccounts()) {
PendingProfileDownloads.get(context).pendProfileDownload(
profile, accountId, imageSidePixels);
......
......@@ -135,8 +135,7 @@ public class AccountManagementFragment extends PreferenceFragment
badgeConfig = new ProfileDataCache.BadgeConfig(
badge, new Point(badgePositionX, badgePositionY), badgeBorderSize);
}
mProfileDataCache =
new ProfileDataCache(getActivity(), mProfile, avatarImageSize, badgeConfig);
mProfileDataCache = new ProfileDataCache(getActivity(), avatarImageSize, badgeConfig);
}
@Override
......
......@@ -26,7 +26,6 @@ import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.AccountTrackerService.OnSystemAccountsSeededListener;
import org.chromium.chrome.browser.signin.ConfirmImportSyncDataDialog.ImportSyncType;
import org.chromium.components.signin.AccountManagerDelegateException;
......@@ -149,7 +148,7 @@ public class AccountSigninView extends FrameLayout {
super(context, attrs);
mAccountsChangedObserver = this::triggerUpdateAccounts;
mProfileDataCacheObserver = (String accountId) -> updateProfileData();
mProfileDataCache = new ProfileDataCache(context, Profile.getLastUsedProfile(),
mProfileDataCache = new ProfileDataCache(context,
context.getResources().getDimensionPixelSize(R.dimen.signin_account_image_size));
mCancelButtonTextId = R.string.no_thanks;
......
......@@ -25,7 +25,6 @@ import android.support.v7.content.res.AppCompatResources;
import org.chromium.base.ObserverList;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileDownloader;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.ProfileDataSource;
......@@ -91,7 +90,6 @@ public class ProfileDataCache implements ProfileDownloader.Observer, ProfileData
}
private final Context mContext;
private final Profile mProfile;
private final int mImageSize;
private @Nullable final BadgeConfig mBadgeConfig;
private final Drawable mPlaceholderImage;
......@@ -99,14 +97,12 @@ public class ProfileDataCache implements ProfileDownloader.Observer, ProfileData
private final Map<String, DisplayableProfileData> mCachedProfileData = new HashMap<>();
private @Nullable final ProfileDataSource mProfileDataSource;
public ProfileDataCache(Context context, Profile profile, int imageSize) {
this(context, profile, imageSize, null);
public ProfileDataCache(Context context, int imageSize) {
this(context, imageSize, null);
}
public ProfileDataCache(
Context context, Profile profile, int imageSize, @Nullable BadgeConfig badgeConfig) {
public ProfileDataCache(Context context, int imageSize, @Nullable BadgeConfig badgeConfig) {
mContext = context;
mProfile = profile;
mImageSize = imageSize;
mBadgeConfig = badgeConfig;
......@@ -131,7 +127,7 @@ public class ProfileDataCache implements ProfileDownloader.Observer, ProfileData
for (int i = 0; i < accounts.size(); i++) {
if (mCachedProfileData.get(accounts.get(i)) == null) {
ProfileDownloader.startFetchingAccountInfoFor(
mContext, mProfile, accounts.get(i), mImageSize, true);
mContext, accounts.get(i), mImageSize, true);
}
}
}
......
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