Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4941)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/profiles/ProfileDownloader.java

Issue 1256283002: GAIA ID migration for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3ac59f70cfa8c16c5743fd03122f9345219e3ac4 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,16 @@
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.base.annotations.SuppressFBWarnings;
+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 +55,79 @@ 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 final ArrayList<Profile> mProfiles;
+ private final ArrayList<String> mAccountIds;
+ private final ArrayList<Integer> mImageSidePixels;
+
+ private PendingProfileDownloads() {
+ mProfiles = new ArrayList<>();
+ mAccountIds = new ArrayList<>();
+ mImageSidePixels = new ArrayList<>();
+ }
+
+ @SuppressFBWarnings("LI_LAZY_INIT_UPDATE_STATIC")
+ public static PendingProfileDownloads get(Context context) {
+ ThreadUtils.assertOnUiThread();
+ if (sPendingProfileDownloads == null) {
+ sPendingProfileDownloads = new PendingProfileDownloads();
+ AccountTrackerService.get(context).addSystemAccountsSeededListener(
+ sPendingProfileDownloads);
+ }
+ return sPendingProfileDownloads;
+ }
+
+ public void pendProfileDownload(Profile profile, String accountId, int imageSidePixels) {
+ mProfiles.add(profile);
+ mAccountIds.add(accountId);
+ mImageSidePixels.add(imageSidePixels);
+ }
+
+ @Override
+ public void onSystemAccountsSeedingComplete() {
+ int numberOfPendingRequests = mAccountIds.size();
+ while (numberOfPendingRequests > 0) {
+ // Pending requests here must be pre-signin request since SigninManager will wait
+ // system accounts been seeded into AccountTrackerService before finishing sign in.
+ nativeStartFetchingAccountInfoFor(
+ mProfiles.get(0), mAccountIds.get(0), mImageSidePixels.get(0), true);
+ mProfiles.remove(0);
+ mAccountIds.remove(0);
+ mImageSidePixels.remove(0);
+ numberOfPendingRequests--;
+ }
+ }
+
+ @Override
+ public void onSystemAccountsForceRefreshed() {
+ 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(context).pendProfileDownload(
+ profile, accountId, imageSidePixels);
+ return;
+ }
nativeStartFetchingAccountInfoFor(profile, accountId, imageSidePixels, isPreSignin);
}

Powered by Google App Engine
This is Rietveld 408576698