mobile/android/base/fxa/login/BaseRequestDelegate.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/fxa/login/BaseRequestDelegate.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.fxa.login;
     1.9 +
    1.10 +import org.mozilla.gecko.background.fxa.FxAccountClient10;
    1.11 +import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException;
    1.12 +import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate;
    1.13 +import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.AccountNeedsVerification;
    1.14 +import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.LocalError;
    1.15 +import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.RemoteError;
    1.16 +
    1.17 +public abstract class BaseRequestDelegate<T> implements FxAccountClient10.RequestDelegate<T> {
    1.18 +  protected final ExecuteDelegate delegate;
    1.19 +  protected final State state;
    1.20 +
    1.21 +  public BaseRequestDelegate(State state, ExecuteDelegate delegate) {
    1.22 +    this.delegate = delegate;
    1.23 +    this.state = state;
    1.24 +  }
    1.25 +
    1.26 +  @Override
    1.27 +  public void handleFailure(FxAccountClientRemoteException e) {
    1.28 +    // Order matters here: we don't want to ignore upgrade required responses
    1.29 +    // even if the server tells us something else as well. We don't go directly
    1.30 +    // to the Doghouse on upgrade required; we want the user to try to update
    1.31 +    // their credentials, and then display UI telling them they need to upgrade.
    1.32 +    // Then they go to the Doghouse.
    1.33 +    if (e.isUpgradeRequired()) {
    1.34 +      delegate.handleTransition(new RemoteError(e), new Separated(state.email, state.uid, state.verified));
    1.35 +      return;
    1.36 +    }
    1.37 +    if (e.isInvalidAuthentication()) {
    1.38 +      delegate.handleTransition(new RemoteError(e), new Separated(state.email, state.uid, state.verified));
    1.39 +      return;
    1.40 +    }
    1.41 +    if (e.isUnverified()) {
    1.42 +      delegate.handleTransition(new AccountNeedsVerification(), state);
    1.43 +      return;
    1.44 +    }
    1.45 +    delegate.handleTransition(new RemoteError(e), state);
    1.46 +  }
    1.47 +
    1.48 +  @Override
    1.49 +  public void handleError(Exception e) {
    1.50 +    delegate.handleTransition(new LocalError(e), state);
    1.51 +  }
    1.52 +}

mercurial