Skip to content

Commit

Permalink
Fix memory leak due to usage of statics in AccountSelectionViewBinder…
Browse files Browse the repository at this point in the history
….java

This CL removes the use of never-cleared statics in
AccountSelectionViewBinder.java

BUG=None

Change-Id: I7eb980b49b10337383ceed656746e50a4c528271
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3214416
Reviewed-by: Ken Buchanan <[email protected]>
Reviewed-by: Yi Gu <[email protected]>
Commit-Queue: Peter Kotwicz <[email protected]>
Cr-Commit-Position: refs/heads/main@{#931151}
  • Loading branch information
pkotwicz authored and Chromium LUCI CQ committed Oct 13, 2021
1 parent db68067 commit 38744d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void setUp() throws InterruptedException {
mAccountSelection.initialize(
mActivityTestRule.getActivity(), mBottomSheetController, mMockBridge);
});
AccountSelectionViewBinder.setTabCreator(sTabCreator);
AccountSelectionViewBinder.setTabCreatorForTesting(sTabCreator);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,11 @@
* to the suitable method in {@link AccountSelectionView}.
*/
class AccountSelectionViewBinder {
private static RoundedIconGenerator sRoundedIconGenerator;
private static TabCreator sTabCreator = new TabDelegate(/* incognito */ false);

static RoundedIconGenerator getRoundedIconGenerator(Resources resources) {
if (sRoundedIconGenerator == null) {
sRoundedIconGenerator = FaviconUtils.createCircularIconGenerator(resources);
}
return sRoundedIconGenerator;
}
private static TabCreator sTabCreatorForTesting;

@VisibleForTesting
static void setTabCreator(TabCreator creator) {
sTabCreator = creator;
static void setTabCreatorForTesting(TabCreator creator) {
sTabCreatorForTesting = creator;
}

/**
Expand Down Expand Up @@ -121,7 +113,8 @@ static Drawable overlayIdpFaviconOnAvatar(View view, AccountProperties.Avatar av
int badgeX = frameSize - badgeSize;
int badgeY = frameSize - badgeSize;

RoundedIconGenerator roundedIconGenerator = getRoundedIconGenerator(view.getResources());
RoundedIconGenerator roundedIconGenerator =
FaviconUtils.createCircularIconGenerator(view.getResources());

// Prepare avatar or its fallback monogram.
Bitmap avatar = avatarData.mAvatar;
Expand Down Expand Up @@ -164,7 +157,10 @@ static Drawable overlayIdpFaviconOnAvatar(View view, AccountProperties.Avatar av
}

static void openTab(String url) {
sTabCreator.launchUrl(url, TabLaunchType.FROM_CHROME_UI);
TabCreator tabCreator = (sTabCreatorForTesting == null)
? new TabDelegate(/* incognito */ false)
: sTabCreatorForTesting;
tabCreator.launchUrl(url, TabLaunchType.FROM_CHROME_UI);
}

static NoUnderlineClickableSpan createLink(Resources r, String url) {
Expand Down

0 comments on commit 38744d6

Please sign in to comment.