Chromium Code Reviews| 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 2e5daa80fbd2633bdb4f86a550669fd4ac23207a..1673a1eabf3fb67a468325123e6c3e7a0896d12f 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 |
| @@ -7,8 +7,11 @@ package org.chromium.chrome.browser.signin; |
| import android.accounts.Account; |
| import android.app.Activity; |
| import android.content.Context; |
| +import android.preference.PreferenceManager; |
| import android.util.Log; |
| +import com.google.common.annotations.VisibleForTesting; |
| + |
| import org.chromium.base.CalledByNative; |
| import org.chromium.base.ObserverList; |
| import org.chromium.base.ThreadUtils; |
| @@ -16,9 +19,12 @@ import org.chromium.chrome.browser.profiles.Profile; |
| import org.chromium.sync.signin.AccountManagerHelper; |
| import org.chromium.sync.signin.ChromeSigninController; |
| +import java.util.Arrays; |
| import java.util.concurrent.Semaphore; |
| import java.util.concurrent.TimeUnit; |
| import java.util.concurrent.atomic.AtomicReference; |
| +import java.util.HashSet; |
| +import java.util.Set; |
| import javax.annotation.Nullable; |
| @@ -33,6 +39,9 @@ public final class OAuth2TokenService { |
| private static final String TAG = "OAuth2TokenService"; |
| + @VisibleForTesting |
| + public static final String STORED_ACCOUNTS_KEY = "google.services.stored_accounts"; |
| + |
| public interface OAuth2TokenServiceObserver { |
| void onRefreshTokenAvailable(Account account); |
| void onRefreshTokenRevoked(Account account); |
| @@ -85,14 +94,18 @@ public final class OAuth2TokenService { |
| return account; |
| } |
| + public static String[] getSystemAccounts(Context context) { |
|
nyquist
2014/04/10 19:07:40
Does this need to be public?
acleung1
2014/04/10 21:36:01
No. Removed public visibility.
|
| + AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context); |
| + java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames(); |
| + return accountNames.toArray(new String[accountNames.size()]); |
| + } |
| + |
| /** |
| * Called by native to list the accounts with OAuth2 refresh tokens. |
| */ |
| @CalledByNative |
| public static String[] getAccounts(Context context) { |
| - AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context); |
| - java.util.List<String> accountNames = accountManagerHelper.getGoogleAccountNames(); |
| - return accountNames.toArray(new String[accountNames.size()]); |
| + return getSystemAccounts(context); |
|
Roger Tawa OOO till Jul 10th
2014/04/10 15:30:54
This needs to remain getStoredAccounts() right? O
acleung1
2014/04/10 21:36:01
I have been trying to find a way to get this to wo
Roger Tawa OOO till Jul 10th
2014/04/14 16:03:58
GetAccounts() is a public api of OAuth2TokenServic
|
| } |
| /** |
| @@ -202,9 +215,15 @@ public final class OAuth2TokenService { |
| ThreadUtils.assertOnUiThread(); |
| String currentlySignedInAccount = |
| ChromeSigninController.get(context).getSignedInAccountName(); |
| - String[] accounts = getAccounts(context); |
| - nativeValidateAccounts( |
| - mNativeProfileOAuth2TokenService, accounts, currentlySignedInAccount); |
| + String[] prevAccounts = getStoredAccounts(context); |
| + saveStoredAccounts(context, getSystemAccounts(context)); |
| + |
| + if (!nativeValidateAccounts( |
| + mNativeProfileOAuth2TokenService, prevAccounts, currentlySignedInAccount)) { |
| + // We will assume that there is no way to get tokens unless we have a sync account. |
| + // again. |
| + saveStoredAccounts(context, new String[]{}); |
| + } |
| } |
| /** |
| @@ -262,10 +281,23 @@ public final class OAuth2TokenService { |
| } |
| } |
| + private static String[] getStoredAccounts(Context context) { |
| + Set<String> accounts = |
| + PreferenceManager.getDefaultSharedPreferences(context) |
| + .getStringSet(STORED_ACCOUNTS_KEY, null); |
| + return accounts == null ? new String[]{} : accounts.toArray(new String[accounts.size()]); |
| + } |
| + |
| + private static void saveStoredAccounts(Context context, String[] accounts) { |
| + Set<String> set = new HashSet<String>(Arrays.asList(accounts)); |
| + PreferenceManager.getDefaultSharedPreferences(context).edit(). |
| + putStringSet(STORED_ACCOUNTS_KEY, set).apply(); |
| + } |
| + |
| private static native Object nativeGetForProfile(Profile profile); |
| private static native void nativeOAuth2TokenFetched( |
| String authToken, boolean result, long nativeCallback); |
| - private native void nativeValidateAccounts( |
| + private native boolean nativeValidateAccounts( |
| long nativeAndroidProfileOAuth2TokenService, |
| String[] accounts, String currentlySignedInAccount); |
| private native void nativeFireRefreshTokenAvailableFromJava( |