| Index: chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java
|
| index 9e9c8ccdb5356ebba162138002e3a1617d955c06..8b52fd4c1c4e9dbf3fcaf4a048b320931b52db27 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java
|
| @@ -51,16 +51,16 @@ public final class OAuth2TokenService
|
|
|
| private static final String OAUTH2_SCOPE_PREFIX = "oauth2:";
|
|
|
| - private Context mPendingValidationContext;
|
| + private boolean mPendingValidation;
|
| private boolean mPendingValidationForceNotifications;
|
|
|
| private final long mNativeOAuth2TokenServiceDelegateAndroid;
|
| private final ObserverList<OAuth2TokenServiceObserver> mObservers;
|
|
|
| - private OAuth2TokenService(Context context, long nativeOAuth2Service) {
|
| + private OAuth2TokenService(long nativeOAuth2Service) {
|
| mNativeOAuth2TokenServiceDelegateAndroid = nativeOAuth2Service;
|
| mObservers = new ObserverList<OAuth2TokenServiceObserver>();
|
| - AccountTrackerService.get(context).addSystemAccountsSeededListener(this);
|
| + AccountTrackerService.get().addSystemAccountsSeededListener(this);
|
| }
|
|
|
| public static OAuth2TokenService getForProfile(Profile profile) {
|
| @@ -69,9 +69,9 @@ public final class OAuth2TokenService
|
| }
|
|
|
| @CalledByNative
|
| - private static OAuth2TokenService create(Context context, long nativeOAuth2Service) {
|
| + private static OAuth2TokenService create(long nativeOAuth2Service) {
|
| ThreadUtils.assertOnUiThread();
|
| - return new OAuth2TokenService(context, nativeOAuth2Service);
|
| + return new OAuth2TokenService(nativeOAuth2Service);
|
| }
|
|
|
| @VisibleForTesting
|
| @@ -86,13 +86,13 @@ public final class OAuth2TokenService
|
| mObservers.removeObserver(observer);
|
| }
|
|
|
| - private static Account getAccountOrNullFromUsername(Context context, String username) {
|
| + private static Account getAccountOrNullFromUsername(String username) {
|
| if (username == null) {
|
| Log.e(TAG, "Username is null");
|
| return null;
|
| }
|
|
|
| - AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
|
| + AccountManagerHelper accountManagerHelper = AccountManagerHelper.get();
|
| Account account = accountManagerHelper.getAccountFromName(username);
|
| if (account == null) {
|
| Log.e(TAG, "Account not found for provided username.");
|
| @@ -106,8 +106,8 @@ public final class OAuth2TokenService
|
| */
|
| @VisibleForTesting
|
| @CalledByNative
|
| - public static String[] getSystemAccountNames(Context context) {
|
| - AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
|
| + public static String[] getSystemAccountNames() {
|
| + AccountManagerHelper accountManagerHelper = AccountManagerHelper.get();
|
| java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames();
|
| return accountNames.toArray(new String[accountNames.size()]);
|
| }
|
| @@ -119,21 +119,20 @@ public final class OAuth2TokenService
|
| * in sync.
|
| */
|
| @CalledByNative
|
| - public static String[] getAccounts(Context context) {
|
| - return getStoredAccounts(context);
|
| + public static String[] getAccounts() {
|
| + return getStoredAccounts();
|
| }
|
|
|
| /**
|
| * Called by native to retrieve OAuth2 tokens.
|
| - *
|
| - * @param username The native username (full address).
|
| + * @param username The native username (full address).
|
| * @param scope The scope to get an auth token for (without Android-style 'oauth2:' prefix).
|
| * @param nativeCallback The pointer to the native callback that should be run upon completion.
|
| */
|
| @CalledByNative
|
| public static void getOAuth2AuthToken(
|
| - Context context, String username, String scope, final long nativeCallback) {
|
| - Account account = getAccountOrNullFromUsername(context, username);
|
| + String username, String scope, final long nativeCallback) {
|
| + Account account = getAccountOrNullFromUsername(username);
|
| if (account == null) {
|
| ThreadUtils.postOnUiThread(new Runnable() {
|
| @Override
|
| @@ -145,7 +144,7 @@ public final class OAuth2TokenService
|
| }
|
| String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;
|
|
|
| - AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
|
| + AccountManagerHelper accountManagerHelper = AccountManagerHelper.get();
|
| accountManagerHelper.getAuthToken(
|
| account, oauth2Scope, new AccountManagerHelper.GetAuthTokenCallback() {
|
| @Override
|
| @@ -170,7 +169,7 @@ public final class OAuth2TokenService
|
| public static void getOAuth2AccessToken(Context context, Account account, String scope,
|
| AccountManagerHelper.GetAuthTokenCallback callback) {
|
| String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;
|
| - AccountManagerHelper.get(context).getAuthToken(account, oauth2Scope, callback);
|
| + AccountManagerHelper.get().getAuthToken(account, oauth2Scope, callback);
|
| }
|
|
|
| /**
|
| @@ -222,13 +221,13 @@ public final class OAuth2TokenService
|
| * Called by native to check wether the account has an OAuth2 refresh token.
|
| */
|
| @CalledByNative
|
| - public static boolean hasOAuth2RefreshToken(Context context, String accountName) {
|
| + public static boolean hasOAuth2RefreshToken(String accountName) {
|
| // Temporarily allowing disk read while fixing. TODO: http://crbug.com/618096.
|
| // This function is called in RefreshTokenIsAvailable of OAuth2TokenService which is
|
| // expected to be called in the UI thread synchronously.
|
| StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
|
| try {
|
| - return AccountManagerHelper.get(context).hasAccountForName(accountName);
|
| + return AccountManagerHelper.get().hasAccountForName(accountName);
|
| } finally {
|
| StrictMode.setThreadPolicy(oldPolicy);
|
| }
|
| @@ -238,9 +237,9 @@ public final class OAuth2TokenService
|
| * Called by native to invalidate an OAuth2 token.
|
| */
|
| @CalledByNative
|
| - public static void invalidateOAuth2AuthToken(Context context, String accessToken) {
|
| + public static void invalidateOAuth2AuthToken(String accessToken) {
|
| if (accessToken != null) {
|
| - AccountManagerHelper.get(context).invalidateAuthToken(accessToken);
|
| + AccountManagerHelper.get().invalidateAuthToken(accessToken);
|
| }
|
| }
|
|
|
| @@ -250,10 +249,9 @@ public final class OAuth2TokenService
|
| */
|
| @Override
|
| public void onSystemAccountsSeedingComplete() {
|
| - if (mPendingValidationContext != null) {
|
| - validateAccountsWithSignedInAccountName(
|
| - mPendingValidationContext, mPendingValidationForceNotifications);
|
| - mPendingValidationContext = null;
|
| + if (mPendingValidation) {
|
| + validateAccountsWithSignedInAccountName(mPendingValidationForceNotifications);
|
| + mPendingValidation = false;
|
| mPendingValidationForceNotifications = false;
|
| }
|
| }
|
| @@ -264,28 +262,25 @@ public final class OAuth2TokenService
|
| */
|
| @Override
|
| public void onSystemAccountsChanged() {
|
| - mPendingValidationContext = null;
|
| mPendingValidationForceNotifications = false;
|
| }
|
|
|
| @CalledByNative
|
| - public void validateAccounts(Context context, boolean forceNotifications) {
|
| + public void validateAccounts(boolean forceNotifications) {
|
| ThreadUtils.assertOnUiThread();
|
| - if (!AccountTrackerService.get(context).checkAndSeedSystemAccounts()) {
|
| - mPendingValidationContext = context;
|
| + if (!AccountTrackerService.get().checkAndSeedSystemAccounts()) {
|
| + mPendingValidation = true;
|
| mPendingValidationForceNotifications = forceNotifications;
|
| return;
|
| }
|
|
|
| - validateAccountsWithSignedInAccountName(context, forceNotifications);
|
| + validateAccountsWithSignedInAccountName(forceNotifications);
|
| }
|
|
|
| - private void validateAccountsWithSignedInAccountName(
|
| - Context context, boolean forceNotifications) {
|
| - String currentlySignedInAccount =
|
| - ChromeSigninController.get(context).getSignedInAccountName();
|
| + private void validateAccountsWithSignedInAccountName(boolean forceNotifications) {
|
| + String currentlySignedInAccount = ChromeSigninController.get().getSignedInAccountName();
|
| if (currentlySignedInAccount != null
|
| - && isSignedInAccountChanged(context, currentlySignedInAccount)) {
|
| + && isSignedInAccountChanged(currentlySignedInAccount)) {
|
| // Set currentlySignedInAccount to null for validation if signed-in account was changed
|
| // (renamed or removed from the device), this will cause all credentials in token
|
| // service be revoked.
|
| @@ -298,8 +293,8 @@ public final class OAuth2TokenService
|
| forceNotifications);
|
| }
|
|
|
| - private boolean isSignedInAccountChanged(Context context, String signedInAccountName) {
|
| - String[] accountNames = getSystemAccountNames(context);
|
| + private boolean isSignedInAccountChanged(String signedInAccountName) {
|
| + String[] accountNames = getSystemAccountNames();
|
| for (String accountName : accountNames) {
|
| if (accountName.equals(signedInAccountName)) return false;
|
| }
|
| @@ -366,15 +361,14 @@ public final class OAuth2TokenService
|
| }
|
| }
|
|
|
| - private static String[] getStoredAccounts(Context context) {
|
| + private static String[] getStoredAccounts() {
|
| Set<String> accounts =
|
| - ContextUtils.getAppSharedPreferences()
|
| - .getStringSet(STORED_ACCOUNTS_KEY, null);
|
| + ContextUtils.getAppSharedPreferences().getStringSet(STORED_ACCOUNTS_KEY, null);
|
| return accounts == null ? new String[]{} : accounts.toArray(new String[accounts.size()]);
|
| }
|
|
|
| @CalledByNative
|
| - private static void saveStoredAccounts(Context context, String[] accounts) {
|
| + private static void saveStoredAccounts(String[] accounts) {
|
| Set<String> set = new HashSet<String>(Arrays.asList(accounts));
|
| ContextUtils.getAppSharedPreferences().edit()
|
| .putStringSet(STORED_ACCOUNTS_KEY, set).apply();
|
|
|