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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/childaccounts/ChildAccountService.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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/services/AndroidEduAndChildAccountHelper.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/childaccounts/ChildAccountService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/childaccounts/ChildAccountService.java b/chrome/android/java/src/org/chromium/chrome/browser/childaccounts/ChildAccountService.java
index ffbb7faf647a7bcfa9683fb48daa219cbfb7723b..f40736ab33aa521e03b728b097d342c230279ce8 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/childaccounts/ChildAccountService.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/childaccounts/ChildAccountService.java
@@ -5,18 +5,12 @@
package org.chromium.chrome.browser.childaccounts;
import android.accounts.Account;
-import android.accounts.AccountManagerCallback;
-import android.accounts.AccountManagerFuture;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
import android.content.Context;
-import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
+import org.chromium.sync.signin.AccountManagerDelegate.Callback;
import org.chromium.sync.signin.AccountManagerHelper;
-import java.io.IOException;
-
/**
* This class serves as a simple interface for querying the child account information.
* It has two methods namely, checkHasChildAccount(...) which is asynchronous and queries the
@@ -29,55 +23,30 @@ import java.io.IOException;
* side and also takes responsibility for monitoring changes and taking a suitable action.
*/
public class ChildAccountService {
- private static final String TAG = "ChildAccountService";
-
private ChildAccountService() {
// Only for static usage.
}
/**
- * A callback to return the result of {@link #checkHasChildAccount}.
- */
- public static interface HasChildAccountCallback {
-
- /**
- * @param hasChildAccount Whether there is exactly one child account on the device.
- */
- public void onChildAccountChecked(boolean hasChildAccount);
-
- }
-
- /**
* Checks for the presence of child accounts on the device.
*
* @param callback A callback which will be called with the result.
*/
- public static void checkHasChildAccount(
- Context context, final HasChildAccountCallback callback) {
+ public static void checkHasChildAccount(Context context, final Callback<Boolean> callback) {
ThreadUtils.assertOnUiThread();
if (!nativeIsChildAccountDetectionEnabled()) {
- callback.onChildAccountChecked(false);
- return;
- }
- AccountManagerHelper helper = AccountManagerHelper.get(context);
- Account[] accounts = helper.getGoogleAccounts();
- if (accounts.length != 1) {
- callback.onChildAccountChecked(false);
+ callback.gotResult(false);
return;
}
- helper.checkChildAccount(accounts[0], new AccountManagerCallback<Boolean>() {
+ final AccountManagerHelper helper = AccountManagerHelper.get(context);
+ helper.getGoogleAccounts(new Callback<Account[]>() {
@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.");
+ public void gotResult(Account[] accounts) {
+ if (accounts.length != 1) {
+ callback.gotResult(false);
+ } else {
+ helper.checkChildAccount(accounts[0], callback);
}
- callback.onChildAccountChecked(hasFeatures);
}
});
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/services/AndroidEduAndChildAccountHelper.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698