diff options
author | maxbogue <maxbogue@chromium.org> | 2015-10-27 11:17:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-27 18:19:17 +0000 |
commit | bc808d5d314a6dca042f94c018ca6b520fc8e787 (patch) | |
tree | 426defe71367051f54eb7e6a2fce18ae2beeeb7b | |
parent | c6f7263b89e90123ae005f39338fe60d04259dc5 (diff) | |
download | chromium_src-bc808d5d314a6dca042f94c018ca6b520fc8e787.zip chromium_src-bc808d5d314a6dca042f94c018ca6b520fc8e787.tar.gz chromium_src-bc808d5d314a6dca042f94c018ca6b520fc8e787.tar.bz2 |
Convert AccountManagerDelegate.Callback to use base.Callback.
The new generic Callback implementation should be used to simplify code and interfaces.
BUG=547973
Review URL: https://codereview.chromium.org/1421343002
Cr-Commit-Position: refs/heads/master@{#356345}
8 files changed, 47 insertions, 23 deletions
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 f40736a..d033661 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 @@ -7,8 +7,8 @@ package org.chromium.chrome.browser.childaccounts; import android.accounts.Account; import android.content.Context; +import org.chromium.base.Callback; import org.chromium.base.ThreadUtils; -import org.chromium.sync.signin.AccountManagerDelegate.Callback; import org.chromium.sync.signin.AccountManagerHelper; /** @@ -35,15 +35,15 @@ public class ChildAccountService { public static void checkHasChildAccount(Context context, final Callback<Boolean> callback) { ThreadUtils.assertOnUiThread(); if (!nativeIsChildAccountDetectionEnabled()) { - callback.gotResult(false); + callback.onResult(false); return; } final AccountManagerHelper helper = AccountManagerHelper.get(context); helper.getGoogleAccounts(new Callback<Account[]>() { @Override - public void gotResult(Account[] accounts) { + public void onResult(Account[] accounts) { if (accounts.length != 1) { - callback.gotResult(false); + callback.onResult(false); } else { helper.checkChildAccount(accounts[0], callback); } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/services/AndroidEduAndChildAccountHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/services/AndroidEduAndChildAccountHelper.java index 87b20a0..2bdd20f 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/services/AndroidEduAndChildAccountHelper.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/services/AndroidEduAndChildAccountHelper.java @@ -6,10 +6,10 @@ package org.chromium.chrome.browser.services; import android.content.Context; +import org.chromium.base.Callback; import org.chromium.base.Log; import org.chromium.chrome.browser.ChromeApplication; import org.chromium.chrome.browser.childaccounts.ChildAccountService; -import org.chromium.sync.signin.AccountManagerDelegate.Callback; /** * A helper for Android EDU and child account checks. @@ -63,9 +63,9 @@ public abstract class AndroidEduAndChildAccountHelper checkDone(); } - // AccountManagerDelegate.Callback<Boolean>: + // Callback<Boolean>: @Override - public void gotResult(Boolean hasChildAccount) { + public void onResult(Boolean hasChildAccount) { Log.d(TAG, "onChildAccountChecked"); mHasChildAccount = hasChildAccount; checkDone(); diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountTrackerService.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountTrackerService.java index 097272e..fe11974 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountTrackerService.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountTrackerService.java @@ -8,12 +8,12 @@ import android.accounts.Account; import android.content.Context; import android.os.AsyncTask; +import org.chromium.base.Callback; import org.chromium.base.Log; import org.chromium.base.ObserverList; import org.chromium.base.ThreadUtils; import org.chromium.base.VisibleForTesting; import org.chromium.base.annotations.JNINamespace; -import org.chromium.sync.signin.AccountManagerDelegate.Callback; import org.chromium.sync.signin.AccountManagerHelper; /** @@ -103,7 +103,7 @@ public class AccountTrackerService { } AccountManagerHelper.get(mContext).getGoogleAccounts(new Callback<Account[]>() { @Override - public void gotResult(final Account[] accounts) { + public void onResult(final Account[] accounts) { new AsyncTask<Void, Void, String[][]>() { @Override public String[][] doInBackground(Void... params) { diff --git a/components/signin/core/browser/android/java/src/org/chromium/components/signin/ChildAccountInfoFetcher.java b/components/signin/core/browser/android/java/src/org/chromium/components/signin/ChildAccountInfoFetcher.java index db155bc..6303784 100644 --- a/components/signin/core/browser/android/java/src/org/chromium/components/signin/ChildAccountInfoFetcher.java +++ b/components/signin/core/browser/android/java/src/org/chromium/components/signin/ChildAccountInfoFetcher.java @@ -8,8 +8,8 @@ import android.accounts.Account; import android.content.Context; import org.chromium.base.ApplicationStatus; +import org.chromium.base.Callback; import org.chromium.base.annotations.CalledByNative; -import org.chromium.sync.signin.AccountManagerDelegate.Callback; import org.chromium.sync.signin.AccountManagerHelper; /** @@ -32,7 +32,7 @@ public final class ChildAccountInfoFetcher { Account account = helper.createAccountFromName(accountName); helper.checkChildAccount(account, new Callback<Boolean>() { @Override - public void gotResult(Boolean isChildAccount) { + public void onResult(Boolean isChildAccount) { nativeSetIsChildAccount(nativeAccountFetcherService, accountId, isChildAccount); } }); diff --git a/sync/android/java/src/org/chromium/sync/signin/AccountManagerDelegate.java b/sync/android/java/src/org/chromium/sync/signin/AccountManagerDelegate.java index 4cc32a1..60ecb57 100644 --- a/sync/android/java/src/org/chromium/sync/signin/AccountManagerDelegate.java +++ b/sync/android/java/src/org/chromium/sync/signin/AccountManagerDelegate.java @@ -28,7 +28,8 @@ public interface AccountManagerDelegate { @Deprecated Account[] getAccountsByType(String type); - void getAccountsByType(String type, Callback<Account[]> callback); + // TODO(maxbogue): Remove full Callback path once AccountManagerDelegate.Callback is removed. + void getAccountsByType(String type, org.chromium.base.Callback<Account[]> callback); AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType, boolean notifyAuthFailure, AccountManagerCallback<Bundle> callback, Handler handler); @@ -37,5 +38,7 @@ public interface AccountManagerDelegate { AuthenticatorDescription[] getAuthenticatorTypes(); - void hasFeatures(Account account, String[] features, Callback<Boolean> callback); + // TODO(maxbogue): Remove full Callback path once AccountManagerDelegate.Callback is removed. + void hasFeatures( + Account account, String[] features, org.chromium.base.Callback<Boolean> callback); } diff --git a/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java b/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java index a73769a..8b1b0c3 100644 --- a/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java +++ b/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java @@ -20,6 +20,7 @@ import android.os.Bundle; import android.os.Process; import android.util.Log; +import org.chromium.base.Callback; import org.chromium.base.ThreadUtils; import org.chromium.base.VisibleForTesting; import org.chromium.net.NetworkChangeNotifier; @@ -165,7 +166,10 @@ public class AccountManagerHelper { return mAccountManager.getAccountsByType(GOOGLE_ACCOUNT_TYPE); } - public void getGoogleAccounts(AccountManagerDelegate.Callback<Account[]> callback) { + /** + * Retrieves all Google accounts on the device asynchronously. + */ + public void getGoogleAccounts(Callback<Account[]> callback) { mAccountManager.getAccountsByType(GOOGLE_ACCOUNT_TYPE, callback); } @@ -373,8 +377,7 @@ public class AccountManagerHelper { } } - public void checkChildAccount( - Account account, AccountManagerDelegate.Callback<Boolean> callback) { + public void checkChildAccount(Account account, Callback<Boolean> callback) { String[] features = {FEATURE_IS_CHILD_ACCOUNT_KEY}; mAccountManager.hasFeatures(account, features, callback); } 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 8688314..5865586 100644 --- a/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java +++ b/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java @@ -53,8 +53,10 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate { return accounts; } + // TODO(maxbogue): Remove full Callback path once AccountManagerDelegate.Callback is removed. @Override - public void getAccountsByType(final String type, final Callback<Account[]> callback) { + public void getAccountsByType( + final String type, final org.chromium.base.Callback<Account[]> callback) { new AsyncTask<Void, Void, Account[]>() { @Override protected Account[] doInBackground(Void... params) { @@ -63,7 +65,7 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate { @Override protected void onPostExecute(Account[] accounts) { - callback.gotResult(accounts); + callback.onResult(accounts); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -92,9 +94,23 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate { return mAccountManager.getAuthenticatorTypes(); } + // TODO(maxbogue): Remove full Callback path once AccountManagerDelegate.Callback is removed. @Override public void hasFeatures(Account account, String[] features, - final AccountManagerDelegate.Callback<Boolean> callback) { + final org.chromium.base.Callback<Boolean> callback) { + hasFeatures(account, features, new Callback<Boolean>() { + @Override + public void gotResult(Boolean result) { + callback.onResult(result); + } + }); + } + + /** + * TODO(maxbogue): Remove once downstream override is removed. + */ + @Deprecated + public void hasFeatures(Account account, String[] features, final Callback<Boolean> callback) { if (!AccountManagerHelper.get(mApplicationContext).hasGetAccountsPermission()) { ThreadUtils.postOnUiThread(new Runnable() { @Override diff --git a/sync/test/android/javatests/src/org/chromium/sync/test/util/MockAccountManager.java b/sync/test/android/javatests/src/org/chromium/sync/test/util/MockAccountManager.java index ada8a64..0420772 100644 --- a/sync/test/android/javatests/src/org/chromium/sync/test/util/MockAccountManager.java +++ b/sync/test/android/javatests/src/org/chromium/sync/test/util/MockAccountManager.java @@ -136,9 +136,10 @@ public class MockAccountManager implements AccountManagerDelegate { } } + // TODO(maxbogue): Remove full Callback path once AccountManagerDelegate.Callback is removed. @Override public void getAccountsByType( - final String type, final AccountManagerDelegate.Callback<Account[]> callback) { + final String type, final org.chromium.base.Callback<Account[]> callback) { new AsyncTask<Void, Void, Account[]>() { @Override protected Account[] doInBackground(Void... params) { @@ -147,7 +148,7 @@ public class MockAccountManager implements AccountManagerDelegate { @Override protected void onPostExecute(Account[] accounts) { - callback.gotResult(accounts); + callback.onResult(accounts); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -280,9 +281,10 @@ public class MockAccountManager implements AccountManagerDelegate { return new AuthenticatorDescription[] { googleAuthenticator }; } + // TODO(maxbogue): Remove full Callback path once AccountManagerDelegate.Callback is removed. @Override public void hasFeatures(Account account, final String[] features, - final AccountManagerDelegate.Callback<Boolean> callback) { + final org.chromium.base.Callback<Boolean> callback) { final AccountHolder accountHolder = getAccountHolder(account); accountHolder.addFeaturesCallback(new Runnable() { @Override @@ -295,7 +297,7 @@ public class MockAccountManager implements AccountManagerDelegate { hasAllFeatures = false; } } - callback.gotResult(hasAllFeatures); + callback.onResult(hasAllFeatures); } }); } |