michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.fxa.login; michael@0: michael@0: import org.mozilla.gecko.background.fxa.FxAccountClient10; michael@0: import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException; michael@0: import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate; michael@0: import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.AccountNeedsVerification; michael@0: import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.LocalError; michael@0: import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.RemoteError; michael@0: michael@0: public abstract class BaseRequestDelegate implements FxAccountClient10.RequestDelegate { michael@0: protected final ExecuteDelegate delegate; michael@0: protected final State state; michael@0: michael@0: public BaseRequestDelegate(State state, ExecuteDelegate delegate) { michael@0: this.delegate = delegate; michael@0: this.state = state; michael@0: } michael@0: michael@0: @Override michael@0: public void handleFailure(FxAccountClientRemoteException e) { michael@0: // Order matters here: we don't want to ignore upgrade required responses michael@0: // even if the server tells us something else as well. We don't go directly michael@0: // to the Doghouse on upgrade required; we want the user to try to update michael@0: // their credentials, and then display UI telling them they need to upgrade. michael@0: // Then they go to the Doghouse. michael@0: if (e.isUpgradeRequired()) { michael@0: delegate.handleTransition(new RemoteError(e), new Separated(state.email, state.uid, state.verified)); michael@0: return; michael@0: } michael@0: if (e.isInvalidAuthentication()) { michael@0: delegate.handleTransition(new RemoteError(e), new Separated(state.email, state.uid, state.verified)); michael@0: return; michael@0: } michael@0: if (e.isUnverified()) { michael@0: delegate.handleTransition(new AccountNeedsVerification(), state); michael@0: return; michael@0: } michael@0: delegate.handleTransition(new RemoteError(e), state); michael@0: } michael@0: michael@0: @Override michael@0: public void handleError(Exception e) { michael@0: delegate.handleTransition(new LocalError(e), state); michael@0: } michael@0: }