Commit 4939a281 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Postpone validateAccountSettings until accounts are ready

This CL modifies SigninHelper.validateAccountSettings so that accounts
are accessed only after AccountManagerFacade cache is populated.
SigninHelper.validateAccountSettings is called early during startup,
so postponing this call should reduce the amount of time spent waiting
for accounts on UI thread.

Bug: 837374
Change-Id: Ica027806d9a329e08b880abec12dc0954c540e63
Reviewed-on: https://chromium-review.googlesource.com/c/1329247Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607221}
parent 39643e34
...@@ -120,6 +120,13 @@ public class SigninHelper { ...@@ -120,6 +120,13 @@ public class SigninHelper {
} }
public void validateAccountSettings(boolean accountsChanged) { public void validateAccountSettings(boolean accountsChanged) {
// validateAccountsInternal accesses account list (to check whether account exists), so
// postpone the call until account list cache in AccountManagerFacade is ready.
AccountManagerFacade.get().runAfterCacheIsPopulated(
() -> validateAccountsInternal(accountsChanged));
}
private void validateAccountsInternal(boolean accountsChanged) {
// Ensure System accounts have been seeded. // Ensure System accounts have been seeded.
mAccountTrackerService.checkAndSeedSystemAccounts(); mAccountTrackerService.checkAndSeedSystemAccounts();
if (!accountsChanged) { if (!accountsChanged) {
...@@ -155,7 +162,7 @@ public class SigninHelper { ...@@ -155,7 +162,7 @@ public class SigninHelper {
if (renamedAccount == null) { if (renamedAccount == null) {
mSigninManager.signOut(SignoutReason.ACCOUNT_REMOVED_FROM_DEVICE); mSigninManager.signOut(SignoutReason.ACCOUNT_REMOVED_FROM_DEVICE);
} else { } else {
validateAccountSettings(true); validateAccountsInternal(true);
} }
} }
}; };
...@@ -217,7 +224,7 @@ public class SigninHelper { ...@@ -217,7 +224,7 @@ public class SigninHelper {
if (mProfileSyncService != null) { if (mProfileSyncService != null) {
mProfileSyncService.setSetupInProgress(false); mProfileSyncService.setSetupInProgress(false);
} }
validateAccountSettings(true); validateAccountsInternal(true);
} }
@Override @Override
......
...@@ -229,7 +229,6 @@ public class AccountManagerFacade { ...@@ -229,7 +229,6 @@ public class AccountManagerFacade {
* @param runnable The callback to call after cache is populated. Invoked on the main thread. * @param runnable The callback to call after cache is populated. Invoked on the main thread.
*/ */
@MainThread @MainThread
@VisibleForTesting
public void runAfterCacheIsPopulated(Runnable runnable) { public void runAfterCacheIsPopulated(Runnable runnable) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
if (isCachePopulated()) { if (isCachePopulated()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment