Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java |
| index 69eb23555b90ca3ed30e45b9d656cbef7986c0b0..fbf6ae00a61b6c85f139397aebf8f8b45cd5e77d 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/SigninManager.java |
| @@ -11,7 +11,6 @@ import android.app.DialogFragment; |
| import android.app.ProgressDialog; |
| import android.content.Context; |
| import android.content.DialogInterface; |
| -import android.os.AsyncTask; |
| import android.os.Bundle; |
| import android.os.Handler; |
| import android.support.v7.app.AlertDialog; |
| @@ -44,7 +43,6 @@ import javax.annotation.Nullable; |
| * See chrome/browser/signin/signin_manager_android.h for more details. |
| */ |
| public class SigninManager { |
| - |
| public static final String CONFIRM_MANAGED_SIGNIN_DIALOG_TAG = |
| "confirm_managed_signin_dialog_tag"; |
| @@ -86,6 +84,7 @@ public class SigninManager { |
| new ObserverList<SignInAllowedObserver>(); |
| private final SigninNotificationController mSigninNotificationController; |
| + private final AccountTrackerService mAccountTrackerService; |
| private Activity mSignInActivity; |
| private Account mSignInAccount; |
| @@ -143,28 +142,6 @@ public class SigninManager { |
| } |
| /** |
| - * Structure used to pass account ids and names from a background async task to the |
| - * foreground post execute function. This structure contains two arrays of the same |
| - * length: one containing strings of stable account ids and the other containing |
| - * strings of account names (or emails). An account id corresponds with the account |
| - * name at the same position in the array. |
| - */ |
| - private static class AccountIdsAndNames { |
| - public final String[] mAccountIds; |
| - public final String[] mAccountNames; |
| - |
| - public AccountIdsAndNames(String[] accountIds, String[] accountNames) { |
| - // Make sure that both arrays arguments are either null or have the same length. |
| - assert (accountIds == null) == (accountNames == null); |
| - if (accountIds != null && accountNames != null) { |
| - assert accountIds.length == accountNames.length; |
| - } |
| - mAccountIds = accountIds; |
| - mAccountNames = accountNames; |
| - } |
| - } |
| - |
| - /** |
| * A helper method for retrieving the application-wide SigninManager. |
| * <p/> |
| * Can only be accessed on the main thread. |
| @@ -192,6 +169,7 @@ public class SigninManager { |
| mSigninNotificationController = new SigninNotificationController( |
| mContext, controller, AccountManagementFragment.class); |
| ChromeSigninController.get(mContext).addListener(mSigninNotificationController); |
| + mAccountTrackerService = AccountTrackerService.get(context); |
| } |
| /** |
| @@ -265,6 +243,41 @@ public class SigninManager { |
| } |
| /** |
| + * Private class to pend sign in when system accounts have not been seeded into |
| + * AccountTrackerService. It listens onSystemAccountsSeedingComplete to finish pending sign in. |
| + */ |
| + private static class PendingSignin |
| + implements AccountTrackerService.SystemAccountsSeedingObserver { |
| + private static PendingSignin sPendingSignin; |
| + private static Context sContext; |
| + |
| + private boolean mIsSigninPended = false; |
| + |
| + public static PendingSignin get(Context context) { |
| + if (sPendingSignin == null) { |
| + sPendingSignin = new PendingSignin(); |
| + AccountTrackerService.get(context).observeSystemAccountsSeeding(sPendingSignin); |
| + } |
| + sContext = context; |
| + return sPendingSignin; |
| + } |
|
Roger Tawa OOO till Jul 10th
2015/08/14 15:01:22
Do we need this singleton, or can PendingSignin be
gogerald1
2015/08/18 01:14:26
Done.
|
| + |
| + public void pendSignin() { |
| + mIsSigninPended = true; |
| + if (AccountTrackerService.get(sContext).isSystemAccountsSeeded()) { |
| + onSystemAccountsSeedingComplete(); |
| + } |
| + } |
| + |
| + public synchronized void onSystemAccountsSeedingComplete() { |
| + if (mIsSigninPended) { |
| + mIsSigninPended = false; |
| + SigninManager.get(sContext).doSignIn(); |
| + } |
| + } |
| + } |
| + |
| + /** |
| * Starts the sign-in flow, and executes the callback when ready to proceed. |
| * <p/> |
| * This method checks with the native side whether the account has management enabled, and may |
| @@ -295,23 +308,32 @@ public class SigninManager { |
| notifySignInAllowedChanged(); |
| - if (!nativeShouldLoadPolicyForUser(account.name)) { |
| + if (!mAccountTrackerService.isSystemAccountsSeeded()) { |
| + PendingSignin.get(mContext).pendSignin(); |
| + return; |
| + } |
| + |
| + doSignIn(); |
| + } |
| + |
| + private void doSignIn() { |
| + if (!nativeShouldLoadPolicyForUser(mSignInAccount.name)) { |
| // Proceed with the sign-in flow without checking for policy if it can be determined |
| // that this account can't have management enabled based on the username. |
| - doSignIn(); |
| + finishSignIn(); |
| return; |
| } |
| Log.d(TAG, "Checking if account has policy management enabled"); |
| // This will call back to onPolicyCheckedBeforeSignIn. |
| - nativeCheckPolicyBeforeSignIn(mNativeSigninManagerAndroid, account.name); |
| + nativeCheckPolicyBeforeSignIn(mNativeSigninManagerAndroid, mSignInAccount.name); |
| } |
| @CalledByNative |
| private void onPolicyCheckedBeforeSignIn(String managementDomain) { |
| if (managementDomain == null) { |
| Log.d(TAG, "Account doesn't have policy"); |
| - doSignIn(); |
| + finishSignIn(); |
| return; |
| } |
| @@ -361,47 +383,18 @@ public class SigninManager { |
| private void onPolicyFetchedBeforeSignIn() { |
| // Policy has been fetched for the user and is being enforced; features like sync may now |
| // be disabled by policy, and the rest of the sign-in flow can be resumed. |
| - doSignIn(); |
| + finishSignIn(); |
| } |
| - private void doSignIn() { |
| + private void finishSignIn() { |
| Log.d(TAG, "Committing the sign-in process now"); |
| - assert mSignInAccount != null; |
| - |
| - // Get mapping from account names to account ids. |
| - final AccountIdProvider provider = AccountIdProvider.getInstance(); |
| - if (provider != null) { |
| - new AsyncTask<Void, Void, AccountIdsAndNames>() { |
| - @Override |
| - public AccountIdsAndNames doInBackground(Void... params) { |
| - Log.d(TAG, "Getting id/email mapping"); |
| - String[] accountNames = OAuth2TokenService.getSystemAccounts(mContext); |
| - assert accountNames.length > 0; |
| - String[] accountIds = new String[accountNames.length]; |
| - for (int i = 0; i < accountIds.length; ++i) { |
| - accountIds[i] = provider.getAccountId(mContext, accountNames[i]); |
| - } |
| - return new AccountIdsAndNames(accountIds, accountNames); |
| - } |
| - @Override |
| - public void onPostExecute(AccountIdsAndNames accountIdsAndNames) { |
| - finishSignIn(accountIdsAndNames); |
| - } |
| - }.execute(); |
| - } else { |
| - finishSignIn(new AccountIdsAndNames(null, null)); |
| - } |
| - } |
| - |
| - private void finishSignIn(AccountIdsAndNames accountIdsAndNames) { |
| if (mSignInAccount == null) { |
| Log.w(TAG, "Sign in request was canceled; aborting finishSignIn()."); |
| return; |
| } |
| // Tell the native side that sign-in has completed. |
| - nativeOnSignInCompleted(mNativeSigninManagerAndroid, mSignInAccount.name, |
| - accountIdsAndNames.mAccountIds, accountIdsAndNames.mAccountNames); |
| + nativeOnSignInCompleted(mNativeSigninManagerAndroid, mSignInAccount.name); |
| // Cache the signed-in account name. This must be done after the native call, otherwise |
| // sync tries to start without being signed in natively and crashes. |
| @@ -444,7 +437,6 @@ public class SigninManager { |
| mSignOutCallback = callback; |
| boolean wipeData = getManagementDomain() != null; |
| - Log.d(TAG, "Signing out, wipe data? " + wipeData); |
| ChromeSigninController.get(mContext).clearSignedInUser(); |
| ProfileSyncService.get(mContext).signOut(); |
| @@ -455,6 +447,8 @@ public class SigninManager { |
| } else { |
| onSignOutDone(); |
| } |
| + |
| + mAccountTrackerService.forceRefresh(); |
| } |
| /** |
| @@ -627,8 +621,7 @@ public class SigninManager { |
| private native void nativeCheckPolicyBeforeSignIn( |
| long nativeSigninManagerAndroid, String username); |
| private native void nativeFetchPolicyBeforeSignIn(long nativeSigninManagerAndroid); |
| - private native void nativeOnSignInCompleted(long nativeSigninManagerAndroid, String username, |
| - String[] accountIds, String[] accountNames); |
| + private native void nativeOnSignInCompleted(long nativeSigninManagerAndroid, String username); |
| private native void nativeSignOut(long nativeSigninManagerAndroid); |
| private native String nativeGetManagementDomain(long nativeSigninManagerAndroid); |
| private native void nativeWipeProfileData(long nativeSigninManagerAndroid); |