Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/profiles/ProfileDownloader.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/profiles/ProfileDownloader.java b/chrome/android/java/src/org/chromium/chrome/browser/profiles/ProfileDownloader.java |
| index 286e99f1520d62476e501e30cefa230bfad330f6..296a4aa5f5e25255f9037d7e83552dff2f2f80fe 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/profiles/ProfileDownloader.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/profiles/ProfileDownloader.java |
| @@ -4,11 +4,15 @@ |
| package org.chromium.chrome.browser.profiles; |
| +import android.content.Context; |
| import android.graphics.Bitmap; |
| import org.chromium.base.ObserverList; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.chrome.browser.signin.AccountTrackerService; |
| + |
| +import java.util.ArrayList; |
| /** |
| * Android wrapper of the ProfileDownloader which provides access from the Java layer. |
| @@ -50,14 +54,73 @@ public class ProfileDownloader { |
| } |
| /** |
| + * Private class to pend profile download requests when system accounts have not been seeded into |
| + * AccountTrackerService. It listens onSystemAccountsSeedingComplete to finish pending requests |
| + * and onSystemAccountsForceRefreshed to clear outdated pending requests. |
| + */ |
| + private static class PendingProfileDownloads |
| + implements AccountTrackerService.OnSystemAccountsSeededListener { |
| + private static PendingProfileDownloads sPendingProfileDownloads; |
| + |
| + private ArrayList<Profile> mProfiles; |
|
nyquist
2015/08/28 19:18:25
Could all these be final?
gogerald1
2015/08/28 21:38:45
Done.
|
| + private ArrayList<String> mAccountIds; |
| + private ArrayList<Integer> mImageSidePixels; |
| + |
| + private PendingProfileDownloads() { |
| + mProfiles = new ArrayList<Profile>(); |
|
nyquist
2015/08/28 19:18:26
You can just use new ArrayList<>();
gogerald1
2015/08/28 21:38:45
Done.
|
| + mAccountIds = new ArrayList<String>(); |
| + mImageSidePixels = new ArrayList<Integer>(); |
| + } |
| + |
| + public static PendingProfileDownloads get() { |
| + ThreadUtils.assertOnUiThread(); |
| + if (sPendingProfileDownloads == null) { |
| + sPendingProfileDownloads = new PendingProfileDownloads(); |
| + AccountTrackerService.addSystemAccountsSeededListener(sPendingProfileDownloads); |
| + } |
| + return sPendingProfileDownloads; |
| + } |
| + |
| + public void pendProfileDownload(Profile profile, String accountId, int imageSidePixels) { |
| + mProfiles.add(profile); |
| + mAccountIds.add(accountId); |
| + mImageSidePixels.add(imageSidePixels); |
| + } |
| + |
| + public void onSystemAccountsSeedingComplete() { |
|
nyquist
2015/08/28 19:18:25
Missing @Override
gogerald1
2015/08/28 21:38:46
Done.
|
| + int numberOfPendingRequests = mAccountIds.size(); |
| + while (numberOfPendingRequests > 0) { |
|
nyquist
2015/08/28 19:18:26
numberOfPendingRequests is never updated within th
gogerald1
2015/08/28 21:38:45
Done.
|
| + // Pending requests here must be pre-signin request since SigninManager will wait |
| + // system accounts been seeded into AccountTrackerService before finishing sign in. |
| + ProfileDownloader.nativeStartFetchingAccountInfoFor(mProfiles.get(0), |
|
nyquist
2015/08/28 19:18:25
Just remove |ProfileDownloader.| from this.
gogerald1
2015/08/28 21:38:46
Done.
|
| + mAccountIds.get(0), mImageSidePixels.get(0).intValue(), true); |
|
nyquist
2015/08/28 19:18:26
You don't need .intValue()
gogerald1
2015/08/28 21:38:45
Done.
|
| + mProfiles.remove(0); |
|
nyquist
2015/08/28 19:18:25
This isn't thread safe, but I'm guessing that's no
gogerald1
2015/08/28 21:38:45
Yes, and the observers are called in UI thread.
|
| + mAccountIds.remove(0); |
| + mImageSidePixels.remove(0); |
| + } |
| + } |
| + |
| + public void onSystemAccountsForceRefreshed() { |
|
nyquist
2015/08/28 19:18:25
Missing @Override
gogerald1
2015/08/28 21:38:45
Done.
|
| + mProfiles.clear(); |
| + mAccountIds.clear(); |
| + mImageSidePixels.clear(); |
| + } |
| + } |
| + |
| + /** |
| * 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( |
| - Profile profile, String accountId, int imageSidePixels, boolean isPreSignin) { |
| + public static void startFetchingAccountInfoFor(Context context, Profile profile, |
| + String accountId, int imageSidePixels, boolean isPreSignin) { |
| ThreadUtils.assertOnUiThread(); |
| + if (!AccountTrackerService.get(context).isSystemAccountsSeeded()) { |
| + PendingProfileDownloads.get().pendProfileDownload(profile, accountId, imageSidePixels); |
| + return; |
| + } |
| nativeStartFetchingAccountInfoFor(profile, accountId, imageSidePixels, isPreSignin); |
| } |