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,91 +292,86 @@ public class AccountSigninView extends FrameLayout { ...@@ -292,91 +292,86 @@ 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);
} }
} });
}); }
private void updateAccounts(AccountManagerResult<List<String>> result) {
if (!ViewCompat.isAttachedToWindow(AccountSigninView.this)) {
// This callback is invoked after AccountSigninView is detached from window
// (e.g., Chrome is minimized). Updating view now is redundant and dangerous
// (getFragmentManager() can return null, etc.). See https://crbug.com/733117.
return; return;
} }
AccountManagerFacade accountManager = AccountManagerFacade.get(); final List<String> accountNames;
accountManager.getGoogleAccountNames(new Callback<AccountManagerResult<List<String>>>() { try {
@Override accountNames = result.get();
public void onResult(AccountManagerResult<List<String>> result) { } catch (GmsAvailabilityException e) {
if (!ViewCompat.isAttachedToWindow(AccountSigninView.this)) { dismissGmsUpdatingDialog();
// This callback is invoked after AccountSigninView is detached from window showGmsErrorDialog(e.getGmsAvailabilityReturnCode());
// (e.g., Chrome is minimized). Updating view now is redundant and dangerous return;
// (getFragmentManager() can return null, etc.). See https://crbug.com/733117. } catch (GmsJustUpdatedException e) {
return; dismissGmsErrorDialog();
} showGmsUpdatingDialog();
return;
} catch (AccountManagerDelegateException e) {
Log.e(TAG, "Unknown exception from AccountManagerFacade.", e);
dismissGmsErrorDialog();
dismissGmsUpdatingDialog();
return;
}
dismissGmsErrorDialog();
dismissGmsUpdatingDialog();
List<String> oldAccountNames = mAccountNames; if (mSelectedAccountName != null) {
try { if (accountNames.contains(mSelectedAccountName)) return;
mAccountNames = result.get();
} catch (GmsAvailabilityException e) {
dismissGmsUpdatingDialog();
showGmsErrorDialog(e.getGmsAvailabilityReturnCode());
return;
} catch (GmsJustUpdatedException e) {
dismissGmsErrorDialog();
showGmsUpdatingDialog();
return;
} catch (AccountManagerDelegateException e) {
Log.e(TAG, "Unknown exception from AccountManagerFacade.", e);
dismissGmsErrorDialog();
dismissGmsUpdatingDialog();
return;
}
dismissGmsErrorDialog();
dismissGmsUpdatingDialog();
if (mSelectedAccountName != null) { if (mUndoBehavior == UNDO_BACK_TO_SELECTION) {
// If sign-in completed in the mean time, return in order to avoid showing the RecordUserAction.record("Signin_Undo_Signin");
// wrong state in the UI. showSigninPage();
return; } else {
} mListener.onFailedToSetForcedAccount(mSelectedAccountName);
}
return;
}
int oldSelectedAccount = mSigninChooseView.getSelectedAccountPosition(); List<String> oldAccountNames = mAccountNames;
AccountSelectionResult selection = selectAccountAfterAccountsUpdate( mAccountNames = accountNames;
oldAccountNames, mAccountNames, oldSelectedAccount);
int accountToSelect = selection.getSelectedAccountIndex(); int oldSelectedAccount = mSigninChooseView.getSelectedAccountPosition();
boolean shouldJumpToConfirmationScreen = selection.shouldJumpToConfirmationScreen(); AccountSelectionResult selection = selectAccountAfterAccountsUpdate(
oldAccountNames, mAccountNames, oldSelectedAccount);
mSigninChooseView.updateAccounts(mAccountNames, accountToSelect, mProfileData); int accountToSelect = selection.getSelectedAccountIndex();
setUpSigninButton(!mAccountNames.isEmpty()); boolean shouldJumpToConfirmationScreen = selection.shouldJumpToConfirmationScreen();
mProfileData.update(mAccountNames);
mSigninChooseView.updateAccounts(mAccountNames, accountToSelect, mProfileData);
boolean selectedAccountChanged = oldAccountNames != null setUpSigninButton(!mAccountNames.isEmpty());
&& !oldAccountNames.isEmpty() mProfileData.update(mAccountNames);
&& (mAccountNames.isEmpty()
|| mAccountNames.get(accountToSelect) boolean selectedAccountChanged = oldAccountNames != null && !oldAccountNames.isEmpty()
.equals(oldAccountNames.get(oldSelectedAccount))); && (mAccountNames.isEmpty()
if (selectedAccountChanged) { || mAccountNames.get(accountToSelect)
// Any dialogs that may have been showing are now invalid (they were created .equals(oldAccountNames.get(oldSelectedAccount)));
// for the previously selected account). if (selectedAccountChanged) {
ConfirmSyncDataStateMachine.cancelAllDialogs(mDelegate.getFragmentManager()); // Any dialogs that may have been showing are now invalid (they were created
} // for the previously selected account).
ConfirmSyncDataStateMachine.cancelAllDialogs(mDelegate.getFragmentManager());
}
if (shouldJumpToConfirmationScreen) { if (shouldJumpToConfirmationScreen) {
showConfirmSigninPageAccountTrackerServiceCheck(); showConfirmSigninPageAccountTrackerServiceCheck();
} }
}
});
} }
private boolean hasGmsError() { private boolean hasGmsError() {
...@@ -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