Skip to content

Commit

Permalink
Migrate getLastUsedRegularProfile from Profile -> ProfileManager.
Browse files Browse the repository at this point in the history
Deprecated profile methods will be removed in a subsequent CL
to avoid late breaking conflicts.

Bug: 40254448
Change-Id: I6dddb9f9b78abe58a4f8c3f65b6dd7c1b7489595
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5304420
Reviewed-by: Andrew Grieve <[email protected]>
Reviewed-by: Theresa Sullivan <[email protected]>
Commit-Queue: Ted Choc <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1262058}
  • Loading branch information
Ted Choc authored and Chromium LUCI CQ committed Feb 17, 2024
1 parent 6929fef commit f486e3f
Show file tree
Hide file tree
Showing 299 changed files with 935 additions and 714 deletions.
2 changes: 1 addition & 1 deletion PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class BanRule:
),
),
BanRule(
'Profile.getLastUsedRegularProfile()',
'ProfileManager.getLastUsedRegularProfile()',
(
'Prefer passing in the Profile reference instead of relying on the '
'static getLastUsedRegularProfile() call. Only top level entry points '
Expand Down
2 changes: 1 addition & 1 deletion PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,7 @@ def testBannedJavaFunctions(self):
MockFile('some/java/problematic/requestlayout.java',
['requestLayout();']),
MockFile('some/java/problematic/lastprofile.java',
['Profile.getLastUsedRegularProfile();']),
['ProfileManager.getLastUsedRegularProfile();']),
MockFile('some/java/problematic/getdrawable1.java',
['ResourcesCompat.getDrawable();']),
MockFile('some/java/problematic/getdrawable2.java',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.keyboard_accessory.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.util.ChromeAccessibilityUtil;
import org.chromium.components.browser_ui.widget.textbubble.TextBubble;
import org.chromium.components.feature_engagement.EventConstants;
Expand Down Expand Up @@ -189,7 +189,7 @@ private static Tracker getTrackerFromProfile() {
// incognito profile) instead of always using regular profile. It works correctly now,
// but it is not safe.
final Tracker tracker =
TrackerFactory.getTrackerForProfile(Profile.getLastUsedRegularProfile());
TrackerFactory.getTrackerForProfile(ProfileManager.getLastUsedRegularProfile());
if (!tracker.isInitialized()) return null;
return tracker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import org.chromium.base.Callback;
import org.chromium.chrome.browser.keyboard_accessory.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.ui.favicon.FaviconUtils;
import org.chromium.components.browser_ui.widget.RoundedIconGenerator;
import org.chromium.components.favicon.LargeIconBridge;
Expand Down Expand Up @@ -74,7 +74,7 @@ public Drawable getDefaultIcon(String origin) {
*/
public void fetchFavicon(String origin, Callback<Drawable> setIconCallback) {
final LargeIconBridge mIconBridge =
new LargeIconBridge(Profile.getLastUsedRegularProfile());
new LargeIconBridge(ProfileManager.getLastUsedRegularProfile());
final GURL gurlOrigin = new GURL(origin);
if (!gurlOrigin.isValid()) return;
mIconBridge.getLargeIconForUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.chromium.chrome.browser.feed.ScrollableContainerDelegate;
import org.chromium.chrome.browser.ntp.NewTabPageLaunchOrigin;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
Expand Down Expand Up @@ -107,7 +108,7 @@ ExploreSurfaceCoordinator create(
boolean isInNightMode,
boolean isPlaceholderShown,
@NewTabPageLaunchOrigin int launchOrigin) {
Profile profile = Profile.getLastUsedRegularProfile();
Profile profile = ProfileManager.getLastUsedRegularProfile();

return new ExploreSurfaceCoordinator(
profile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.chromium.chrome.browser.feed.FeedSurfaceCoordinator;
import org.chromium.chrome.browser.feed.FeedSurfaceLifecycleManager;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.components.user_prefs.UserPrefs;

/** Explore surface feed lifecycle manager. */
Expand All @@ -32,7 +32,7 @@ protected boolean canShow() {
}

private boolean shouldShowFeed() {
return UserPrefs.get(Profile.getLastUsedRegularProfile())
return UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
.getBoolean(Pref.ARTICLES_LIST_VISIBLE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.chromium.chrome.browser.omnibox.OmniboxStub;
import org.chromium.chrome.browser.omnibox.styles.OmniboxResourceProvider;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.suggestions.tile.MostVisitedTilesCoordinator;
import org.chromium.chrome.browser.suggestions.tile.TileGroupDelegateImpl;
Expand Down Expand Up @@ -572,7 +573,7 @@ public void initWithNative() {
mStartSurfaceMediator.initWithNative(
mIsStartSurfaceEnabled ? mOmniboxStubSupplier.get() : null,
mExploreSurfaceCoordinatorFactory,
UserPrefs.get(Profile.getLastUsedRegularProfile()),
UserPrefs.get(ProfileManager.getLastUsedRegularProfile()),
mSnackbarManager);

if (mGridTabSwitcher != null) {
Expand Down Expand Up @@ -1340,7 +1341,7 @@ public void initializeMVTiles() {
return;
}

Profile profile = Profile.getLastUsedRegularProfile();
Profile profile = ProfileManager.getLastUsedRegularProfile();
MostVisitedTileNavigationDelegate navigationDelegate =
new MostVisitedTileNavigationDelegate(mActivity, profile, mParentTabSupplier);
mSuggestionsUiDelegate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
import org.chromium.chrome.browser.offlinepages.RequestCoordinatorBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.document.ChromeAsyncTabLauncher;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void navigateToSuggestionUrl(int windowOpenDisposition, String url, boole
private void saveUrlForOffline(String url) {
// TODO(crbug.com/1193816): Namespace shouldn't be NTP_SUGGESTIONS_NAMESPACE since it's
// not on NTP.
RequestCoordinatorBridge.getForProfile(Profile.getLastUsedRegularProfile())
RequestCoordinatorBridge.getForProfile(ProfileManager.getLastUsedRegularProfile())
.savePageLater(
url,
OfflinePageBridge.NTP_SUGGESTIONS_NAMESPACE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.chromium.chrome.browser.ntp.IncognitoCookieControlsManager;
import org.chromium.chrome.browser.omnibox.OmniboxStub;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.suggestions.tile.MostVisitedTilesCoordinator;
import org.chromium.chrome.browser.suggestions.tile.TileGroupDelegateImpl;
import org.chromium.chrome.browser.tab.Tab;
Expand Down Expand Up @@ -179,7 +180,7 @@ public TasksSurfaceCoordinator(
View.OnClickListener incognitoLearnMoreClickListener =
v -> {
Profile profile =
Profile.getLastUsedRegularProfile()
ProfileManager.getLastUsedRegularProfile()
.getPrimaryOTRProfile(/* createIfNeeded= */ true);
HelpAndFeedbackLauncherImpl.getForProfile(profile)
.show(
Expand Down Expand Up @@ -228,7 +229,7 @@ public void initializeMVTiles() {
return;
}

Profile profile = Profile.getLastUsedRegularProfile();
Profile profile = ProfileManager.getLastUsedRegularProfile();
MostVisitedTileNavigationDelegate navigationDelegate =
new MostVisitedTileNavigationDelegate(mActivity, profile, mParentTabSupplier);
mSuggestionsUiDelegate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.chromium.chrome.browser.ntp.search.SearchBoxCoordinator;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.CoordinatorLayoutForPointer;
Expand Down Expand Up @@ -471,7 +472,7 @@ void setStartSurfaceBackgroundColor(int backgroundColor) {

boolean shouldShowTrackingProtectionNtp() {
Profile profile =
Profile.getLastUsedRegularProfile()
ProfileManager.getLastUsedRegularProfile()
.getPrimaryOTRProfile(/* createIfNeeded= */ true);
return (UserPrefs.get(profile).getBoolean(Pref.TRACKING_PROTECTION3PCD_ENABLED)
|| ChromeFeatureList.isEnabled(ChromeFeatureList.TRACKING_PROTECTION_3PCD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.tasks.ReturnToChromeUtil;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
Expand Down Expand Up @@ -147,7 +147,7 @@ public void testCachedFeedVisibility() {
// FEED_ARTICLES_LIST_VISIBLE should equal to ARTICLES_LIST_VISIBLE.
CriteriaHelper.pollUiThread(
() ->
UserPrefs.get(Profile.getLastUsedRegularProfile())
UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
.getBoolean(Pref.ARTICLES_LIST_VISIBLE)
== ReturnToChromeUtil.getFeedArticlesVisibility());

Expand All @@ -158,7 +158,7 @@ public void testCachedFeedVisibility() {
TestThreadUtils.runOnUiThreadBlocking(
() ->
Assert.assertEquals(
UserPrefs.get(Profile.getLastUsedRegularProfile())
UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
.getBoolean(Pref.ARTICLES_LIST_VISIBLE),
ReturnToChromeUtil.getFeedArticlesVisibility()));

Expand All @@ -169,7 +169,7 @@ public void testCachedFeedVisibility() {
TestThreadUtils.runOnUiThreadBlocking(
() ->
Assert.assertEquals(
UserPrefs.get(Profile.getLastUsedRegularProfile())
UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
.getBoolean(Pref.ARTICLES_LIST_VISIBLE),
ReturnToChromeUtil.getFeedArticlesVisibility()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
import org.chromium.chrome.browser.layouts.LayoutStateProvider;
import org.chromium.chrome.browser.layouts.LayoutTestUtils;
import org.chromium.chrome.browser.layouts.LayoutType;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tasks.ReturnToChromeUtil;
Expand Down Expand Up @@ -913,7 +913,8 @@ public void test_UsesSpareTabForNavigationFromMVTiles() {
// SpareTab should be created when the start surface is shown.
CriteriaHelper.pollUiThread(
() -> {
WarmupManager.getInstance().hasSpareTab(Profile.getLastUsedRegularProfile());
WarmupManager.getInstance()
.hasSpareTab(ProfileManager.getLastUsedRegularProfile());
});

// The spareTab initializes a renderer process.
Expand All @@ -927,7 +928,7 @@ public void test_UsesSpareTabForNavigationFromMVTiles() {
CriteriaHelper.pollUiThread(
() ->
!WarmupManager.getInstance()
.hasSpareTab(Profile.getLastUsedRegularProfile()));
.hasSpareTab(ProfileManager.getLastUsedRegularProfile()));
Assert.assertEquals(
1,
RecordHistogram.getHistogramValueCountForTesting(
Expand Down Expand Up @@ -956,7 +957,8 @@ public void test_UsesSpareTabForNavigationFromSearchBox() {
// SpareTab should be created when the start surface is shown.
CriteriaHelper.pollUiThread(
() -> {
WarmupManager.getInstance().hasSpareTab(Profile.getLastUsedRegularProfile());
WarmupManager.getInstance()
.hasSpareTab(ProfileManager.getLastUsedRegularProfile());
});

// Navigate from StartSurface using search box.
Expand All @@ -972,7 +974,7 @@ public void test_UsesSpareTabForNavigationFromSearchBox() {
CriteriaHelper.pollUiThread(
() ->
!WarmupManager.getInstance()
.hasSpareTab(Profile.getLastUsedRegularProfile()));
.hasSpareTab(ProfileManager.getLastUsedRegularProfile()));
Assert.assertEquals(
1,
RecordHistogram.getHistogramValueCountForTesting(
Expand All @@ -999,7 +1001,8 @@ public void test_DoesntUseSpareTabForNavigationFromSingleTabSwitcher() {
// SpareTab should be created when the start surface is shown.
CriteriaHelper.pollUiThread(
() -> {
WarmupManager.getInstance().hasSpareTab(Profile.getLastUsedRegularProfile());
WarmupManager.getInstance()
.hasSpareTab(ProfileManager.getLastUsedRegularProfile());
});

// Navigate from StartSurface using carousel tab switcher.
Expand All @@ -1010,7 +1013,7 @@ public void test_DoesntUseSpareTabForNavigationFromSingleTabSwitcher() {
CriteriaHelper.pollUiThread(
() ->
!WarmupManager.getInstance()
.hasSpareTab(Profile.getLastUsedRegularProfile()));
.hasSpareTab(ProfileManager.getLastUsedRegularProfile()));
Assert.assertEquals(
1,
RecordHistogram.getHistogramValueCountForTesting(
Expand Down Expand Up @@ -1038,7 +1041,8 @@ public void test_SpareTabCreatesNewRendererProcessWithParamEnabled() {
// SpareTab should be created when the start surface is shown.
CriteriaHelper.pollUiThread(
() -> {
WarmupManager.getInstance().hasSpareTab(Profile.getLastUsedRegularProfile());
WarmupManager.getInstance()
.hasSpareTab(ProfileManager.getLastUsedRegularProfile());
});

// The renderer process count should be 1 as spareTab also initializes renderer when the
Expand Down Expand Up @@ -1067,7 +1071,8 @@ public void test_SpareTabNotUsedOnOtherSurface() {
// SpareTab should be created when the start surface is shown.
CriteriaHelper.pollUiThread(
() -> {
WarmupManager.getInstance().hasSpareTab(Profile.getLastUsedRegularProfile());
WarmupManager.getInstance()
.hasSpareTab(ProfileManager.getLastUsedRegularProfile());
});

// Navigate from start surface using link
Expand All @@ -1077,7 +1082,7 @@ public void test_SpareTabNotUsedOnOtherSurface() {
CriteriaHelper.pollUiThread(
() ->
!WarmupManager.getInstance()
.hasSpareTab(Profile.getLastUsedRegularProfile()));
.hasSpareTab(ProfileManager.getLastUsedRegularProfile()));
Assert.assertEquals(
1,
RecordHistogram.getHistogramValueCountForTesting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.chromium.chrome.browser.omnibox.voice.VoiceRecognitionHandler;
import org.chromium.chrome.browser.preferences.PrefChangeRegistrar;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.services.IdentityServicesProviderJni;
Expand Down Expand Up @@ -113,8 +114,8 @@ public MockTabModelFilterProvider(Activity activity) {
List<TabModel> tabModels = new ArrayList<>();
MockTabModelSelector selector =
new MockTabModelSelector(
Profile.getLastUsedRegularProfile(),
Profile.getLastUsedRegularProfile().getPrimaryOTRProfile(true),
ProfileManager.getLastUsedRegularProfile(),
ProfileManager.getLastUsedRegularProfile().getPrimaryOTRProfile(true),
0,
0,
null);
Expand Down Expand Up @@ -180,7 +181,7 @@ private void initJniMocks() {
Mockito.when(profile.getPrimaryOTRProfile(Mockito.anyBoolean()))
.thenReturn(incognitoProfile);
PrefService prefService = Mockito.mock(PrefService.class);
Profile.setLastUsedProfileForTesting(profile);
ProfileManager.setLastUsedProfileForTesting(profile);

mSuggestionsDeps.getFactory().offlinePageBridge = new FakeOfflinePageBridge();
mSuggestionsDeps.getFactory().mostVisitedSites = new FakeMostVisitedSites();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import org.chromium.chrome.browser.omnibox.UrlFocusChangeListener;
import org.chromium.chrome.browser.omnibox.voice.VoiceRecognitionHandler;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.tab.MockTab;
import org.chromium.chrome.browser.tab.Tab;
Expand Down Expand Up @@ -216,7 +217,7 @@ public void setUp() {

doReturn(false).when(mProfile).isOffTheRecord();
mProfileSupplier.set(mProfile);
Profile.setLastUsedProfileForTesting(mProfile);
ProfileManager.setLastUsedProfileForTesting(mProfile);
TemplateUrlServiceFactory.setInstanceForTesting(mTemplateUrlService);

ArrayList<PropertyKey> allProperties =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.chromium.chrome.browser.ntp.IncognitoCookieControlsManager;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileManager;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
Expand Down Expand Up @@ -103,7 +104,7 @@ public void setUp() throws Exception {

mJniMocker.mock(UserPrefsJni.TEST_HOOKS, mUserPrefsJniMock);
when(mProfile.getPrimaryOTRProfile(true)).thenReturn(mProfile);
Profile.setLastUsedProfileForTesting(mProfile);
ProfileManager.setLastUsedProfileForTesting(mProfile);
when(mUserPrefsJniMock.get(mProfile)).thenReturn(mPrefService);
createTasksView(R.layout.tasks_view_layout);
}
Expand Down
Loading

0 comments on commit f486e3f

Please sign in to comment.