Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4935)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/signin/OAuth2TokenService.java

Issue 213823004: Calls FireRefreshTokenRevoked if an account is removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments + tests Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..9adf0cc472e9e8f95a260ee8c5d573b8e517b156 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";
nyquist 2014/04/24 22:27:05 Nit: This is in a shared namespace. It lgtm, but k
+
public interface OAuth2TokenServiceObserver {
void onRefreshTokenAvailable(Account account);
void onRefreshTokenRevoked(Account account);
@@ -86,16 +95,28 @@ public final class OAuth2TokenService {
}
/**
- * Called by native to list the accounts with OAuth2 refresh tokens.
+ * Called by native to list the activite accounts in the OS.
nyquist 2014/04/24 22:27:05 Add a comment along the lines "This might not be w
*/
+ @VisibleForTesting
@CalledByNative
- public static String[] getAccounts(Context context) {
+ public static String[] getSystemAccounts(Context context) {
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.
+ * This can differ from getSystemAccounts as the user add/remove accounts
nyquist 2014/04/24 22:27:05 Nit: Use JavaDoc style (ie. {@link #getSystemAccou
+ * from the OS. validateAccounts should be called to keep these two
nyquist 2014/04/24 22:27:05 Nit: Same as above.
+ * in sync.
+ */
+ @CalledByNative
+ public static String[] getAccounts(Context context) {
+ return getStoredAccounts(context);
+ }
+
+ /**
* Called by native to retrieve OAuth2 tokens.
*
* @param username The native username (full address).
@@ -202,9 +223,7 @@ public final class OAuth2TokenService {
ThreadUtils.assertOnUiThread();
String currentlySignedInAccount =
ChromeSigninController.get(context).getSignedInAccountName();
- String[] accounts = getAccounts(context);
- nativeValidateAccounts(
- mNativeProfileOAuth2TokenService, accounts, currentlySignedInAccount);
+ nativeValidateAccounts(mNativeProfileOAuth2TokenService, currentlySignedInAccount);
}
/**
@@ -262,12 +281,26 @@ 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()]);
+ }
+
+ @CalledByNative
+ 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();
nyquist 2014/04/24 22:27:05 .apply() does a best-effort attempt to persist the
+ }
+
private static native Object nativeGetForProfile(Profile profile);
private static native void nativeOAuth2TokenFetched(
String authToken, boolean result, long nativeCallback);
private native void nativeValidateAccounts(
long nativeAndroidProfileOAuth2TokenService,
- String[] accounts, String currentlySignedInAccount);
+ String currentlySignedInAccount);
private native void nativeFireRefreshTokenAvailableFromJava(
long nativeAndroidProfileOAuth2TokenService, String accountName);
private native void nativeFireRefreshTokenRevokedFromJava(

Powered by Google App Engine
This is Rietveld 408576698