Bug 699786 - Use Android's AsyncTask in Favicons (r=blassey)

Ensure that listener is always called on main UI thread. We'll need AsyncTask's
cancellation support in Favicons.
This commit is contained in:
Lucas Rocha 2011-11-17 21:35:14 +00:00
parent 4a85aab8a1
commit 7630d6c2b4
2 changed files with 20 additions and 8 deletions

View File

@ -173,7 +173,7 @@ public class Favicons {
mDbHelper.close();
}
private class LoadFaviconTask extends GeckoAsyncTask<Void, Void, BitmapDrawable> {
private class LoadFaviconTask extends AsyncTask<Void, Void, BitmapDrawable> {
private String mPageUrl;
private String mFaviconUrl;
private OnFaviconLoadedListener mListener;
@ -338,11 +338,17 @@ public class Favicons {
}
@Override
protected void onPostExecute(BitmapDrawable image) {
protected void onPostExecute(final BitmapDrawable image) {
Log.d(LOGTAG, "LoadFaviconTask finished for URL = " + mPageUrl);
if (mListener != null)
mListener.onFaviconLoaded(mPageUrl, image);
if (mListener != null) {
// We want to always run the listener on UI thread
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
public void run() {
mListener.onFaviconLoaded(mPageUrl, image);
}
});
}
}
}
}

View File

@ -964,10 +964,11 @@ abstract public class GeckoApp
return;
tab.updateTitle(title);
loadFavicon(tab);
mMainHandler.post(new Runnable() {
public void run() {
loadFavicon(tab);
if (Tabs.getInstance().isSelectedTab(tab))
mBrowserToolbar.setTitle(tab.getDisplayTitle());
onTabsChanged(tab);
@ -993,7 +994,7 @@ abstract public class GeckoApp
void handleLinkAdded(final int tabId, String rel, final String href) {
if (rel.indexOf("icon") != -1) {
Tab tab = Tabs.getInstance().getTab(tabId);
final Tab tab = Tabs.getInstance().getTab(tabId);
if (tab != null) {
tab.updateFaviconURL(href);
@ -1001,8 +1002,13 @@ abstract public class GeckoApp
// want to load the image straight away. If tab is still
// loading, we only load the favicon once the page's content
// is fully loaded (see handleContentLoaded()).
if (!tab.isLoading())
loadFavicon(tab);
if (!tab.isLoading()) {
mMainHandler.post(new Runnable() {
public void run() {
loadFavicon(tab);
}
});
}
}
}
}