Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.fxa.login; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.background.fxa.FxAccountClient10; |
michael@0 | 8 | import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException; |
michael@0 | 9 | import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate; |
michael@0 | 10 | import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.AccountNeedsVerification; |
michael@0 | 11 | import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.LocalError; |
michael@0 | 12 | import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.RemoteError; |
michael@0 | 13 | |
michael@0 | 14 | public abstract class BaseRequestDelegate<T> implements FxAccountClient10.RequestDelegate<T> { |
michael@0 | 15 | protected final ExecuteDelegate delegate; |
michael@0 | 16 | protected final State state; |
michael@0 | 17 | |
michael@0 | 18 | public BaseRequestDelegate(State state, ExecuteDelegate delegate) { |
michael@0 | 19 | this.delegate = delegate; |
michael@0 | 20 | this.state = state; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | @Override |
michael@0 | 24 | public void handleFailure(FxAccountClientRemoteException e) { |
michael@0 | 25 | // Order matters here: we don't want to ignore upgrade required responses |
michael@0 | 26 | // even if the server tells us something else as well. We don't go directly |
michael@0 | 27 | // to the Doghouse on upgrade required; we want the user to try to update |
michael@0 | 28 | // their credentials, and then display UI telling them they need to upgrade. |
michael@0 | 29 | // Then they go to the Doghouse. |
michael@0 | 30 | if (e.isUpgradeRequired()) { |
michael@0 | 31 | delegate.handleTransition(new RemoteError(e), new Separated(state.email, state.uid, state.verified)); |
michael@0 | 32 | return; |
michael@0 | 33 | } |
michael@0 | 34 | if (e.isInvalidAuthentication()) { |
michael@0 | 35 | delegate.handleTransition(new RemoteError(e), new Separated(state.email, state.uid, state.verified)); |
michael@0 | 36 | return; |
michael@0 | 37 | } |
michael@0 | 38 | if (e.isUnverified()) { |
michael@0 | 39 | delegate.handleTransition(new AccountNeedsVerification(), state); |
michael@0 | 40 | return; |
michael@0 | 41 | } |
michael@0 | 42 | delegate.handleTransition(new RemoteError(e), state); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | @Override |
michael@0 | 46 | public void handleError(Exception e) { |
michael@0 | 47 | delegate.handleTransition(new LocalError(e), state); |
michael@0 | 48 | } |
michael@0 | 49 | } |