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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.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/signin/OAuth2TokenService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java
index 2ca4be96e58c4cebb099e195c38c6423176c03b0..fb161a9b17c55a59c2a252c88f39e2532a472e2c 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java
@@ -34,8 +34,8 @@ import javax.annotation.Nullable;
* AccountManagerHelper and forwards callbacks to native code.
* <p/>
*/
-public final class OAuth2TokenService {
-
+public final class OAuth2TokenService
+ implements AccountTrackerService.OnSystemAccountsSeededListener {
private static final String TAG = "OAuth2TokenService";
@VisibleForTesting
@@ -53,12 +53,16 @@ public final class OAuth2TokenService {
private static final String OAUTH2_SCOPE_PREFIX = "oauth2:";
+ private Context mPendingValidationContext = null;
+ private boolean mPendingValidationForceNotifications = false;
+
private final long mNativeOAuth2TokenServiceDelegateAndroid;
private final ObserverList<OAuth2TokenServiceObserver> mObservers;
- private OAuth2TokenService(long nativeOAuth2Service) {
+ private OAuth2TokenService(Context context, long nativeOAuth2Service) {
mNativeOAuth2TokenServiceDelegateAndroid = nativeOAuth2Service;
mObservers = new ObserverList<OAuth2TokenServiceObserver>();
+ AccountTrackerService.get(context).addSystemAccountsSeededListener(this);
}
public static OAuth2TokenService getForProfile(Profile profile) {
@@ -67,9 +71,9 @@ public final class OAuth2TokenService {
}
@CalledByNative
- private static OAuth2TokenService create(long nativeOAuth2Service) {
+ private static OAuth2TokenService create(Context context, long nativeOAuth2Service) {
ThreadUtils.assertOnUiThread();
- return new OAuth2TokenService(nativeOAuth2Service);
+ return new OAuth2TokenService(context, nativeOAuth2Service);
}
@VisibleForTesting
@@ -100,19 +104,19 @@ public final class OAuth2TokenService {
}
/**
- * Called by native to list the activite accounts in the OS.
+ * Called by native to list the activite account names in the OS.
*/
@VisibleForTesting
@CalledByNative
- public static String[] getSystemAccounts(Context context) {
+ public static String[] getSystemAccountNames(Context context) {
AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames();
return accountNames.toArray(new String[accountNames.size()]);
}
/**
- * Called by native to list the accounts with OAuth2 refresh tokens.
- * This can differ from getSystemAccounts as the user add/remove accounts
+ * Called by native to list the accounts Id with OAuth2 refresh tokens.
+ * This can differ from getSystemAccountNames as the user add/remove accounts
* from the OS. validateAccounts should be called to keep these two
* in sync.
*/
@@ -229,9 +233,44 @@ public final class OAuth2TokenService {
}
}
+ /**
+ * Continue pending accounts validation after system accounts have been seeded into
+ * AccountTrackerService.
+ */
+ @Override
+ public void onSystemAccountsSeedingComplete() {
+ if (mPendingValidationContext != null) {
+ validateAccountsWithSignedInAccountName(
+ mPendingValidationContext, mPendingValidationForceNotifications);
+ mPendingValidationContext = null;
+ mPendingValidationForceNotifications = false;
+ }
+ }
+
+ /**
+ * Clear pending accounts validation when system accounts in AccountTrackerService were
+ * refreshed.
+ */
+ @Override
+ public void onSystemAccountsForceRefreshed() {
+ mPendingValidationContext = null;
+ mPendingValidationForceNotifications = false;
+ }
+
@CalledByNative
public void validateAccounts(Context context, boolean forceNotifications) {
ThreadUtils.assertOnUiThread();
+ if (!AccountTrackerService.get(context).isSystemAccountsSeeded()) {
+ mPendingValidationContext = context;
+ mPendingValidationForceNotifications = forceNotifications;
+ return;
+ }
+
+ validateAccountsWithSignedInAccountName(context, forceNotifications);
+ }
+
+ private void validateAccountsWithSignedInAccountName(
+ Context context, boolean forceNotifications) {
String currentlySignedInAccount =
ChromeSigninController.get(context).getSignedInAccountName();
nativeValidateAccounts(mNativeOAuth2TokenServiceDelegateAndroid, currentlySignedInAccount,

Powered by Google App Engine
This is Rietveld 408576698