Commit 1bfabdd7 authored by bzanotti's avatar bzanotti Committed by Commit bot

[SignIn] Fix AccountSigninView for asynchronous updateAccounts()

updateAccounts() now takes a callback to allow code to run once the
accounts have actually been fetched.

This also adds some check in updateAccounts() to ensure it only updates
the accounts when expected (i.e. when the user isn't signed in).

BUG=678543,672255

Review-Url: https://codereview.chromium.org/2616643005
Cr-Commit-Position: refs/heads/master@{#442932}
parent 447bdcac
......@@ -226,13 +226,31 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
}
/**
* Refresh the list of available system accounts.
* Refresh the list of available system accounts asynchronously. This is a convenience method
* that will ignore whether the accounts updating was actually successful.
*/
private void updateAccounts() {
if (mSignedIn || mProfileData == null) return;
updateAccounts(new Callback<Boolean>() {
@Override
public void onResult(Boolean result) {}
});
}
/**
* Refresh the list of available system accounts asynchronously.
*
* @param callback Called once the accounts have been refreshed. Boolean indicates whether the
* accounts haven been successfully updated.
*/
private void updateAccounts(final Callback<Boolean> callback) {
if (mSignedIn || mProfileData == null) {
callback.onResult(false);
return;
}
if (!checkGooglePlayServicesAvailable()) {
setUpSigninButton(false);
callback.onResult(false);
return;
}
......@@ -256,6 +274,13 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
updatingGmsDialog.dismiss();
}
mIsGooglePlayServicesOutOfDate = false;
if (mSignedIn) {
// If sign-in completed in the mean time, return in order to avoid showing the
// wrong state in the UI.
return;
}
mAccountNames = result;
int accountToSelect = 0;
......@@ -263,6 +288,7 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
accountToSelect = mAccountNames.indexOf(mForcedAccountName);
if (accountToSelect < 0) {
mListener.onFailedToSetForcedAccount(mForcedAccountName);
callback.onResult(false);
return;
}
} else {
......@@ -275,6 +301,7 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
mSigninChooseView.updateAccounts(mAccountNames, accountToSelect, mProfileData);
if (mAccountNames.isEmpty()) {
setUpSigninButton(false);
callback.onResult(true);
return;
}
setUpSigninButton(true);
......@@ -283,7 +310,10 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
// Determine how the accounts have changed. Each list should only have unique
// elements.
if (oldAccountNames == null || oldAccountNames.isEmpty()) return;
if (oldAccountNames == null || oldAccountNames.isEmpty()) {
callback.onResult(true);
return;
}
if (!mAccountNames.get(accountToSelect).equals(
oldAccountNames.get(oldSelectedAccount))) {
......@@ -299,7 +329,7 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
showConfirmSigninPageAccountTrackerServiceCheck();
}
}
callback.onResult(true);
}
});
}
......@@ -568,11 +598,16 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
*/
public void switchToForcedAccountMode(String forcedAccountName) {
mForcedAccountName = forcedAccountName;
updateAccounts();
updateAccounts(new Callback<Boolean>() {
@Override
public void onResult(Boolean result) {
if (!result) return;
assert TextUtils.equals(getSelectedAccountName(), mForcedAccountName);
switchToSignedMode();
assert TextUtils.equals(getSelectedAccountName(), mForcedAccountName);
}
});
}
/**
* @return Whether the view is in signed in mode.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment