Commit 25f79f74 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

weblayer: Avoid WeakReference gc churn

Keep a single ImmutableWeakReference in FragmentWindowAndroid instead of
creating a new instance with every getActivity call.

This is a follow up to
https://chromium-review.googlesource.com/c/chromium/src/+/2165148

Change-Id: I11a02521ba4dfc79f99321760e0d479500b14aa7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2166620Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762873}
parent ac8a070c
......@@ -12,6 +12,7 @@ import android.content.IntentSender;
import android.os.Build;
import org.chromium.ui.base.ActivityKeyboardVisibilityDelegate;
import org.chromium.ui.base.ImmutableWeakReference;
import org.chromium.ui.base.IntentWindowAndroid;
import org.chromium.ui.modaldialog.ModalDialogManager;
......@@ -25,6 +26,9 @@ public class FragmentWindowAndroid extends IntentWindowAndroid {
private BrowserFragmentImpl mFragment;
private ModalDialogManager mModalDialogManager;
// Just create one ImmutableWeakReference object to avoid gc churn.
private ImmutableWeakReference<Activity> mActivityWeakRefHolder;
FragmentWindowAndroid(Context context, BrowserFragmentImpl fragment) {
super(context);
mFragment = fragment;
......@@ -46,7 +50,10 @@ public class FragmentWindowAndroid extends IntentWindowAndroid {
@Override
public final WeakReference<Activity> getActivity() {
return new WeakReference<>(mFragment.getActivity());
if (mActivityWeakRefHolder == null) {
mActivityWeakRefHolder = new ImmutableWeakReference<>(mFragment.getActivity());
}
return mActivityWeakRefHolder;
}
@Override
......
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