Commit 7ea27b8d authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Commit Bot

[Android] Remove ChromeSigninController usage from chrome/browser/sync/settings

Bug: 1049540
Change-Id: I918562e135600769120247f82840c00c23350eb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2066743Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744723}
parent 2d5dc722
......@@ -48,8 +48,8 @@ import org.chromium.chrome.browser.signin.SigninUtils;
import org.chromium.chrome.browser.superviseduser.FilteringBehavior;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.GAIAServiceType;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.metrics.SignoutReason;
import java.util.List;
......@@ -164,7 +164,8 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
mSignedInAccountName = ChromeSigninController.get().getSignedInAccountName();
mSignedInAccountName = CoreAccountInfo.getEmailFrom(
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo());
if (mSignedInAccountName == null) {
// The AccountManagementFragment can only be shown when the user is signed in. If the
// user is signed out, exit the fragment.
......@@ -368,7 +369,7 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
public void onSignOutClicked(boolean forceWipeUserData) {
// In case the user reached this fragment without being signed in, we guard the sign out so
// we do not hit a native crash.
if (!ChromeSigninController.get().isSignedIn()) return;
if (!IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) return;
final DialogFragment clearDataProgressDialog = new ClearDataProgressDialog();
IdentityServicesProvider.get().getSigninManager().signOut(
......
......@@ -39,7 +39,6 @@ import org.chromium.chrome.browser.sync.TrustedVaultClient;
import org.chromium.chrome.browser.sync.ui.PassphraseCreationDialogFragment;
import org.chromium.chrome.browser.sync.ui.PassphraseDialogFragment;
import org.chromium.chrome.browser.sync.ui.PassphraseTypeDialogFragment;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.PassphraseType;
......@@ -219,9 +218,8 @@ public class ManageSyncSettings extends PreferenceFragmentCompat
* from this state.
*/
private void updateSyncPreferences() {
// TODO(crbug.com/1041815): Migrate away from ChromeSigninController and use IdentityManager
// instead.
String signedInAccountName = ChromeSigninController.get().getSignedInAccountName();
String signedInAccountName = CoreAccountInfo.getEmailFrom(
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo());
if (signedInAccountName == null) {
// May happen if account is removed from the device while this screen is shown.
getActivity().finish();
......
......@@ -31,7 +31,7 @@ import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.ProfileSyncService.SyncStateChangedListener;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.AccountsChangeObserver;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.metrics.SigninAccessPoint;
import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.ui.base.ViewUtils;
......@@ -162,9 +162,10 @@ public class SignInPreference
return;
}
String accountName = ChromeSigninController.get().getSignedInAccountName();
if (accountName != null) {
setupSignedIn(accountName);
CoreAccountInfo accountInfo =
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo();
if (accountInfo != null) {
setupSignedIn(accountInfo.getEmail());
return;
}
......
......@@ -62,7 +62,6 @@ import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils.SyncError;
import org.chromium.chrome.browser.sync.ui.PassphraseDialogFragment;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.metrics.SigninAccessPoint;
import org.chromium.components.signin.metrics.SignoutReason;
......@@ -310,9 +309,8 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
mProfileSyncService.addSyncStateChangedListener(this);
mSigninPreference.registerForUpdates();
// TODO(crbug.com/1041815): Migrate away from ChromeSigninController and use IdentityManager
// instead.
if (!mIsFromSigninScreen || ChromeSigninController.get().isSignedIn()) {
if (!mIsFromSigninScreen
|| IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) {
return;
}
......@@ -483,10 +481,11 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
}
if (mCurrentSyncError == SyncError.AUTH_ERROR) {
// TODO(crbug.com/1041815): Migrate away from ChromeSigninController and use
// IdentityManager instead.
AccountManagerFacade.get().updateCredentials(
ChromeSigninController.get().getSignedInUser(), getActivity(), null);
CoreAccountInfo.getAndroidAccountFrom(IdentityServicesProvider.get()
.getIdentityManager()
.getPrimaryAccountInfo()),
getActivity(), null);
return;
}
......@@ -500,9 +499,8 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
}
if (mCurrentSyncError == SyncError.OTHER_ERRORS) {
// TODO(crbug.com/1041815): Migrate away from ChromeSigninController and use
// IdentityManager instead.
final Account account = ChromeSigninController.get().getSignedInUser();
final Account account = CoreAccountInfo.getAndroidAccountFrom(
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo());
// TODO(https://crbug.com/873116): Pass the correct reason for the signout.
IdentityServicesProvider.get().getSigninManager().signOut(
SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS,
......@@ -567,9 +565,7 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
closeDialogIfOpen(FRAGMENT_ENTER_PASSPHRASE);
}
// TODO(crbug.com/1041815): Migrate away from ChromeSigninController and use IdentityManager
// instead.
if (!ChromeSigninController.get().isSignedIn()) {
if (!IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) {
getPreferenceScreen().removePreference(mManageYourGoogleAccount);
getPreferenceScreen().removePreference(mSyncCategory);
return;
......
......@@ -28,11 +28,11 @@ import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.LaunchIntentDispatcher;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider.CustomTabsUiType;
import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider;
import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.chrome.browser.sync.GoogleServiceAuthError;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.TrustedVaultClient;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.components.sync.StopSource;
......@@ -145,7 +145,7 @@ public class SyncSettingsUtils {
* Return a short summary of the current sync status.
*/
public static String getSyncStatusSummary(Context context) {
if (!ChromeSigninController.get().isSignedIn()) return "";
if (!IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) return "";
ProfileSyncService profileSyncService = ProfileSyncService.get();
Resources res = context.getResources();
......@@ -180,7 +180,6 @@ public class SyncSettingsUtils {
return res.getString(R.string.sync_error_generic);
}
String accountName = ChromeSigninController.get().getSignedInAccountName();
boolean syncEnabled = AndroidSyncSettings.get().isSyncEnabled();
if (syncEnabled) {
if (!profileSyncService.isSyncActive()) {
......@@ -206,7 +205,7 @@ public class SyncSettingsUtils {
* Returns an icon that represents the current sync state.
*/
public static @Nullable Drawable getSyncStatusIcon(Context context) {
if (!ChromeSigninController.get().isSignedIn()) return null;
if (!IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) return null;
ProfileSyncService profileSyncService = ProfileSyncService.get();
if (profileSyncService == null || !AndroidSyncSettings.get().isSyncEnabled()) {
......@@ -309,7 +308,7 @@ public class SyncSettingsUtils {
* @param activity The activity to use for starting the intent.
*/
public static void openGoogleMyAccount(Activity activity) {
assert ChromeSigninController.get().isSignedIn();
assert IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount();
RecordUserAction.record("SyncPreferences_ManageGoogleAccountClicked");
openCustomTabWithURL(activity, MY_ACCOUNT_URL);
}
......
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