Bug 1130694 - Remove DB code path from ThumbnailHelper.getAndProcessThumbnailFor and move to Tab class r=rnewman

This commit is contained in:
Mark Finkle 2015-02-12 10:03:47 -05:00
Родитель c745109d10
Коммит 3888d12c92
3 изменённых файлов: 29 добавлений и 25 удалений

Просмотреть файл

@ -21,6 +21,7 @@ import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.favicons.LoadFaviconTask;
import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
import org.mozilla.gecko.favicons.RemoteFavicon;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.gfx.Layer;
import org.mozilla.gecko.toolbar.BrowserToolbar.TabEditingState;
import org.mozilla.gecko.util.ThreadUtils;
@ -641,7 +642,7 @@ public class Tab {
if (!TextUtils.equals(oldURL, getURL()))
return;
ThumbnailHelper.getInstance().getAndProcessThumbnailFor(tab, mDB);
ThumbnailHelper.getInstance().getAndProcessThumbnailFor(tab);
}
}, 500);
}
@ -657,7 +658,7 @@ public class Tab {
}
try {
String url = getURL();
final String url = getURL();
if (url == null) {
return;
}
@ -668,11 +669,33 @@ public class Tab {
}
}
public void loadThumbnailFromDB(final BrowserDB db) {
try {
final String url = getURL();
if (url == null) {
return;
}
byte[] thumbnail = db.getThumbnailForUrl(getContentResolver(), url);
if (thumbnail == null) {
return;
}
Bitmap bitmap = BitmapUtils.decodeByteArray(thumbnail);
mThumbnail = new BitmapDrawable(mAppContext.getResources(), bitmap);
Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.THUMBNAIL);
} catch (Exception e) {
// ignore
}
}
private void clearThumbnailFromDB(final BrowserDB db) {
try {
String url = getURL();
if (url == null)
final String url = getURL();
if (url == null) {
return;
}
// Passing in a null thumbnail will delete the stored thumbnail for this url
db.updateThumbnailForUrl(getContentResolver(), url, null);

Просмотреть файл

@ -5,7 +5,6 @@
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.mozglue.DirectBufferAllocator;
import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
@ -68,29 +67,12 @@ public final class ThumbnailHelper {
mHeight = -1;
}
public void getAndProcessThumbnailFor(Tab tab, final BrowserDB db) {
public void getAndProcessThumbnailFor(Tab tab) {
if (AboutPages.isAboutHome(tab.getURL())) {
tab.updateThumbnail(null, CachePolicy.NO_STORE);
return;
}
// If we don't have a database, there's nothing left to do.
if (db == null) {
return;
}
if (tab.getState() == Tab.STATE_DELAYED) {
String url = tab.getURL();
if (url != null) {
byte[] thumbnail = db.getThumbnailForUrl(GeckoAppShell.getContext().getContentResolver(), url);
if (thumbnail != null) {
// Since this thumbnail is from the database, its ok to store it
setTabThumbnail(tab, null, thumbnail, CachePolicy.STORE);
}
}
return;
}
synchronized (mPendingThumbnails) {
if (mPendingThumbnails.lastIndexOf(tab) > 0) {
// This tab is already in the queue, so don't add it again.

Просмотреть файл

@ -153,8 +153,7 @@ public final class BitmapUtils {
}
}
});
final GeckoProfile profile = GeckoProfile.get(context);
ThumbnailHelper.getInstance().getAndProcessThumbnailFor(tab, profile.getDB());
ThumbnailHelper.getInstance().getAndProcessThumbnailFor(tab);
}
public static Bitmap decodeByteArray(byte[] bytes) {