Commit e875efb9 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android][Signin] Introduce legacy methods to replace ChromeSigninController

Adds setLegacySyncAccountEmail/getLegacySyncAccountEmail to
SigninPreferencesManager. These methods will be used until the
downstream code is migrated to IdentityManager. Most of
ChromeSigninController is removed - only get() and getSignedInAccountName
are kept for now. The class will be removed completely as soon as
downstream usages are migrated to SigninPreferencesManager.

Bug: 10918587, 1046412
Change-Id: Ia297b48632ae9ec9e614024e50853981ce7fd156
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339979Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799043}
parent 0a7565bc
...@@ -16,7 +16,6 @@ import org.chromium.base.ContextUtils; ...@@ -16,7 +16,6 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.TraceEvent;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
...@@ -26,7 +25,6 @@ import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; ...@@ -26,7 +25,6 @@ import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.sync.AndroidSyncSettings; import org.chromium.chrome.browser.sync.AndroidSyncSettings;
import org.chromium.components.signin.AccountTrackerService; import org.chromium.components.signin.AccountTrackerService;
import org.chromium.components.signin.AccountUtils; import org.chromium.components.signin.AccountUtils;
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.identitymanager.ClearAccountsAction; import org.chromium.components.signin.identitymanager.ClearAccountsAction;
import org.chromium.components.signin.identitymanager.ConsentLevel; import org.chromium.components.signin.identitymanager.ConsentLevel;
...@@ -238,25 +236,6 @@ public class SigninManager ...@@ -238,25 +236,6 @@ public class SigninManager
mIdentityManager.addObserver(this); mIdentityManager.addObserver(this);
reloadAllAccountsFromSystem(); reloadAllAccountsFromSystem();
reconcileJavaAndNativeStates();
}
private void reconcileJavaAndNativeStates() {
try (TraceEvent ignored = TraceEvent.scoped("SigninManager.reconcileJavaAndNativeStates")) {
ThreadUtils.assertOnUiThread();
// The sign out flow starts by clearing the signed in user in the ChromeSigninController
// on the Java side, and then performs a sign out on the native side. If there is a
// crash on the native side then the signin state may get out of sync. Make sure that
// the native side is signed out if the Java side doesn't have a currently signed in
// user.
if (!ChromeSigninController.get().isSignedIn()
&& mIdentityManager.hasPrimaryAccount()) {
Log.w(TAG, "Signed in state got out of sync, forcing native sign out");
// TODO(https://crbug.com/873116): Pass the correct reason for the signout.
signOut(SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS);
}
}
} }
/** /**
...@@ -488,10 +467,11 @@ public class SigninManager ...@@ -488,10 +467,11 @@ public class SigninManager
return; return;
} }
// Cache the signed-in account name. This must be done after the native call, otherwise // TODO(https://crbug.com/1091858): Remove this after migrating the legacy code that uses
// sync tries to start without being signed in natively and crashes. // the sync account before the native is loaded.
ChromeSigninController.get().setSignedInAccountName( SigninPreferencesManager.getInstance().setLegacySyncAccountEmail(
mSignInState.mCoreAccountInfo.getEmail()); mSignInState.mCoreAccountInfo.getEmail());
enableSync(mSignInState.mCoreAccountInfo); enableSync(mSignInState.mCoreAccountInfo);
if (mSignInState.mCallback != null) { if (mSignInState.mCallback != null) {
...@@ -649,9 +629,10 @@ public class SigninManager ...@@ -649,9 +629,10 @@ public class SigninManager
Log.d(TAG, "On native signout, wipe user data: " + mSignOutState.mShouldWipeUserData); Log.d(TAG, "On native signout, wipe user data: " + mSignOutState.mShouldWipeUserData);
// Native sign-out must happen before resetting the account so data is deleted correctly. // TODO(https://crbug.com/1091858): Remove this after migrating the legacy code that uses
// http://crbug.com/589028 // the sync account before the native is loaded.
ChromeSigninController.get().setSignedInAccountName(null); SigninPreferencesManager.getInstance().setLegacySyncAccountEmail(null);
if (mSignOutState.mSignOutCallback != null) mSignOutState.mSignOutCallback.preWipeData(); if (mSignOutState.mSignOutCallback != null) mSignOutState.mSignOutCallback.preWipeData();
disableSyncAndWipeData(mSignOutState.mShouldWipeUserData, this::finishSignOut); disableSyncAndWipeData(mSignOutState.mShouldWipeUserData, this::finishSignOut);
mAccountTrackerService.invalidateAccountSeedStatus(true); mAccountTrackerService.invalidateAccountSeedStatus(true);
......
...@@ -168,4 +168,24 @@ public class SigninPreferencesManager { ...@@ -168,4 +168,24 @@ public class SigninPreferencesManager {
public void clearNewTabPageSigninPromoSuppressionPeriodStart() { public void clearNewTabPageSigninPromoSuppressionPeriodStart() {
mManager.removeKey(ChromePreferenceKeys.SIGNIN_PROMO_NTP_PROMO_SUPPRESSION_PERIOD_START); mManager.removeKey(ChromePreferenceKeys.SIGNIN_PROMO_NTP_PROMO_SUPPRESSION_PERIOD_START);
} }
/**
* Sets the email of the account for which sync was enabled.
*
* @param accountEmail The email of the sync account or null if sync isn't enabled.
*/
// TODO(https://crbug.com/1091858): Remove this after migrating the legacy code that uses
// the sync account before the native is loaded.
public void setLegacySyncAccountEmail(@Nullable String accountEmail) {
mManager.writeString(ChromePreferenceKeys.SIGNIN_LEGACY_SYNC_ACCOUNT_EMAIL, accountEmail);
}
/**
* The email of the account for which sync was enabled.
*/
// TODO(https://crbug.com/1091858): Remove this after migrating the legacy code that uses
// the sync account before the native is loaded.
public String getLegacySyncAccountEmail() {
return mManager.readString(ChromePreferenceKeys.SIGNIN_LEGACY_SYNC_ACCOUNT_EMAIL, null);
}
} }
...@@ -653,6 +653,10 @@ public final class ChromePreferenceKeys { ...@@ -653,6 +653,10 @@ public final class ChromePreferenceKeys {
public static final String SIGNIN_PROMO_SETTINGS_PERSONALIZED_DISMISSED = public static final String SIGNIN_PROMO_SETTINGS_PERSONALIZED_DISMISSED =
"settings_personalized_signin_promo_dismissed"; "settings_personalized_signin_promo_dismissed";
// TODO(https://crbug.com/1091858): Remove this after migrating the legacy code that uses
// the sync account before the native is loaded.
public static final String SIGNIN_LEGACY_SYNC_ACCOUNT_EMAIL = "google.services.username";
public static final String SNAPSHOT_DATABASE_REMOVED = "snapshot_database_removed"; public static final String SNAPSHOT_DATABASE_REMOVED = "snapshot_database_removed";
public static final String SURVEY_DATE_LAST_ROLLED = "last_rolled_for_chrome_survey_key"; public static final String SURVEY_DATE_LAST_ROLLED = "last_rolled_for_chrome_survey_key";
......
...@@ -169,6 +169,7 @@ public class GrandfatheredChromePreferenceKeys { ...@@ -169,6 +169,7 @@ public class GrandfatheredChromePreferenceKeys {
ChromePreferenceKeys.SIGNIN_PROMO_NTP_PROMO_SUPPRESSION_PERIOD_START, ChromePreferenceKeys.SIGNIN_PROMO_NTP_PROMO_SUPPRESSION_PERIOD_START,
ChromePreferenceKeys.SIGNIN_PROMO_PERSONALIZED_DECLINED, ChromePreferenceKeys.SIGNIN_PROMO_PERSONALIZED_DECLINED,
ChromePreferenceKeys.SIGNIN_PROMO_SETTINGS_PERSONALIZED_DISMISSED, ChromePreferenceKeys.SIGNIN_PROMO_SETTINGS_PERSONALIZED_DISMISSED,
ChromePreferenceKeys.SIGNIN_LEGACY_SYNC_ACCOUNT_EMAIL,
ChromePreferenceKeys.SNAPSHOT_DATABASE_REMOVED, ChromePreferenceKeys.SNAPSHOT_DATABASE_REMOVED,
ChromePreferenceKeys.SURVEY_DATE_LAST_ROLLED, ChromePreferenceKeys.SURVEY_DATE_LAST_ROLLED,
ChromePreferenceKeys.SURVEY_INFO_BAR_DISPLAYED, ChromePreferenceKeys.SURVEY_INFO_BAR_DISPLAYED,
......
...@@ -4,13 +4,12 @@ ...@@ -4,13 +4,12 @@
package org.chromium.components.signin; package org.chromium.components.signin;
import android.accounts.Account;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
/** /**
* Caches the signed-in username in the app prefs. * Caches the signed-in username in the app prefs.
*/ */
@Deprecated
public class ChromeSigninController { public class ChromeSigninController {
public static final String TAG = "ChromeSigninController"; public static final String TAG = "ChromeSigninController";
...@@ -36,25 +35,8 @@ public class ChromeSigninController { ...@@ -36,25 +35,8 @@ public class ChromeSigninController {
return sChromeSigninController; return sChromeSigninController;
} }
public Account getSignedInUser() { // TODO(https://crbug.com/1046412): Remove after migrating downstream usages to
String syncAccountName = getSignedInAccountName(); // SigninPreferencesManager.
if (syncAccountName == null) {
return null;
}
return AccountUtils.createAccountFromName(syncAccountName);
}
public boolean isSignedIn() {
return getSignedInAccountName() != null;
}
public void setSignedInAccountName(String accountName) {
ContextUtils.getAppSharedPreferences()
.edit()
.putString(SIGNED_IN_ACCOUNT_KEY, accountName)
.apply();
}
public String getSignedInAccountName() { public String getSignedInAccountName() {
return ContextUtils.getAppSharedPreferences().getString(SIGNED_IN_ACCOUNT_KEY, null); return ContextUtils.getAppSharedPreferences().getString(SIGNED_IN_ACCOUNT_KEY, null);
} }
......
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