| 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 8b52fd4c1c4e9dbf3fcaf4a048b320931b52db27..9e9c8ccdb5356ebba162138002e3a1617d955c06 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 @@
|
|
|
| private static final String OAUTH2_SCOPE_PREFIX = "oauth2:";
|
|
|
| - private boolean mPendingValidation;
|
| + private Context mPendingValidationContext;
|
| private boolean mPendingValidationForceNotifications;
|
|
|
| private final long mNativeOAuth2TokenServiceDelegateAndroid;
|
| private final ObserverList<OAuth2TokenServiceObserver> mObservers;
|
|
|
| - private OAuth2TokenService(long nativeOAuth2Service) {
|
| + private OAuth2TokenService(Context context, long nativeOAuth2Service) {
|
| mNativeOAuth2TokenServiceDelegateAndroid = nativeOAuth2Service;
|
| mObservers = new ObserverList<OAuth2TokenServiceObserver>();
|
| - AccountTrackerService.get().addSystemAccountsSeededListener(this);
|
| + AccountTrackerService.get(context).addSystemAccountsSeededListener(this);
|
| }
|
|
|
| public static OAuth2TokenService getForProfile(Profile profile) {
|
| @@ -69,9 +69,9 @@
|
| }
|
|
|
| @CalledByNative
|
| - private static OAuth2TokenService create(long nativeOAuth2Service) {
|
| - ThreadUtils.assertOnUiThread();
|
| - return new OAuth2TokenService(nativeOAuth2Service);
|
| + private static OAuth2TokenService create(Context context, long nativeOAuth2Service) {
|
| + ThreadUtils.assertOnUiThread();
|
| + return new OAuth2TokenService(context, nativeOAuth2Service);
|
| }
|
|
|
| @VisibleForTesting
|
| @@ -86,13 +86,13 @@
|
| mObservers.removeObserver(observer);
|
| }
|
|
|
| - private static Account getAccountOrNullFromUsername(String username) {
|
| + private static Account getAccountOrNullFromUsername(Context context, String username) {
|
| if (username == null) {
|
| Log.e(TAG, "Username is null");
|
| return null;
|
| }
|
|
|
| - AccountManagerHelper accountManagerHelper = AccountManagerHelper.get();
|
| + AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
|
| Account account = accountManagerHelper.getAccountFromName(username);
|
| if (account == null) {
|
| Log.e(TAG, "Account not found for provided username.");
|
| @@ -106,8 +106,8 @@
|
| */
|
| @VisibleForTesting
|
| @CalledByNative
|
| - public static String[] getSystemAccountNames() {
|
| - AccountManagerHelper accountManagerHelper = AccountManagerHelper.get();
|
| + public static String[] getSystemAccountNames(Context context) {
|
| + AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
|
| java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames();
|
| return accountNames.toArray(new String[accountNames.size()]);
|
| }
|
| @@ -119,20 +119,21 @@
|
| * in sync.
|
| */
|
| @CalledByNative
|
| - public static String[] getAccounts() {
|
| - return getStoredAccounts();
|
| + public static String[] getAccounts(Context context) {
|
| + return getStoredAccounts(context);
|
| }
|
|
|
| /**
|
| * 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(
|
| - String username, String scope, final long nativeCallback) {
|
| - Account account = getAccountOrNullFromUsername(username);
|
| + Context context, String username, String scope, final long nativeCallback) {
|
| + Account account = getAccountOrNullFromUsername(context, username);
|
| if (account == null) {
|
| ThreadUtils.postOnUiThread(new Runnable() {
|
| @Override
|
| @@ -144,7 +145,7 @@
|
| }
|
| String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;
|
|
|
| - AccountManagerHelper accountManagerHelper = AccountManagerHelper.get();
|
| + AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
|
| accountManagerHelper.getAuthToken(
|
| account, oauth2Scope, new AccountManagerHelper.GetAuthTokenCallback() {
|
| @Override
|
| @@ -169,7 +170,7 @@
|
| public static void getOAuth2AccessToken(Context context, Account account, String scope,
|
| AccountManagerHelper.GetAuthTokenCallback callback) {
|
| String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;
|
| - AccountManagerHelper.get().getAuthToken(account, oauth2Scope, callback);
|
| + AccountManagerHelper.get(context).getAuthToken(account, oauth2Scope, callback);
|
| }
|
|
|
| /**
|
| @@ -221,13 +222,13 @@
|
| * Called by native to check wether the account has an OAuth2 refresh token.
|
| */
|
| @CalledByNative
|
| - public static boolean hasOAuth2RefreshToken(String accountName) {
|
| + public static boolean hasOAuth2RefreshToken(Context context, 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().hasAccountForName(accountName);
|
| + return AccountManagerHelper.get(context).hasAccountForName(accountName);
|
| } finally {
|
| StrictMode.setThreadPolicy(oldPolicy);
|
| }
|
| @@ -237,9 +238,9 @@
|
| * Called by native to invalidate an OAuth2 token.
|
| */
|
| @CalledByNative
|
| - public static void invalidateOAuth2AuthToken(String accessToken) {
|
| + public static void invalidateOAuth2AuthToken(Context context, String accessToken) {
|
| if (accessToken != null) {
|
| - AccountManagerHelper.get().invalidateAuthToken(accessToken);
|
| + AccountManagerHelper.get(context).invalidateAuthToken(accessToken);
|
| }
|
| }
|
|
|
| @@ -249,9 +250,10 @@
|
| */
|
| @Override
|
| public void onSystemAccountsSeedingComplete() {
|
| - if (mPendingValidation) {
|
| - validateAccountsWithSignedInAccountName(mPendingValidationForceNotifications);
|
| - mPendingValidation = false;
|
| + if (mPendingValidationContext != null) {
|
| + validateAccountsWithSignedInAccountName(
|
| + mPendingValidationContext, mPendingValidationForceNotifications);
|
| + mPendingValidationContext = null;
|
| mPendingValidationForceNotifications = false;
|
| }
|
| }
|
| @@ -262,25 +264,28 @@
|
| */
|
| @Override
|
| public void onSystemAccountsChanged() {
|
| + mPendingValidationContext = null;
|
| mPendingValidationForceNotifications = false;
|
| }
|
|
|
| @CalledByNative
|
| - public void validateAccounts(boolean forceNotifications) {
|
| - ThreadUtils.assertOnUiThread();
|
| - if (!AccountTrackerService.get().checkAndSeedSystemAccounts()) {
|
| - mPendingValidation = true;
|
| + public void validateAccounts(Context context, boolean forceNotifications) {
|
| + ThreadUtils.assertOnUiThread();
|
| + if (!AccountTrackerService.get(context).checkAndSeedSystemAccounts()) {
|
| + mPendingValidationContext = context;
|
| mPendingValidationForceNotifications = forceNotifications;
|
| return;
|
| }
|
|
|
| - validateAccountsWithSignedInAccountName(forceNotifications);
|
| - }
|
| -
|
| - private void validateAccountsWithSignedInAccountName(boolean forceNotifications) {
|
| - String currentlySignedInAccount = ChromeSigninController.get().getSignedInAccountName();
|
| + validateAccountsWithSignedInAccountName(context, forceNotifications);
|
| + }
|
| +
|
| + private void validateAccountsWithSignedInAccountName(
|
| + Context context, boolean forceNotifications) {
|
| + String currentlySignedInAccount =
|
| + ChromeSigninController.get(context).getSignedInAccountName();
|
| if (currentlySignedInAccount != null
|
| - && isSignedInAccountChanged(currentlySignedInAccount)) {
|
| + && isSignedInAccountChanged(context, 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.
|
| @@ -293,8 +298,8 @@
|
| forceNotifications);
|
| }
|
|
|
| - private boolean isSignedInAccountChanged(String signedInAccountName) {
|
| - String[] accountNames = getSystemAccountNames();
|
| + private boolean isSignedInAccountChanged(Context context, String signedInAccountName) {
|
| + String[] accountNames = getSystemAccountNames(context);
|
| for (String accountName : accountNames) {
|
| if (accountName.equals(signedInAccountName)) return false;
|
| }
|
| @@ -361,14 +366,15 @@
|
| }
|
| }
|
|
|
| - private static String[] getStoredAccounts() {
|
| + private static String[] getStoredAccounts(Context context) {
|
| 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(String[] accounts) {
|
| + private static void saveStoredAccounts(Context context, String[] accounts) {
|
| Set<String> set = new HashSet<String>(Arrays.asList(accounts));
|
| ContextUtils.getAppSharedPreferences().edit()
|
| .putStringSet(STORED_ACCOUNTS_KEY, set).apply();
|
|
|