From d3a5ef1490acb34c1b13cc554f8876965a0bec53 Mon Sep 17 00:00:00 2001 From: maxbogue Date: Wed, 16 Sep 2015 02:59:10 -0700 Subject: [PATCH] [Sync] Some cleanup of AccountManagerHelper. - Remove deprecated getAuthTokenFromBackground. - Rename getAuthTokenFromForeground to getAuthToken. - Rename getNewAuthTokenFromForeground to getNewAuthToken. - Remove the unused Activity param from getAuthToken. BUG=488563 Review URL: https://codereview.chromium.org/1344093004 Cr-Commit-Position: refs/heads/master@{#349086} --- .../chrome/browser/signin/OAuth2TokenService.java | 10 ++--- .../invalidation/InvalidationClientService.java | 5 +-- .../chromium/sync/signin/AccountManagerHelper.java | 44 ++++++---------------- 3 files changed, 18 insertions(+), 41 deletions(-) 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 fb161a9b17c5..fdc1380ec5f0 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 @@ -148,8 +148,8 @@ public final class OAuth2TokenService String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope; AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context); - accountManagerHelper.getAuthTokenFromForeground( - null, account, oauth2Scope, new AccountManagerHelper.GetAuthTokenCallback() { + accountManagerHelper.getAuthToken( + account, oauth2Scope, new AccountManagerHelper.GetAuthTokenCallback() { @Override public void tokenAvailable(String token, boolean isTransientError) { nativeOAuth2TokenFetched(token, isTransientError, nativeCallback); @@ -169,8 +169,7 @@ public final class OAuth2TokenService Context context, @Nullable Activity activity, Account account, String scope, AccountManagerHelper.GetAuthTokenCallback callback) { String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope; - AccountManagerHelper.get(context).getAuthTokenFromForeground( - activity, account, oauth2Scope, callback); + AccountManagerHelper.get(context).getAuthToken(account, oauth2Scope, callback); } /** @@ -193,8 +192,7 @@ public final class OAuth2TokenService final AtomicReference result = new AtomicReference(); final Semaphore semaphore = new Semaphore(0); getOAuth2AccessToken( - context, activity, account, scope, - new AccountManagerHelper.GetAuthTokenCallback() { + context, activity, account, scope, new AccountManagerHelper.GetAuthTokenCallback() { @Override public void tokenAvailable(String token, boolean isTransientError) { result.set(token); diff --git a/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java b/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java index 2ea2bb67936b..c7694a5c641b 100644 --- a/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java +++ b/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java @@ -207,9 +207,8 @@ public class InvalidationClientService extends AndroidListener { // Attempt to retrieve a token for the user. This method will also invalidate // invalidAuthToken if it is non-null. - AccountManagerHelper.get(this).getNewAuthTokenFromForeground( - account, invalidAuthToken, getOAuth2ScopeWithType(), - new AccountManagerHelper.GetAuthTokenCallback() { + AccountManagerHelper.get(this).getNewAuthToken(account, invalidAuthToken, + getOAuth2ScopeWithType(), new AccountManagerHelper.GetAuthTokenCallback() { @Override public void tokenAvailable(String token, boolean isTransientError) { if (token != null) { diff --git a/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java b/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java index d10991ca5cc3..cdb61f579bcb 100644 --- a/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java +++ b/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java @@ -13,7 +13,6 @@ import android.accounts.AccountManagerFuture; import android.accounts.AuthenticatorDescription; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; -import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; import android.os.AsyncTask; @@ -34,16 +33,13 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; -import javax.annotation.Nullable; - /** * AccountManagerHelper wraps our access of AccountManager in Android. * * Use the AccountManagerHelper.get(someContext) to instantiate it */ public class AccountManagerHelper { - - private static final String TAG = "AccountManagerHelper"; + private static final String TAG = "cr.Sync.Signin"; private static final Pattern AT_SYMBOL = Pattern.compile("@"); @@ -227,32 +223,17 @@ public class AccountManagerHelper { } /** - * Gets the auth token synchronously. - * - * - Assumes that the account is a valid account. - * - Should not be called on the main thread. - */ - @Deprecated - public String getAuthTokenFromBackground(Account account, String authTokenType) { - AccountManagerFuture future = mAccountManager.getAuthToken( - account, authTokenType, true, null, null); - AtomicBoolean isTransientError = new AtomicBoolean(false); - return getAuthTokenInner(future, isTransientError); - } - - /** * Gets the auth token and returns the response asynchronously. * This should be called when we have a foreground activity that needs an auth token. * If encountered an IO error, it will attempt to retry when the network is back. * * - Assumes that the account is a valid account. */ - public void getAuthTokenFromForeground(Activity activity, Account account, String authTokenType, - GetAuthTokenCallback callback) { + public void getAuthToken(Account account, String authTokenType, GetAuthTokenCallback callback) { AtomicInteger numTries = new AtomicInteger(0); AtomicBoolean isTransientError = new AtomicBoolean(false); - getAuthTokenAsynchronously(activity, account, authTokenType, callback, numTries, - isTransientError, null); + getAuthTokenAsynchronously( + account, authTokenType, callback, numTries, isTransientError, null); } private class ConnectionRetry implements NetworkChangeNotifier.ConnectionTypeObserver { @@ -280,8 +261,8 @@ public class AccountManagerHelper { } if (NetworkChangeNotifier.isOnline()) { NetworkChangeNotifier.removeConnectionTypeObserver(this); - getAuthTokenAsynchronously(null, mAccount, mAuthTokenType, mCallback, mNumTries, - mIsTransientError, this); + getAuthTokenAsynchronously( + mAccount, mAuthTokenType, mCallback, mNumTries, mIsTransientError, this); } } } @@ -318,10 +299,9 @@ public class AccountManagerHelper { return null; } - private void getAuthTokenAsynchronously(@Nullable Activity activity, final Account account, - final String authTokenType, final GetAuthTokenCallback callback, - final AtomicInteger numTries, final AtomicBoolean isTransientError, - final ConnectionRetry retry) { + private void getAuthTokenAsynchronously(final Account account, final String authTokenType, + final GetAuthTokenCallback callback, final AtomicInteger numTries, + final AtomicBoolean isTransientError, final ConnectionRetry retry) { // Return null token for no USE_CREDENTIALS permission. if (!hasUseCredentialsPermission()) { ThreadUtils.runOnUiThread(new Runnable() { @@ -372,13 +352,13 @@ public class AccountManagerHelper { * * - Assumes that the account is a valid account. */ - public void getNewAuthTokenFromForeground(Account account, String authToken, - String authTokenType, GetAuthTokenCallback callback) { + public void getNewAuthToken(Account account, String authToken, String authTokenType, + GetAuthTokenCallback callback) { invalidateAuthToken(authToken); AtomicInteger numTries = new AtomicInteger(0); AtomicBoolean isTransientError = new AtomicBoolean(false); getAuthTokenAsynchronously( - null, account, authTokenType, callback, numTries, isTransientError, null); + account, authTokenType, callback, numTries, isTransientError, null); } /** -- 2.11.4.GIT