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