summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authormaxbogue <maxbogue@chromium.org>2015-11-09 11:16:13 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-09 19:17:33 +0000
commitb3770eeab810aa0b2735c649a99dd8d2aaa39514 (patch)
tree93a1a03b671f9b1e07edc4658cf6222489fcc552 /sync
parentbbd0b7debb205ac260dde1c91fc8147fe6931c94 (diff)
downloadchromium_src-b3770eeab810aa0b2735c649a99dd8d2aaa39514.zip
chromium_src-b3770eeab810aa0b2735c649a99dd8d2aaa39514.tar.gz
chromium_src-b3770eeab810aa0b2735c649a99dd8d2aaa39514.tar.bz2
[Sync] Add async methods to AccountManagerHelper + deprecate the sync ones.
getGoogleAccounts is becoming asynchronous and therefore all uses of it must become asynchronous as well. See bug for more info. Note that this change adds ~25 deprecation warnings to the build output. BUG=517697 Review URL: https://codereview.chromium.org/1419223005 Cr-Commit-Position: refs/heads/master@{#358621}
Diffstat (limited to 'sync')
-rw-r--r--sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java78
1 files changed, 74 insertions, 4 deletions
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 8b1b0c3..6fd2bb4 100644
--- a/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java
+++ b/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java
@@ -150,6 +150,10 @@ public class AccountManagerHelper {
return new Account(name, GOOGLE_ACCOUNT_TYPE);
}
+ /**
+ * Use the asynchronous version below instead. See http://crbug.com/517697.
+ */
+ @Deprecated
public List<String> getGoogleAccountNames() {
List<String> accountNames = new ArrayList<String>();
for (Account account : getGoogleAccounts()) {
@@ -159,9 +163,25 @@ public class AccountManagerHelper {
}
/**
- * Returns all Google accounts on the device.
- * @return an array of accounts.
+ * Retrieves a list of the Google account names on the device asynchronously.
*/
+ public void getGoogleAccountNames(final Callback<List<String>> callback) {
+ getGoogleAccounts(new Callback<Account[]>() {
+ @Override
+ public void onResult(Account[] accounts) {
+ List<String> accountNames = new ArrayList<String>();
+ for (Account account : accounts) {
+ accountNames.add(account.name);
+ }
+ callback.onResult(accountNames);
+ }
+ });
+ }
+
+ /**
+ * Use the asynchronous version below instead. See http://crbug.com/517697.
+ */
+ @Deprecated
public Account[] getGoogleAccounts() {
return mAccountManager.getAccountsByType(GOOGLE_ACCOUNT_TYPE);
}
@@ -173,10 +193,26 @@ public class AccountManagerHelper {
mAccountManager.getAccountsByType(GOOGLE_ACCOUNT_TYPE, callback);
}
+ /**
+ * Use the asynchronous version below instead. See http://crbug.com/517697.
+ */
+ @Deprecated
public boolean hasGoogleAccounts() {
return getGoogleAccounts().length > 0;
}
+ /**
+ * Asynchronously determine whether any Google accounts have been added.
+ */
+ public void hasGoogleAccounts(final Callback<Boolean> callback) {
+ getGoogleAccounts(new Callback<Account[]>() {
+ @Override
+ public void onResult(Account[] accounts) {
+ callback.onResult(accounts.length > 0);
+ }
+ });
+ }
+
private String canonicalizeName(String name) {
String[] parts = AT_SYMBOL.split(name);
if (parts.length != 2) return name;
@@ -191,8 +227,9 @@ public class AccountManagerHelper {
}
/**
- * Returns the account if it exists, null otherwise.
+ * Use the asynchronous version below instead. See http://crbug.com/517697.
*/
+ @Deprecated
public Account getAccountFromName(String accountName) {
String canonicalName = canonicalizeName(accountName);
Account[] accounts = getGoogleAccounts();
@@ -205,13 +242,46 @@ public class AccountManagerHelper {
}
/**
- * Returns whether the accounts exists.
+ * Asynchronously returns the account if it exists; null otherwise.
*/
+ public void getAccountFromName(String accountName, final Callback<Account> callback) {
+ final String canonicalName = canonicalizeName(accountName);
+ getGoogleAccounts(new Callback<Account[]>() {
+ @Override
+ public void onResult(Account[] accounts) {
+ Account accountForName = null;
+ for (Account account : accounts) {
+ if (canonicalizeName(account.name).equals(canonicalName)) {
+ accountForName = account;
+ break;
+ }
+ }
+ callback.onResult(accountForName);
+ }
+ });
+ }
+
+ /**
+ * Use the asynchronous version below instead. See http://crbug.com/517697.
+ */
+ @Deprecated
public boolean hasAccountForName(String accountName) {
return getAccountFromName(accountName) != null;
}
/**
+ * Asynchronously returns whether an account exists with the given name.
+ */
+ public void hasAccountForName(String accountName, final Callback<Boolean> callback) {
+ getAccountFromName(accountName, new Callback<Account>() {
+ @Override
+ public void onResult(Account account) {
+ callback.onResult(account != null);
+ }
+ });
+ }
+
+ /**
* @return Whether or not there is an account authenticator for Google accounts.
*/
public boolean hasGoogleAccountAuthenticator() {