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