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

Unified Diff: sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java

Issue 1353393002: Mask the AccountManager{Future,Callback} with a simple Callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rmcas
Patch Set: fix test. move background task to where it is required. Created 5 years, 2 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: sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java
diff --git a/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java b/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java
index 33b233c4fd33e3531737fda7941708bcddf94a49..888fee368f1c72f08b31d9b7bbb508a17f2fb59d 100644
--- a/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java
+++ b/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java
@@ -12,10 +12,12 @@ import android.accounts.AuthenticatorDescription;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
+import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.metrics.RecordHistogram;
@@ -31,6 +33,7 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate {
private final AccountManager mAccountManager;
private final Context mApplicationContext;
+ private static final String TAG = "Auth";
public SystemAccountManagerDelegate(Context context) {
mApplicationContext = context.getApplicationContext();
@@ -50,6 +53,21 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate {
}
@Override
+ public void getAccountsByType(final String type, final Callback<Account[]> callback) {
+ new AsyncTask<Void, Void, Account[]>() {
+ @Override
+ protected Account[] doInBackground(Void... params) {
+ return getAccountsByType(type);
+ }
+
+ @Override
+ protected void onPostExecute(Account[] accounts) {
+ callback.gotResult(accounts);
+ }
+ }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }
+
+ @Override
public AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType,
boolean notifyAuthFailure, AccountManagerCallback<Bundle> callback, Handler handler) {
return mAccountManager.getAuthToken(account, authTokenType, null, notifyAuthFailure,
@@ -67,19 +85,32 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate {
}
@Override
- public AccountManagerFuture<Boolean> hasFeatures(Account account, String[] features,
- final AccountManagerCallback<Boolean> callback, Handler handler) {
+ public void hasFeatures(Account account, String[] features,
+ final AccountManagerDelegate.Callback<Boolean> callback) {
if (!AccountManagerHelper.get(mApplicationContext).hasGetAccountsPermission()) {
- final FakeFalseAccountManagerFuture future = new FakeFalseAccountManagerFuture();
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
- callback.run(future);
+ callback.gotResult(false);
}
});
- return future;
+ return;
}
- return mAccountManager.hasFeatures(account, features, callback, handler);
+ mAccountManager.hasFeatures(account, features, new AccountManagerCallback<Boolean>() {
+ @Override
+ public void run(AccountManagerFuture<Boolean> future) {
+ assert future.isDone();
+ boolean hasFeatures = false;
+ try {
+ hasFeatures = future.getResult();
+ } catch (AuthenticatorException | IOException e) {
+ Log.e(TAG, "Error while checking features: ", e);
+ } catch (OperationCanceledException e) {
+ Log.e(TAG, "Checking features was cancelled. This should not happen.");
+ }
+ callback.gotResult(hasFeatures);
+ }
+ }, null /* handler */);
}
/**
@@ -94,34 +125,4 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate {
if (!LibraryLoader.isInitialized()) return;
RecordHistogram.recordTimesHistogram(histogramName, elapsedMs, TimeUnit.MILLISECONDS);
}
-
- private static final class FakeFalseAccountManagerFuture
- implements AccountManagerFuture<Boolean> {
- @Override
- public boolean cancel(boolean mayInterruptIfRunning) {
- return false;
- }
-
- @Override
- public boolean isCancelled() {
- return false;
- }
-
- @Override
- public boolean isDone() {
- return true;
- }
-
- @Override
- public Boolean getResult()
- throws OperationCanceledException, IOException, AuthenticatorException {
- return false;
- }
-
- @Override
- public Boolean getResult(long timeout, TimeUnit unit)
- throws OperationCanceledException, IOException, AuthenticatorException {
- return getResult();
- }
- }
}

Powered by Google App Engine
This is Rietveld 408576698