Commit 2ac3a842 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Separate cache for local and foreign favicons.

https://chromium-review.googlesource.com/c/chromium/src/+/1634695
renamed FaviconCache#(get|put)SyncedFaviconImage() methods into
(get|put)ForeignFaviconImage() but never called the new versions,
instead calling (get|put)LocalFaviconImage(). This effectively
causes the caches to be unified.

This CL split the caches into two, as I believe the author intended.

Change-Id: If461911620c83a901b9d8c89af3fc3acf48293ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852422
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705322}
parent 875ee43f
...@@ -11,6 +11,7 @@ import android.graphics.BitmapFactory; ...@@ -11,6 +11,7 @@ import android.graphics.BitmapFactory;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.LruCache; import android.util.LruCache;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -43,13 +44,14 @@ import java.lang.annotation.Retention; ...@@ -43,13 +44,14 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Row adapter for presenting recently closed tabs, synced tabs from other devices, the sync or * Row adapter for presenting recently closed tabs, synced tabs from other devices, the sync or
* sign in promo, and currently open tabs (only in document mode) in a grouped list view. * sign in promo, and currently open tabs (only in document mode) in a grouped list view.
*/ */
public class RecentTabsRowAdapter extends BaseExpandableListAdapter { public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
private static final int MAX_NUM_FAVICONS_TO_CACHE = 256; private static final int MAX_NUM_FAVICONS_TO_CACHE = 128;
@IntDef({ChildType.NONE, ChildType.DEFAULT_CONTENT, ChildType.PERSONALIZED_SIGNIN_PROMO, @IntDef({ChildType.NONE, ChildType.DEFAULT_CONTENT, ChildType.PERSONALIZED_SIGNIN_PROMO,
ChildType.SYNC_PROMO}) ChildType.SYNC_PROMO})
...@@ -98,6 +100,15 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -98,6 +100,15 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
int NUM_ENTRIES = 11; int NUM_ENTRIES = 11;
} }
@IntDef({FaviconLocality.LOCAL, FaviconLocality.FOREIGN})
@Retention(RetentionPolicy.SOURCE)
private @interface FaviconLocality {
int LOCAL = 0;
int FOREIGN = 1;
int NUM_ENTRIES = 2;
}
private final Activity mActivity; private final Activity mActivity;
private final List<Group> mGroups; private final List<Group> mGroups;
private final DefaultFaviconHelper mDefaultFaviconHelper; private final DefaultFaviconHelper mDefaultFaviconHelper;
...@@ -105,7 +116,8 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -105,7 +116,8 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
private final RecentlyClosedTabsGroup mRecentlyClosedTabsGroup = new RecentlyClosedTabsGroup(); private final RecentlyClosedTabsGroup mRecentlyClosedTabsGroup = new RecentlyClosedTabsGroup();
private final SeparatorGroup mVisibleSeparatorGroup = new SeparatorGroup(true); private final SeparatorGroup mVisibleSeparatorGroup = new SeparatorGroup(true);
private final SeparatorGroup mInvisibleSeparatorGroup = new SeparatorGroup(false); private final SeparatorGroup mInvisibleSeparatorGroup = new SeparatorGroup(false);
private final FaviconCache mFaviconCache; private final Map<Integer, FaviconCache> mFaviconCaches =
new ArrayMap<>(FaviconLocality.NUM_ENTRIES);
private final int mFaviconSize; private final int mFaviconSize;
private boolean mHasForeignDataRecorded; private boolean mHasForeignDataRecorded;
private RoundedIconGenerator mIconGenerator; private RoundedIconGenerator mIconGenerator;
...@@ -640,29 +652,18 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -640,29 +652,18 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
} }
private static class FaviconCache { private static class FaviconCache {
private static final String FOREIGN_FAVICON_PREFIX = "Foreign";
private static final String LOCAL_FAVICON_PREFIX = "Local";
private final LruCache<String, Drawable> mMemoryCache; private final LruCache<String, Drawable> mMemoryCache;
public FaviconCache(int size) { public FaviconCache(int size) {
mMemoryCache = new LruCache<String, Drawable>(size); mMemoryCache = new LruCache<>(size);
}
public Drawable getForeignFaviconImage(String url) {
return mMemoryCache.get(FOREIGN_FAVICON_PREFIX + url);
}
public void putForeignFaviconImage(String url, Drawable image) {
mMemoryCache.put(FOREIGN_FAVICON_PREFIX + url, image);
} }
public Drawable getLocalFaviconImage(String url) { Drawable getFaviconImage(String url) {
return mMemoryCache.get(LOCAL_FAVICON_PREFIX + url); return mMemoryCache.get(url);
} }
public void putLocalFaviconImage(String url, Drawable image) { public void putFaviconImage(String url, Drawable image) {
mMemoryCache.put(LOCAL_FAVICON_PREFIX + url, image); mMemoryCache.put(url, image);
} }
} }
...@@ -677,7 +678,8 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -677,7 +678,8 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
mActivity = activity; mActivity = activity;
mRecentTabsManager = recentTabsManager; mRecentTabsManager = recentTabsManager;
mGroups = new ArrayList<>(); mGroups = new ArrayList<>();
mFaviconCache = new FaviconCache(MAX_NUM_FAVICONS_TO_CACHE); mFaviconCaches.put(FaviconLocality.LOCAL, new FaviconCache(MAX_NUM_FAVICONS_TO_CACHE));
mFaviconCaches.put(FaviconLocality.FOREIGN, new FaviconCache(MAX_NUM_FAVICONS_TO_CACHE));
Resources resources = activity.getResources(); Resources resources = activity.getResources();
mDefaultFaviconHelper = new DefaultFaviconHelper(); mDefaultFaviconHelper = new DefaultFaviconHelper();
...@@ -702,13 +704,6 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -702,13 +704,6 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
public FaviconImageCallback imageCallback; public FaviconImageCallback imageCallback;
} }
@IntDef({FaviconLocality.LOCAL, FaviconLocality.FOREIGN})
@Retention(RetentionPolicy.SOURCE)
private @interface FaviconLocality {
int LOCAL = 0;
int FOREIGN = 1;
}
private void loadFavicon( private void loadFavicon(
final ViewHolder viewHolder, final String url, @FaviconLocality int locality) { final ViewHolder viewHolder, final String url, @FaviconLocality int locality) {
Drawable image; Drawable image;
...@@ -717,7 +712,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -717,7 +712,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
image = mDefaultFaviconHelper.getDefaultFaviconDrawable( image = mDefaultFaviconHelper.getDefaultFaviconDrawable(
mActivity.getResources(), url, true); mActivity.getResources(), url, true);
} else { } else {
image = mFaviconCache.getLocalFaviconImage(url); image = mFaviconCaches.get(locality).getFaviconImage(url);
if (image == null) { if (image == null) {
FaviconImageCallback imageCallback = new FaviconImageCallback() { FaviconImageCallback imageCallback = new FaviconImageCallback() {
@Override @Override
...@@ -726,7 +721,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter { ...@@ -726,7 +721,7 @@ public class RecentTabsRowAdapter extends BaseExpandableListAdapter {
Drawable faviconDrawable = FaviconUtils.getIconDrawableWithFilter(bitmap, Drawable faviconDrawable = FaviconUtils.getIconDrawableWithFilter(bitmap,
url, mIconGenerator, mDefaultFaviconHelper, url, mIconGenerator, mDefaultFaviconHelper,
mActivity.getResources(), mFaviconSize); mActivity.getResources(), mFaviconSize);
mFaviconCache.putLocalFaviconImage(url, faviconDrawable); mFaviconCaches.get(locality).putFaviconImage(url, faviconDrawable);
viewHolder.imageView.setImageDrawable(faviconDrawable); viewHolder.imageView.setImageDrawable(faviconDrawable);
} }
}; };
......
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