Commit 0193faf4 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Extract lengthy callback in AccountSigninView into method

This CL extracts two lengthy (8 and 57 lines) callbacks into a single method
and renames affected methods.

Bug: None
Change-Id: I712116269eef394c1582263d0a2d24e16fdedfe8
Reviewed-on: https://chromium-review.googlesource.com/591652Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490771}
parent d085cd8d
...@@ -196,7 +196,7 @@ public class AccountSigninView extends FrameLayout { ...@@ -196,7 +196,7 @@ public class AccountSigninView extends FrameLayout {
mDelegate = delegate; mDelegate = delegate;
mListener = listener; mListener = listener;
showConfirmSigninPageAccountTrackerServiceCheck(accountName, isDefaultAccount); showConfirmSigninPageAccountTrackerServiceCheck(accountName, isDefaultAccount);
updateAccounts(); triggerUpdateAccounts();
} }
private void setProfileDataCache(ProfileDataCache profileData) { private void setProfileDataCache(ProfileDataCache profileData) {
...@@ -242,7 +242,7 @@ public class AccountSigninView extends FrameLayout { ...@@ -242,7 +242,7 @@ public class AccountSigninView extends FrameLayout {
@Override @Override
protected void onAttachedToWindow() { protected void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
updateAccounts(); triggerUpdateAccounts();
if (mProfileData != null) { if (mProfileData != null) {
mProfileData.addObserver(mProfileDataCacheObserver); mProfileData.addObserver(mProfileDataCacheObserver);
} }
...@@ -260,7 +260,7 @@ public class AccountSigninView extends FrameLayout { ...@@ -260,7 +260,7 @@ public class AccountSigninView extends FrameLayout {
public void onWindowVisibilityChanged(int visibility) { public void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility); super.onWindowVisibilityChanged(visibility);
if (visibility == View.VISIBLE) { if (visibility == View.VISIBLE) {
updateAccounts(); triggerUpdateAccounts();
return; return;
} }
if (visibility == View.INVISIBLE && mGooglePlayServicesUpdateErrorHandler != null) { if (visibility == View.INVISIBLE && mGooglePlayServicesUpdateErrorHandler != null) {
...@@ -292,32 +292,21 @@ public class AccountSigninView extends FrameLayout { ...@@ -292,32 +292,21 @@ public class AccountSigninView extends FrameLayout {
/** /**
* Refresh the list of available system accounts asynchronously. * Refresh the list of available system accounts asynchronously.
*/ */
private void updateAccounts() { private void triggerUpdateAccounts() {
if (mProfileData == null) { if (mProfileData == null) {
return; return;
} }
if (mSelectedAccountName != null) { AccountManagerFacade.get().getGoogleAccountNames(
AccountManagerFacade.get().tryGetGoogleAccountNames(new Callback<List<String>>() { new Callback<AccountManagerResult<List<String>>>() {
@Override @Override
public void onResult(List<String> result) { public void onResult(AccountManagerResult<List<String>> result) {
if (result.contains(mSelectedAccountName)) return; updateAccounts(result);
if (mUndoBehavior == UNDO_BACK_TO_SELECTION) {
RecordUserAction.record("Signin_Undo_Signin");
showSigninPage();
} else {
mListener.onFailedToSetForcedAccount(mSelectedAccountName);
}
} }
}); });
return;
} }
AccountManagerFacade accountManager = AccountManagerFacade.get(); private void updateAccounts(AccountManagerResult<List<String>> result) {
accountManager.getGoogleAccountNames(new Callback<AccountManagerResult<List<String>>>() {
@Override
public void onResult(AccountManagerResult<List<String>> result) {
if (!ViewCompat.isAttachedToWindow(AccountSigninView.this)) { if (!ViewCompat.isAttachedToWindow(AccountSigninView.this)) {
// This callback is invoked after AccountSigninView is detached from window // This callback is invoked after AccountSigninView is detached from window
// (e.g., Chrome is minimized). Updating view now is redundant and dangerous // (e.g., Chrome is minimized). Updating view now is redundant and dangerous
...@@ -325,9 +314,9 @@ public class AccountSigninView extends FrameLayout { ...@@ -325,9 +314,9 @@ public class AccountSigninView extends FrameLayout {
return; return;
} }
List<String> oldAccountNames = mAccountNames; final List<String> accountNames;
try { try {
mAccountNames = result.get(); accountNames = result.get();
} catch (GmsAvailabilityException e) { } catch (GmsAvailabilityException e) {
dismissGmsUpdatingDialog(); dismissGmsUpdatingDialog();
showGmsErrorDialog(e.getGmsAvailabilityReturnCode()); showGmsErrorDialog(e.getGmsAvailabilityReturnCode());
...@@ -346,11 +335,20 @@ public class AccountSigninView extends FrameLayout { ...@@ -346,11 +335,20 @@ public class AccountSigninView extends FrameLayout {
dismissGmsUpdatingDialog(); dismissGmsUpdatingDialog();
if (mSelectedAccountName != null) { if (mSelectedAccountName != null) {
// If sign-in completed in the mean time, return in order to avoid showing the if (accountNames.contains(mSelectedAccountName)) return;
// wrong state in the UI.
if (mUndoBehavior == UNDO_BACK_TO_SELECTION) {
RecordUserAction.record("Signin_Undo_Signin");
showSigninPage();
} else {
mListener.onFailedToSetForcedAccount(mSelectedAccountName);
}
return; return;
} }
List<String> oldAccountNames = mAccountNames;
mAccountNames = accountNames;
int oldSelectedAccount = mSigninChooseView.getSelectedAccountPosition(); int oldSelectedAccount = mSigninChooseView.getSelectedAccountPosition();
AccountSelectionResult selection = selectAccountAfterAccountsUpdate( AccountSelectionResult selection = selectAccountAfterAccountsUpdate(
oldAccountNames, mAccountNames, oldSelectedAccount); oldAccountNames, mAccountNames, oldSelectedAccount);
...@@ -361,8 +359,7 @@ public class AccountSigninView extends FrameLayout { ...@@ -361,8 +359,7 @@ public class AccountSigninView extends FrameLayout {
setUpSigninButton(!mAccountNames.isEmpty()); setUpSigninButton(!mAccountNames.isEmpty());
mProfileData.update(mAccountNames); mProfileData.update(mAccountNames);
boolean selectedAccountChanged = oldAccountNames != null boolean selectedAccountChanged = oldAccountNames != null && !oldAccountNames.isEmpty()
&& !oldAccountNames.isEmpty()
&& (mAccountNames.isEmpty() && (mAccountNames.isEmpty()
|| mAccountNames.get(accountToSelect) || mAccountNames.get(accountToSelect)
.equals(oldAccountNames.get(oldSelectedAccount))); .equals(oldAccountNames.get(oldSelectedAccount)));
...@@ -376,8 +373,6 @@ public class AccountSigninView extends FrameLayout { ...@@ -376,8 +373,6 @@ public class AccountSigninView extends FrameLayout {
showConfirmSigninPageAccountTrackerServiceCheck(); showConfirmSigninPageAccountTrackerServiceCheck();
} }
} }
});
}
private boolean hasGmsError() { private boolean hasGmsError() {
return mGooglePlayServicesUpdateErrorHandler != null || mGmsIsUpdatingDialog != null; return mGooglePlayServicesUpdateErrorHandler != null || mGmsIsUpdatingDialog != null;
...@@ -496,7 +491,7 @@ public class AccountSigninView extends FrameLayout { ...@@ -496,7 +491,7 @@ public class AccountSigninView extends FrameLayout {
mSigninChooseView.setVisibility(View.VISIBLE); mSigninChooseView.setVisibility(View.VISIBLE);
setUpCancelButton(); setUpCancelButton();
updateAccounts(); triggerUpdateAccounts();
} }
private void showConfirmSigninPage() { private void showConfirmSigninPage() {
......
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