OLD | NEW |
| (Empty) |
1 // Copyright 2015 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.blimp.auth; | |
6 | |
7 import android.content.Intent; | |
8 | |
9 import com.google.android.gms.common.ConnectionResult; | |
10 | |
11 /** | |
12 * Interface for an object that can asynchronously retrieve and invalidate user
authentication | |
13 * tokens. | |
14 */ | |
15 public interface TokenSource { | |
16 /** | |
17 * Used to get results of {@link TokenSource#getToken()} attempts. | |
18 */ | |
19 public interface Callback { | |
20 /** | |
21 * A token was successfully received. | |
22 * @param token The token. | |
23 */ | |
24 void onTokenReceived(String token); | |
25 | |
26 /** | |
27 * A token was unable to be retrieved. | |
28 * @param isTransient Whether or not the failure is recoverable or not. | |
29 */ | |
30 void onTokenUnavailable(boolean isTransient); | |
31 | |
32 /** | |
33 * There is no selected user account on the device. By triggering {@cod
e intent} with a | |
34 * result (via {@link android.app.Activity#startActivityForResult(Intent
, int)) the calling | |
35 * {@code android.app.Activity} can show an account chooser to the user.
The resulting | |
36 * {@link Intent} should be passed to the {@link TokenSource} via | |
37 * {@link TokenSource#onAccountSelected(Intent)}. | |
38 * @param intent The {@link Intent} to start to have the user select an
account. | |
39 */ | |
40 void onNeedsAccountToBeSelected(Intent intent); | |
41 } | |
42 | |
43 /** | |
44 * Destroys all internal state and stops (if possible) any outstanding | |
45 * {@link TokenSource#getToken()} attempts. | |
46 */ | |
47 void destroy(); | |
48 | |
49 /** | |
50 * TODO(dtrainor): Rework this to move the Account and Callback into getToke
n() (crbug/537728). | |
51 * Sets the {@link Callback} that will be notified of the results of {@link
getToken()} calls. | |
52 * @param callback The {@link Callback} to notify. | |
53 */ | |
54 void setCallback(Callback callback); | |
55 | |
56 /** | |
57 * Starts off a process of getting an authentication token for the selected
account for this | |
58 * application. If this is called before finishing, it should cancel the ou
tstanding request | |
59 * and start a new one. See {@link Callback} for specific details of each p
ossible callback | |
60 * outcome. | |
61 * - If no account is selected, {@link Callback#onNeedsAccountToBeSelected(I
ntent)} will be | |
62 * called. | |
63 * - If getting the token fails, {@link Callback#onTokenUnavailable(boolean)
} will be called. | |
64 * - If getting the token is successful, {@link Callback#onTokenReceived(Str
ing)} will be | |
65 * called. | |
66 */ | |
67 void getToken(); | |
68 | |
69 /** | |
70 * @return Whether or not this {@link TokenSource} is currently trying to re
trieve a token. | |
71 */ | |
72 boolean isRetrievingToken(); | |
73 | |
74 /** | |
75 * Notifies this {@link TokenSource} that the token it returned is invalid.
This won't | |
76 * automatically trigger another {@link #getToken()} attempt. | |
77 * @param token The token that is invalid and should be removed from the und
erlying token cache. | |
78 * @return The result code of the attempted invalidation (see {@link Co
nnectionResult}. | |
79 */ | |
80 int tokenIsInvalid(String token); | |
81 | |
82 /** | |
83 * Notifies this {@link TokenSource} of a response from the {@link Intent} s
ent through | |
84 * {@link Callback#onNeedsAccountToBeSelected(Intent)}. The selected accoun
t will be parsed and | |
85 * saved. This won't automatically trigger another {@link #getToken()} atte
mpt. | |
86 * @param data The response {@link Intent} data. | |
87 */ | |
88 void onAccountSelected(Intent data); | |
89 } | |
OLD | NEW |