1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | package org.chromium.chrome.browser.sync; |
6 | |
7 | import org.chromium.chrome.R; |
8 | |
9 | /** |
10 | * This class mirrors the native GoogleServiceAuthError class State enum from: |
11 | * google_apis/gaia/google_service_auth_error.h. |
12 | */ |
13 | public class GoogleServiceAuthError { |
14 | |
15 | public enum State { |
16 | // The user is authenticated. |
17 | NONE(0, R.string.sync_error_generic), |
18 | |
19 | // The credentials supplied to GAIA were either invalid, or the locally |
20 | // cached credentials have expired. |
21 | INVALID_GAIA_CREDENTIALS(1, R.string.sync_error_ga), |
22 | |
23 | // The GAIA user is not authorized to use the service. |
24 | USER_NOT_SIGNED_UP(2, R.string.sync_error_generic), |
25 | |
26 | // Could not connect to server to verify credentials. This could be in |
27 | // response to either failure to connect to GAIA or failure to connect to |
28 | // the service needing GAIA tokens during authentication. |
29 | CONNECTION_FAILED(3, R.string.sync_error_connection), |
30 | |
31 | // The user needs to satisfy a CAPTCHA challenge to unlock their account. |
32 | // If no other information is available, this can be resolved by visiting |
33 | // https://www.google.com/accounts/DisplayUnlockCaptcha. Otherwise, |
34 | // captcha() will provide details about the associated challenge. |
35 | CAPTCHA_REQUIRED(4, R.string.sync_error_generic), |
36 | |
37 | // The user account has been deleted. |
38 | ACCOUNT_DELETED(5, R.string.sync_error_generic), |
39 | |
40 | // The user account has been disabled. |
41 | ACCOUNT_DISABLED(6, R.string.sync_error_generic), |
42 | |
43 | // The service is not available; try again later. |
44 | SERVICE_UNAVAILABLE(7, R.string.sync_error_service_unavailable), |
45 | |
46 | // The password is valid but we need two factor to get a token. |
47 | TWO_FACTOR(8, R.string.sync_error_generic), |
48 | |
49 | // The requestor of the authentication step cancelled the request |
50 | // prior to completion. |
51 | REQUEST_CANCELED(9, R.string.sync_error_generic), |
52 | |
53 | // The user has provided a HOSTED account, when this service requires |
54 | // a GOOGLE account. |
55 | HOSTED_NOT_ALLOWED(10, R.string.sync_error_domain); |
56 | |
57 | private final int mCode; |
58 | private final int mMessage; |
59 | |
60 | State(int code, int message) { |
61 | mCode = code; |
62 | mMessage = message; |
63 | } |
64 | |
65 | public static State fromCode(int code) { |
66 | for (State state : State.values()) { |
67 | if (state.mCode == code) { |
68 | return state; |
69 | } |
70 | } |
71 | throw new IllegalArgumentException("No state for code: " + code); |
72 | } |
73 | |
74 | public int getMessage() { |
75 | return mMessage; |
76 | } |
77 | } |
78 | |
79 | private final State mState; |
80 | |
81 | GoogleServiceAuthError(int code) { |
82 | mState = State.fromCode(code); |
83 | } |
84 | |
85 | State getState() { |
86 | return mState; |
87 | } |
88 | } |