Commit 568b29a2 authored by Side Yilmaz's avatar Side Yilmaz Committed by Commit Bot

Replace IdentityServicesProvider functions in sync classes.

This CL replaces deprecated functions of IdentityServicesProvider with
the newer service getters with profile parameter. Currently,
IdentityServicesProvider gives |Profile#getLastUsedRegularProfile| param
to the native. By this CL, sync classes pass
|Profile#getLastUsedRegularProfile| to the IdentityServicesProvider to
be used by native.

Note: This CL is only clean-up and does not change code behaviour.

Bug: 1041781, 1075562
Change-Id: Ib987c4b1e57c6490cd3b844dd9786a3b8459fe17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2253749Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarRamin Halavati <rhalavati@chromium.org>
Commit-Queue: Side YILMAZ <sideyilmaz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781308}
parent dc5b272b
...@@ -75,8 +75,9 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen ...@@ -75,8 +75,9 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
updateSyncStateFromAndroid(); updateSyncStateFromAndroid();
IdentityServicesProvider.get().getSigninManager().addSignInStateObserver( IdentityServicesProvider.get()
new SigninManager.SignInStateObserver() { .getSigninManager(Profile.getLastUsedRegularProfile())
.addSignInStateObserver(new SigninManager.SignInStateObserver() {
@Override @Override
public void onSignedIn() { public void onSignedIn() {
mProfileSyncService.requestStart(); mProfileSyncService.requestStart();
......
...@@ -19,6 +19,7 @@ import org.chromium.chrome.browser.notifications.NotificationBuilderFactory; ...@@ -19,6 +19,7 @@ import org.chromium.chrome.browser.notifications.NotificationBuilderFactory;
import org.chromium.chrome.browser.notifications.NotificationConstants; import org.chromium.chrome.browser.notifications.NotificationConstants;
import org.chromium.chrome.browser.notifications.NotificationUmaTracker; import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
import org.chromium.chrome.browser.notifications.channels.ChromeChannelDefinitions; import org.chromium.chrome.browser.notifications.channels.ChromeChannelDefinitions;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.SettingsLauncher; import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl; import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
...@@ -222,8 +223,9 @@ public class SyncNotificationController implements ProfileSyncService.SyncStateC ...@@ -222,8 +223,9 @@ public class SyncNotificationController implements ProfileSyncService.SyncStateC
*/ */
private void maybeCreateKeyRetrievalNotification() { private void maybeCreateKeyRetrievalNotification() {
CoreAccountInfo primaryAccountInfo = CoreAccountInfo primaryAccountInfo =
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo( IdentityServicesProvider.get()
ConsentLevel.SYNC); .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC);
// Check/set |mTrustedVaultNotificationShownOrCreating| here to ensure notification is not // Check/set |mTrustedVaultNotificationShownOrCreating| here to ensure notification is not
// shown again immediately after cancelling (Sync state might be changed often) and there // shown again immediately after cancelling (Sync state might be changed often) and there
// is only one asynchronous createKeyRetrievalIntent() attempt at the time triggered by // is only one asynchronous createKeyRetrievalIntent() attempt at the time triggered by
......
...@@ -137,7 +137,9 @@ public class AccountManagementFragment extends PreferenceFragmentCompat ...@@ -137,7 +137,9 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
IdentityServicesProvider.get().getSigninManager().addSignInStateObserver(this); IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
.addSignInStateObserver(this);
mProfileDataCache.addObserver(this); mProfileDataCache.addObserver(this);
List<String> accountNames = AccountUtils.toAccountNames( List<String> accountNames = AccountUtils.toAccountNames(
AccountManagerFacadeProvider.getInstance().tryGetGoogleAccounts()); AccountManagerFacadeProvider.getInstance().tryGetGoogleAccounts());
...@@ -148,7 +150,9 @@ public class AccountManagementFragment extends PreferenceFragmentCompat ...@@ -148,7 +150,9 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
IdentityServicesProvider.get().getSigninManager().removeSignInStateObserver(this); IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
.removeSignInStateObserver(this);
mProfileDataCache.removeObserver(this); mProfileDataCache.removeObserver(this);
} }
...@@ -159,8 +163,9 @@ public class AccountManagementFragment extends PreferenceFragmentCompat ...@@ -159,8 +163,9 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
if (getPreferenceScreen() != null) getPreferenceScreen().removeAll(); if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
mSignedInAccountName = CoreAccountInfo.getEmailFrom( mSignedInAccountName = CoreAccountInfo.getEmailFrom(
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo( IdentityServicesProvider.get()
ConsentLevel.SYNC)); .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC));
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.
...@@ -366,24 +371,30 @@ public class AccountManagementFragment extends PreferenceFragmentCompat ...@@ -366,24 +371,30 @@ 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 (!IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) return; if (!IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.hasPrimaryAccount()) {
return;
}
final DialogFragment clearDataProgressDialog = new ClearDataProgressDialog(); final DialogFragment clearDataProgressDialog = new ClearDataProgressDialog();
IdentityServicesProvider.get().getSigninManager().signOut( IdentityServicesProvider.get()
SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS, new SigninManager.SignOutCallback() { .getSigninManager(Profile.getLastUsedRegularProfile())
@Override .signOut(SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS,
public void preWipeData() { new SigninManager.SignOutCallback() {
clearDataProgressDialog.show( @Override
getFragmentManager(), CLEAR_DATA_PROGRESS_DIALOG_TAG); public void preWipeData() {
} clearDataProgressDialog.show(
getFragmentManager(), CLEAR_DATA_PROGRESS_DIALOG_TAG);
@Override }
public void signOutComplete() {
if (clearDataProgressDialog.isAdded()) { @Override
clearDataProgressDialog.dismissAllowingStateLoss(); public void signOutComplete() {
} if (clearDataProgressDialog.isAdded()) {
} clearDataProgressDialog.dismissAllowingStateLoss();
}, forceWipeUserData); }
}
},
forceWipeUserData);
} }
// SignInStateObserver implementation: // SignInStateObserver implementation:
......
...@@ -311,8 +311,9 @@ public class ManageSyncSettings extends PreferenceFragmentCompat ...@@ -311,8 +311,9 @@ public class ManageSyncSettings extends PreferenceFragmentCompat
*/ */
private void updateSyncPreferences() { private void updateSyncPreferences() {
String signedInAccountName = CoreAccountInfo.getEmailFrom( String signedInAccountName = CoreAccountInfo.getEmailFrom(
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo( IdentityServicesProvider.get()
ConsentLevel.SYNC)); .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC));
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();
...@@ -523,8 +524,9 @@ public class ManageSyncSettings extends PreferenceFragmentCompat ...@@ -523,8 +524,9 @@ public class ManageSyncSettings extends PreferenceFragmentCompat
displayPassphraseDialog(); displayPassphraseDialog();
} else if (mProfileSyncService.isTrustedVaultKeyRequired()) { } else if (mProfileSyncService.isTrustedVaultKeyRequired()) {
CoreAccountInfo primaryAccountInfo = CoreAccountInfo primaryAccountInfo =
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo( IdentityServicesProvider.get()
ConsentLevel.SYNC); .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC);
if (primaryAccountInfo != null) { if (primaryAccountInfo != null) {
SyncSettingsUtils.openTrustedVaultKeyRetrievalDialog( SyncSettingsUtils.openTrustedVaultKeyRetrievalDialog(
this, primaryAccountInfo, REQUEST_CODE_TRUSTED_VAULT_KEY_RETRIEVAL); this, primaryAccountInfo, REQUEST_CODE_TRUSTED_VAULT_KEY_RETRIEVAL);
...@@ -615,8 +617,10 @@ public class ManageSyncSettings extends PreferenceFragmentCompat ...@@ -615,8 +617,10 @@ public class ManageSyncSettings extends PreferenceFragmentCompat
private void cancelSync() { private void cancelSync() {
RecordUserAction.record("Signin_Signin_CancelAdvancedSyncSettings"); RecordUserAction.record("Signin_Signin_CancelAdvancedSyncSettings");
IdentityServicesProvider.get().getSigninManager().signOut( IdentityServicesProvider.get()
org.chromium.components.signin.metrics.SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS); .getSigninManager(Profile.getLastUsedRegularProfile())
.signOut(org.chromium.components.signin.metrics.SignoutReason
.USER_CLICKED_SIGNOUT_SETTINGS);
getActivity().finish(); getActivity().finish();
} }
......
...@@ -18,6 +18,7 @@ import org.chromium.chrome.R; ...@@ -18,6 +18,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager; import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.DisplayableProfileData; import org.chromium.chrome.browser.signin.DisplayableProfileData;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView; import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView;
...@@ -93,7 +94,9 @@ public class SignInPreference ...@@ -93,7 +94,9 @@ public class SignInPreference
*/ */
public void registerForUpdates() { public void registerForUpdates() {
mAccountManagerFacade.addObserver(this); mAccountManagerFacade.addObserver(this);
IdentityServicesProvider.get().getSigninManager().addSignInAllowedObserver(this); IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
.addSignInAllowedObserver(this);
mProfileDataCache.addObserver(this); mProfileDataCache.addObserver(this);
FirstRunSignInProcessor.updateSigninManagerFirstRunCheckDone(); FirstRunSignInProcessor.updateSigninManagerFirstRunCheckDone();
AndroidSyncSettings.get().registerObserver(this); AndroidSyncSettings.get().registerObserver(this);
...@@ -112,7 +115,9 @@ public class SignInPreference ...@@ -112,7 +115,9 @@ public class SignInPreference
*/ */
public void unregisterForUpdates() { public void unregisterForUpdates() {
mAccountManagerFacade.removeObserver(this); mAccountManagerFacade.removeObserver(this);
IdentityServicesProvider.get().getSigninManager().removeSignInAllowedObserver(this); IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
.removeSignInAllowedObserver(this);
mProfileDataCache.removeObserver(this); mProfileDataCache.removeObserver(this);
AndroidSyncSettings.get().unregisterObserver(this); AndroidSyncSettings.get().unregisterObserver(this);
ProfileSyncService syncService = ProfileSyncService.get(); ProfileSyncService syncService = ProfileSyncService.get();
...@@ -161,14 +166,17 @@ public class SignInPreference ...@@ -161,14 +166,17 @@ public class SignInPreference
/** Updates the title, summary, and image based on the current sign-in state. */ /** Updates the title, summary, and image based on the current sign-in state. */
private void update() { private void update() {
if (IdentityServicesProvider.get().getSigninManager().isSigninDisabledByPolicy()) { if (IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
.isSigninDisabledByPolicy()) {
setupSigninDisabled(); setupSigninDisabled();
return; return;
} }
CoreAccountInfo accountInfo = CoreAccountInfo accountInfo =
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo( IdentityServicesProvider.get()
ConsentLevel.SYNC); .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC);
if (accountInfo != null) { if (accountInfo != null) {
setupSignedIn(accountInfo.getEmail()); setupSignedIn(accountInfo.getEmail());
return; return;
......
...@@ -312,7 +312,9 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat ...@@ -312,7 +312,9 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
mSigninPreference.registerForUpdates(); mSigninPreference.registerForUpdates();
if (!mIsFromSigninScreen if (!mIsFromSigninScreen
|| IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) { || IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.hasPrimaryAccount()) {
return; return;
} }
...@@ -485,7 +487,7 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat ...@@ -485,7 +487,7 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
AccountManagerFacadeProvider.getInstance().updateCredentials( AccountManagerFacadeProvider.getInstance().updateCredentials(
CoreAccountInfo.getAndroidAccountFrom( CoreAccountInfo.getAndroidAccountFrom(
IdentityServicesProvider.get() IdentityServicesProvider.get()
.getIdentityManager() .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC)), .getPrimaryAccountInfo(ConsentLevel.SYNC)),
getActivity(), null); getActivity(), null);
return; return;
...@@ -502,15 +504,20 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat ...@@ -502,15 +504,20 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
if (mCurrentSyncError == SyncError.OTHER_ERRORS) { if (mCurrentSyncError == SyncError.OTHER_ERRORS) {
final Account account = CoreAccountInfo.getAndroidAccountFrom( final Account account = CoreAccountInfo.getAndroidAccountFrom(
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo( IdentityServicesProvider.get()
ConsentLevel.SYNC)); .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC));
// 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()
SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS, .getSigninManager(Profile.getLastUsedRegularProfile())
() .signOut(SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS,
-> IdentityServicesProvider.get().getSigninManager().signIn( ()
SigninAccessPoint.SYNC_ERROR_CARD, account, null), -> IdentityServicesProvider.get()
false); .getSigninManager(
Profile.getLastUsedRegularProfile())
.signIn(SigninAccessPoint.SYNC_ERROR_CARD, account,
null),
false);
return; return;
} }
...@@ -522,8 +529,9 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat ...@@ -522,8 +529,9 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
if (mCurrentSyncError == SyncError.TRUSTED_VAULT_KEY_REQUIRED_FOR_EVERYTHING if (mCurrentSyncError == SyncError.TRUSTED_VAULT_KEY_REQUIRED_FOR_EVERYTHING
|| mCurrentSyncError == SyncError.TRUSTED_VAULT_KEY_REQUIRED_FOR_PASSWORDS) { || mCurrentSyncError == SyncError.TRUSTED_VAULT_KEY_REQUIRED_FOR_PASSWORDS) {
CoreAccountInfo primaryAccountInfo = CoreAccountInfo primaryAccountInfo =
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo( IdentityServicesProvider.get()
ConsentLevel.SYNC); .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC);
if (primaryAccountInfo != null) { if (primaryAccountInfo != null) {
SyncSettingsUtils.openTrustedVaultKeyRetrievalDialog( SyncSettingsUtils.openTrustedVaultKeyRetrievalDialog(
this, primaryAccountInfo, REQUEST_CODE_TRUSTED_VAULT_KEY_RETRIEVAL); this, primaryAccountInfo, REQUEST_CODE_TRUSTED_VAULT_KEY_RETRIEVAL);
...@@ -570,7 +578,9 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat ...@@ -570,7 +578,9 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
closeDialogIfOpen(FRAGMENT_ENTER_PASSPHRASE); closeDialogIfOpen(FRAGMENT_ENTER_PASSPHRASE);
} }
if (!IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) { if (!IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.hasPrimaryAccount()) {
getPreferenceScreen().removePreference(mManageYourGoogleAccount); getPreferenceScreen().removePreference(mManageYourGoogleAccount);
getPreferenceScreen().removePreference(mSyncCategory); getPreferenceScreen().removePreference(mSyncCategory);
return; return;
...@@ -689,8 +699,9 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat ...@@ -689,8 +699,9 @@ public class SyncAndServicesSettings extends PreferenceFragmentCompat
private void cancelSync() { private void cancelSync() {
RecordUserAction.record("Signin_Signin_CancelAdvancedSyncSettings"); RecordUserAction.record("Signin_Signin_CancelAdvancedSyncSettings");
IdentityServicesProvider.get().getSigninManager().signOut( IdentityServicesProvider.get()
SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS); .getSigninManager(Profile.getLastUsedRegularProfile())
.signOut(SignoutReason.USER_CLICKED_SIGNOUT_SETTINGS);
getActivity().finish(); getActivity().finish();
} }
......
...@@ -29,6 +29,7 @@ import org.chromium.chrome.browser.IntentHandler; ...@@ -29,6 +29,7 @@ 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.profiles.Profile;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; 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;
...@@ -149,7 +150,11 @@ public class SyncSettingsUtils { ...@@ -149,7 +150,11 @@ 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 (!IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) return ""; if (!IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.hasPrimaryAccount()) {
return "";
}
ProfileSyncService profileSyncService = ProfileSyncService.get(); ProfileSyncService profileSyncService = ProfileSyncService.get();
Resources res = context.getResources(); Resources res = context.getResources();
...@@ -209,7 +214,11 @@ public class SyncSettingsUtils { ...@@ -209,7 +214,11 @@ 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 (!IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount()) return null; if (!IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.hasPrimaryAccount()) {
return null;
}
ProfileSyncService profileSyncService = ProfileSyncService.get(); ProfileSyncService profileSyncService = ProfileSyncService.get();
if (profileSyncService == null || !AndroidSyncSettings.get().isSyncEnabled()) { if (profileSyncService == null || !AndroidSyncSettings.get().isSyncEnabled()) {
...@@ -312,7 +321,9 @@ public class SyncSettingsUtils { ...@@ -312,7 +321,9 @@ 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 IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount(); assert IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.hasPrimaryAccount();
RecordUserAction.record("SyncPreferences_ManageGoogleAccountClicked"); RecordUserAction.record("SyncPreferences_ManageGoogleAccountClicked");
openCustomTabWithURL(activity, MY_ACCOUNT_URL); openCustomTabWithURL(activity, MY_ACCOUNT_URL);
} }
......
...@@ -16,6 +16,7 @@ import androidx.fragment.app.FragmentTransaction; ...@@ -16,6 +16,7 @@ import androidx.fragment.app.FragmentTransaction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer; import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.chrome.browser.sync.ProfileSyncService; import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.SyncController; import org.chromium.chrome.browser.sync.SyncController;
...@@ -50,8 +51,9 @@ public class PassphraseActivity extends AppCompatActivity ...@@ -50,8 +51,9 @@ public class PassphraseActivity extends AppCompatActivity
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Account account = CoreAccountInfo.getAndroidAccountFrom( Account account = CoreAccountInfo.getAndroidAccountFrom(
IdentityServicesProvider.get().getIdentityManager().getPrimaryAccountInfo( IdentityServicesProvider.get()
ConsentLevel.SYNC)); .getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.SYNC));
if (account == null) { if (account == null) {
finish(); finish();
return; return;
......
...@@ -17,6 +17,7 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -17,6 +17,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.SigninHelper; import org.chromium.chrome.browser.signin.SigninHelper;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -61,7 +62,9 @@ public class SyncTest { ...@@ -61,7 +62,9 @@ public class SyncTest {
mSyncTestRule.setUpAccountAndSignInForTesting(); mSyncTestRule.setUpAccountAndSignInForTesting();
CriteriaHelper.pollUiThread( CriteriaHelper.pollUiThread(
() ()
-> IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount(), -> IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.hasPrimaryAccount(),
"Timed out checking that hasPrimaryAccount() == true", SyncTestUtil.TIMEOUT_MS, "Timed out checking that hasPrimaryAccount() == true", SyncTestUtil.TIMEOUT_MS,
SyncTestUtil.INTERVAL_MS); SyncTestUtil.INTERVAL_MS);
...@@ -72,7 +75,9 @@ public class SyncTest { ...@@ -72,7 +75,9 @@ public class SyncTest {
Assert.assertFalse(SyncTestUtil.isSyncRequested()); Assert.assertFalse(SyncTestUtil.isSyncRequested());
CriteriaHelper.pollUiThread( CriteriaHelper.pollUiThread(
() ()
-> !IdentityServicesProvider.get().getIdentityManager().hasPrimaryAccount(), -> !IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.hasPrimaryAccount(),
"Timed out checking that hasPrimaryAccount() == false", SyncTestUtil.TIMEOUT_MS, "Timed out checking that hasPrimaryAccount() == false", SyncTestUtil.TIMEOUT_MS,
SyncTestUtil.INTERVAL_MS); SyncTestUtil.INTERVAL_MS);
} }
......
...@@ -230,8 +230,9 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -230,8 +230,9 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
public void signOut() throws InterruptedException { public void signOut() throws InterruptedException {
final Semaphore s = new Semaphore(0); final Semaphore s = new Semaphore(0);
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
IdentityServicesProvider.get().getSigninManager().signOut( IdentityServicesProvider.get()
SignoutReason.SIGNOUT_TEST, s::release, false); .getSigninManager(Profile.getLastUsedRegularProfile())
.signOut(SignoutReason.SIGNOUT_TEST, s::release, false);
}); });
Assert.assertTrue(s.tryAcquire(SyncTestUtil.TIMEOUT_MS, TimeUnit.MILLISECONDS)); Assert.assertTrue(s.tryAcquire(SyncTestUtil.TIMEOUT_MS, TimeUnit.MILLISECONDS));
Assert.assertNull(SigninTestUtil.getCurrentAccount()); Assert.assertNull(SigninTestUtil.getCurrentAccount());
...@@ -414,8 +415,9 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> { ...@@ -414,8 +415,9 @@ public class SyncTestRule extends ChromeActivityTestRule<ChromeActivity> {
private void signinAndEnableSyncInternal(final Account account, boolean setFirstSetupComplete) { private void signinAndEnableSyncInternal(final Account account, boolean setFirstSetupComplete) {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
IdentityServicesProvider.get().getSigninManager().signIn( IdentityServicesProvider.get()
SigninAccessPoint.UNKNOWN, account, new SigninManager.SignInCallback() { .getSigninManager(Profile.getLastUsedRegularProfile())
.signIn(SigninAccessPoint.UNKNOWN, account, new SigninManager.SignInCallback() {
@Override @Override
public void onSignInComplete() { public void onSignInComplete() {
if (setFirstSetupComplete) { if (setFirstSetupComplete) {
......
...@@ -10,6 +10,7 @@ import org.junit.Assert; ...@@ -10,6 +10,7 @@ import org.junit.Assert;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.SyncFirstSetupCompleteSource; import org.chromium.chrome.browser.SyncFirstSetupCompleteSource;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.SigninManager; import org.chromium.chrome.browser.signin.SigninManager;
import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; import org.chromium.chrome.test.util.browser.signin.SigninTestUtil;
...@@ -27,8 +28,9 @@ public final class SyncTestSigninUtils { ...@@ -27,8 +28,9 @@ public final class SyncTestSigninUtils {
*/ */
private static void signinTestAccount(final Account account) { private static void signinTestAccount(final Account account) {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
IdentityServicesProvider.get().getSigninManager().signIn( IdentityServicesProvider.get()
SigninAccessPoint.UNKNOWN, account, new SigninManager.SignInCallback() { .getSigninManager(Profile.getLastUsedRegularProfile())
.signIn(SigninAccessPoint.UNKNOWN, account, new SigninManager.SignInCallback() {
@Override @Override
public void onSignInComplete() { public void onSignInComplete() {
ProfileSyncService.get().setFirstSetupComplete( ProfileSyncService.get().setFirstSetupComplete(
......
...@@ -6232,6 +6232,7 @@ if (is_android) { ...@@ -6232,6 +6232,7 @@ if (is_android) {
"//base:base_java", "//base:base_java",
"//base:jni_java", "//base:jni_java",
"//chrome/android:chrome_all_java", "//chrome/android:chrome_all_java",
"//chrome/browser/profiles/android:java",
"//chrome/test/android:chrome_java_test_support", "//chrome/test/android:chrome_java_test_support",
"//components/signin/public/android:java", "//components/signin/public/android:java",
"//components/sync:sync_java_test_support", "//components/sync:sync_java_test_support",
......
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