Commit 5a7ffae7 authored by estevenson's avatar estevenson Committed by Commit bot

Signin: Reuse existing "update gms" dialogs when possible.

Currently, |updateAccounts()| is sometimes called multiple times in
AccountSigninView which results in multiple "update GMS" dialogs being
generated, and the user must click back three times for the dialogs to
disappear.

This CL changes signin to re-use existing dialogs where possible and
always remove old dialogs before creating a new one.

BUG=679851

Review-Url: https://codereview.chromium.org/2626083004
Cr-Commit-Position: refs/heads/master@{#443349}
parent d8a99a80
......@@ -137,6 +137,11 @@ public abstract class UserRecoverableErrorHandler {
*/
private final boolean mCancelable;
/**
* Last error code from Google Play Services.
*/
private int mErrorCode;
/**
* Create a new Modal Dialog handler for the specified activity and error code. The
* specified activity may be used to launch the dialog via
......@@ -159,8 +164,16 @@ public abstract class UserRecoverableErrorHandler {
*/
@Override
protected final void handle(final Context context, final int errorCode) {
mDialog = GoogleApiAvailability.getInstance().getErrorDialog(
mActivity, errorCode, NO_RESPONSE_REQUIRED);
// Assume old dialogs generated by the same error handler are obsolete when an error
// with a different error code is encountered.
if (mErrorCode != errorCode) {
cancelDialog();
}
if (mDialog == null) {
mDialog = GoogleApiAvailability.getInstance().getErrorDialog(
mActivity, errorCode, NO_RESPONSE_REQUIRED);
mErrorCode = errorCode;
}
// This can happen if |errorCode| is ConnectionResult.SERVICE_INVALID.
if (mDialog != null) {
mDialog.setCancelable(mCancelable);
......@@ -175,6 +188,7 @@ public abstract class UserRecoverableErrorHandler {
public void cancelDialog() {
if (mDialog != null) {
mDialog.cancel();
mDialog = null;
}
}
}
......
......@@ -336,9 +336,11 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
private boolean checkGooglePlayServicesAvailable() {
ExternalAuthUtils extAuthUtils = ExternalAuthUtils.getInstance();
boolean cancelable = !SigninManager.get(getContext()).isForceSigninEnabled();
mGooglePlayServicesUpdateErrorHandler = new UserRecoverableErrorHandler.ModalDialog(
mDelegate.getActivity(), cancelable);
if (mGooglePlayServicesUpdateErrorHandler == null) {
boolean cancelable = !SigninManager.get(getContext()).isForceSigninEnabled();
mGooglePlayServicesUpdateErrorHandler = new UserRecoverableErrorHandler.ModalDialog(
mDelegate.getActivity(), cancelable);
}
int resultCode = extAuthUtils.canUseGooglePlayServicesResultCode(
getContext(), mGooglePlayServicesUpdateErrorHandler);
if (extAuthUtils.isGooglePlayServicesUpdateRequiredError(resultCode)) {
......
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