OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.signin; | 5 package org.chromium.chrome.browser.signin; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.util.Log; | 10 import android.util.Log; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(con
text); | 44 AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(con
text); |
45 Account account = accountManagerHelper.getAccountFromName(username); | 45 Account account = accountManagerHelper.getAccountFromName(username); |
46 if (account == null) { | 46 if (account == null) { |
47 Log.e(TAG, "Account not found for provided username."); | 47 Log.e(TAG, "Account not found for provided username."); |
48 return null; | 48 return null; |
49 } | 49 } |
50 return account; | 50 return account; |
51 } | 51 } |
52 | 52 |
53 /** | 53 /** |
| 54 * Called by native to list the accounts with OAuth2 refresh tokens. |
| 55 */ |
| 56 @CalledByNative |
| 57 public static String[] getAccounts(Context context) { |
| 58 AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(con
text); |
| 59 java.util.List<String> accountNames = accountManagerHelper.getGoogleAcco
untNames(); |
| 60 return accountNames.toArray(new String[accountNames.size()]); |
| 61 } |
| 62 |
| 63 /** |
54 * Called by native to retrieve OAuth2 tokens. | 64 * Called by native to retrieve OAuth2 tokens. |
55 * | 65 * |
56 * @param username The native username (full address). | 66 * @param username The native username (full address). |
57 * @param scope The scope to get an auth token for (without Android-style 'o
auth2:' prefix). | 67 * @param scope The scope to get an auth token for (without Android-style 'o
auth2:' prefix). |
58 * @param nativeCallback The pointer to the native callback that should be r
un upon completion. | 68 * @param nativeCallback The pointer to the native callback that should be r
un upon completion. |
59 */ | 69 */ |
60 @CalledByNative | 70 @CalledByNative |
61 public static void getOAuth2AuthToken( | 71 public static void getOAuth2AuthToken( |
62 Context context, String username, String scope, final int nativeCall
back) { | 72 Context context, String username, String scope, final int nativeCall
back) { |
63 Account account = getAccountOrNullFromUsername(context, username); | 73 Account account = getAccountOrNullFromUsername(context, username); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 timeout + " + " + unit.name() + ")"); | 139 timeout + " + " + unit.name() + ")"); |
130 return null; | 140 return null; |
131 } | 141 } |
132 } catch (InterruptedException e) { | 142 } catch (InterruptedException e) { |
133 Log.w(TAG, "Got interrupted while waiting for auth token"); | 143 Log.w(TAG, "Got interrupted while waiting for auth token"); |
134 return null; | 144 return null; |
135 } | 145 } |
136 } | 146 } |
137 | 147 |
138 /** | 148 /** |
| 149 * Called by native to check wether the account has an OAuth2 refresh token. |
| 150 */ |
| 151 @CalledByNative |
| 152 public static boolean hasOAuth2RefreshToken(Context context, String accountN
ame) { |
| 153 return AccountManagerHelper.get(context).hasAccountForName(accountName); |
| 154 } |
| 155 |
| 156 /** |
139 * Called by native to invalidate an OAuth2 token. | 157 * Called by native to invalidate an OAuth2 token. |
140 */ | 158 */ |
141 @CalledByNative | 159 @CalledByNative |
142 public static void invalidateOAuth2AuthToken(Context context, String accessT
oken) { | 160 public static void invalidateOAuth2AuthToken(Context context, String accessT
oken) { |
143 if (accessToken != null) { | 161 if (accessToken != null) { |
144 AccountManagerHelper.get(context).invalidateAuthToken(accessToken); | 162 AccountManagerHelper.get(context).invalidateAuthToken(accessToken); |
145 } | 163 } |
146 } | 164 } |
147 | 165 |
148 private static native void nativeOAuth2TokenFetched( | 166 private static native void nativeOAuth2TokenFetched( |
149 String authToken, boolean result, int nativeCallback); | 167 String authToken, boolean result, int nativeCallback); |
150 | 168 |
151 } | 169 } |
OLD | NEW |