Chromium Code Reviews| Index: sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java |
| 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 be7628736db87cb8043c7407f86deca8c0a3dd84..3b792d0e2f3a151fade06c7849f37dccdba6c34d 100644 |
| --- a/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java |
| +++ b/sync/android/java/src/org/chromium/sync/signin/AccountManagerHelper.java |
| @@ -25,8 +25,10 @@ import org.chromium.net.NetworkChangeNotifier; |
| import java.io.IOException; |
| import java.util.ArrayList; |
| import java.util.List; |
| +import java.util.Locale; |
| import java.util.concurrent.atomic.AtomicBoolean; |
| import java.util.concurrent.atomic.AtomicInteger; |
| +import java.util.regex.Pattern; |
| import javax.annotation.Nullable; |
| @@ -39,6 +41,12 @@ public class AccountManagerHelper { |
| private static final String TAG = "AccountManagerHelper"; |
| + private static final Pattern AT_SYMBOL = Pattern.compile("@"); |
| + |
| + private static final String GMAIL_COM = "gmail.com"; |
| + |
| + private static final String GOOGLEMAIL_COM = "googlemail.com"; |
| + |
| public static final String GOOGLE_ACCOUNT_TYPE = "com.google"; |
| private static final Object sLock = new Object(); |
| @@ -122,13 +130,27 @@ public class AccountManagerHelper { |
| return getGoogleAccounts().length > 0; |
| } |
| + private String canonicalizeName(String name) { |
| + String[] parts = AT_SYMBOL.split(name); |
| + if (parts.length != 2) return name; |
| + |
| + if (GOOGLEMAIL_COM.equalsIgnoreCase(parts[1])) { |
| + parts[1] = GMAIL_COM; |
| + } |
| + if (GMAIL_COM.equalsIgnoreCase(parts[1])) { |
| + parts[0] = parts[0].replace(".", ""); |
|
nyquist
2014/10/07 15:59:40
I wonder, would this hit the CharSequence version
Roger Tawa OOO till Jul 10th
2014/10/07 19:37:34
I can't use single-char version because you can't
nyquist
2014/10/07 20:05:37
In that case I'd precompile the pattern for the ".
|
| + } |
| + return (parts[0] + "@" + parts[1]).toLowerCase(Locale.US); |
| + } |
| + |
| /** |
| * Returns the account if it exists, null otherwise. |
| */ |
| public Account getAccountFromName(String accountName) { |
|
nyquist
2014/10/07 15:59:40
One quick question, were you going to add a test f
|
| - Account[] accounts = mAccountManager.getAccountsByType(GOOGLE_ACCOUNT_TYPE); |
| + String canonicalName = canonicalizeName(accountName); |
| + Account[] accounts = getGoogleAccounts(); |
| for (Account account : accounts) { |
| - if (account.name.equals(accountName)) { |
| + if (canonicalizeName(account.name).equals(canonicalName)) { |
| return account; |
| } |
| } |