Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachine.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachine.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachine.java |
| index 685eeae76058b9aa825ba1ad9abed9f89374d909..a3a415de9cfe2dd40af7a408a8626afe2c77125f 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachine.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachine.java |
| @@ -8,11 +8,15 @@ import android.app.DialogFragment; |
| import android.app.Fragment; |
| import android.app.FragmentManager; |
| import android.content.Context; |
| +import android.content.DialogInterface; |
| +import android.os.CountDownTimer; |
| import android.support.annotation.IntDef; |
| +import android.support.v7.app.AlertDialog; |
| import android.text.TextUtils; |
| import org.chromium.base.Callback; |
| import org.chromium.base.Promise; |
| +import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.signin.ConfirmImportSyncDataDialog.ImportSyncType; |
| import java.lang.annotation.Retention; |
| @@ -60,8 +64,12 @@ public class ConfirmSyncDataStateMachine |
| private static final int AFTER_NEW_ACCOUNT_DIALOG = 2; // Start of state H. |
| private static final int DONE = 4; |
| + private static final int ACCOUNT_CHECK_TIMEOUT_MS = 10000; |
| + private static final int ACCOUNT_CHECK_RETRY_MS = 100; |
| + |
| private boolean mWipeData; |
| @State private int mState = BEFORE_OLD_ACCOUNT_DIALOG; |
| + private AlertDialog mTimeoutAlertDialog; |
| private final ConfirmImportSyncDataDialog.Listener mCallback; |
| private final String mOldAccountName; |
| @@ -166,6 +174,10 @@ public class ConfirmSyncDataStateMachine |
| mNewAccountManaged.then(new Callback<Boolean>() { |
| @Override |
| public void onResult(Boolean newAccountManaged) { |
| + if (mTimeoutAlertDialog != null) { |
| + mTimeoutAlertDialog.dismiss(); |
| + } |
| + if (mState == DONE) return; |
| if (newAccountManaged) { |
| // Show 'logging into managed account' dialog |
| // This will call back into onConfirm on success. |
| @@ -179,6 +191,9 @@ public class ConfirmSyncDataStateMachine |
| } |
| }); |
| + if (!mNewAccountManaged.isFulfilled()) { |
| + timingAccountCheck(); |
| + } |
| break; |
| case AFTER_NEW_ACCOUNT_DIALOG: |
| mState = DONE; |
| @@ -189,6 +204,55 @@ public class ConfirmSyncDataStateMachine |
| } |
| } |
| + private void timingAccountCheck() { |
| + new CountDownTimer(ACCOUNT_CHECK_TIMEOUT_MS, ACCOUNT_CHECK_RETRY_MS) { |
| + |
| + public void onTick(long millisUntilFinished) { |
| + if (mNewAccountManaged.isFulfilled()) { |
|
Bernhard Bauer
2016/10/04 10:11:02
You're polling the state of the Promise? Don't pol
|
| + cancel(); |
| + } |
| + } |
| + |
| + public void onFinish() { |
| + if (!mNewAccountManaged.isFulfilled()) { |
| + displayTimeoutAlertDialog(); |
| + } |
| + } |
| + }.start(); |
| + } |
| + |
| + private void displayTimeoutAlertDialog() { |
| + mTimeoutAlertDialog = |
| + new AlertDialog.Builder(mContext, R.style.AlertDialogTheme) |
| + .setTitle(mContext.getResources().getString(R.string.sign_in_timeout_title)) |
| + .setMessage( |
| + mContext.getResources().getString(R.string.sign_in_timeout_message)) |
| + .setNegativeButton(mContext.getResources().getString(R.string.cancel), |
| + new DialogInterface.OnClickListener() { |
| + @Override |
| + public void onClick(DialogInterface dialog, int which) { |
| + onCancel(); |
| + } |
| + }) |
| + .setPositiveButton(mContext.getResources().getString(R.string.retry), |
| + new DialogInterface.OnClickListener() { |
| + @Override |
| + public void onClick(DialogInterface dialog, int which) { |
| + timingAccountCheck(); |
|
Bernhard Bauer
2016/10/04 10:11:02
Oh, so "retry" doesn't actually abort the sign-in
|
| + } |
| + }) |
| + .create(); |
| + mTimeoutAlertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
| + @Override |
| + public void onDismiss(DialogInterface dialog) { |
| + mTimeoutAlertDialog = null; |
| + } |
| + }); |
| + mTimeoutAlertDialog.setCancelable(false); |
| + mTimeoutAlertDialog.setCanceledOnTouchOutside(false); |
| + mTimeoutAlertDialog.show(); |
| + } |
| + |
| // ConfirmImportSyncDataDialog.Listener implementation. |
| @Override |
| public void onConfirm(boolean wipeData) { |