Bug 802130 - Move GeckoAppShell.getHandler() to ThreadUtils.getBackgroundHandler(). r=mfinkle

This commit is contained in:
Kartikaya Gupta 2013-03-15 11:52:53 +01:00
Родитель baeed09fed
Коммит e0e4690d71
24 изменённых файлов: 97 добавлений и 87 удалений

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

@ -12,6 +12,7 @@ import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper;
import org.mozilla.gecko.sync.setup.SyncAccounts;
import org.mozilla.gecko.util.ActivityResultHandler;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask;
import org.json.JSONArray;
@ -143,7 +144,7 @@ public class AboutHomeContent extends ScrollView
// Because the tabs URI is coarse grained, this updates the
// remote tabs component on *every* tab change
// The observer will run on the background thread (see constructor argument)
mTabsContentObserver = new ContentObserver(GeckoAppShell.getHandler()) {
mTabsContentObserver = new ContentObserver(ThreadUtils.getBackgroundHandler()) {
@Override
public void onChange(boolean selfChange) {
update(EnumSet.of(AboutHomeContent.UpdateFlags.REMOTE_TABS));
@ -426,7 +427,7 @@ public class AboutHomeContent extends ScrollView
if (urls.size() == 0)
return;
(new UiAsyncTask<Void, Void, Cursor>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Cursor>(ThreadUtils.getBackgroundHandler()) {
@Override
public Cursor doInBackground(Void... params) {
return BrowserDB.getThumbnailsForUrls(cr, urls);
@ -440,7 +441,7 @@ public class AboutHomeContent extends ScrollView
}
void update(final EnumSet<UpdateFlags> flags) {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
if (flags.contains(UpdateFlags.TOP_SITES))
@ -990,7 +991,7 @@ public class AboutHomeContent extends ScrollView
final String url = holder.getUrl();
// Quickly update the view so that there isn't as much lag between the request and response
clearThumbnail(holder);
(new UiAsyncTask<Void, Void, Void>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground(Void... params) {
final ContentResolver resolver = mActivity.getContentResolver();
@ -1011,7 +1012,7 @@ public class AboutHomeContent extends ScrollView
holder.setPinned(true);
// update the database on a background thread
(new UiAsyncTask<Void, Void, Void>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground(Void... params) {
final ContentResolver resolver = mActivity.getContentResolver();
@ -1056,7 +1057,7 @@ public class AboutHomeContent extends ScrollView
holder.setPinned(true);
// update the database on a background thread
(new UiAsyncTask<Void, Void, Bitmap>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Bitmap>(ThreadUtils.getBackgroundHandler()) {
@Override
public Bitmap doInBackground(Void... params) {
final ContentResolver resolver = mActivity.getContentResolver();

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

@ -7,6 +7,7 @@ package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity;
import org.mozilla.gecko.sync.setup.SyncAccounts;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask;
import android.accounts.Account;
@ -70,7 +71,7 @@ public class AboutHomePromoBox extends TextView implements View.OnClickListener
showRandomPromo();
}
};
AccountManager.get(mContext).addOnAccountsUpdatedListener(mAccountListener, GeckoAppShell.getHandler(), false);
AccountManager.get(mContext).addOnAccountsUpdatedListener(mAccountListener, ThreadUtils.getBackgroundHandler(), false);
}
@Override
public boolean canShow() {
@ -193,7 +194,7 @@ public class AboutHomePromoBox extends TextView implements View.OnClickListener
}
private void getAvailableTypes(final GetTypesCallback callback) {
(new UiAsyncTask<Void, Void, ArrayList<Type>>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, ArrayList<Type>>(ThreadUtils.getBackgroundHandler()) {
@Override
public ArrayList<Type> doInBackground(Void... params) {
// Run all of this on a background thread

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

@ -5,7 +5,7 @@
package org.mozilla.gecko;
import org.mozilla.gecko.util.GeckoBackgroundThread;
import org.mozilla.gecko.util.ThreadUtils;
import android.app.ProgressDialog;
import android.content.Context;
@ -85,7 +85,7 @@ class AndroidImportPreference extends MultiChoicePreference {
}
};
GeckoBackgroundThread.getHandler().post(
ThreadUtils.postToBackgroundThread(
// Constructing AndroidImport may need finding the profile,
// which hits disk, so it needs to go into a Runnable too.
new Runnable() {

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

@ -579,7 +579,7 @@ public class AwesomeBar extends GeckoActivity {
editPrompt.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
(new UiAsyncTask<Void, Void, Void>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground(Void... params) {
String newUrl = locationText.getText().toString().trim();
@ -629,7 +629,7 @@ public class AwesomeBar extends GeckoActivity {
break;
}
case R.id.remove_bookmark: {
(new UiAsyncTask<Void, Void, Void>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
private boolean mInReadingList;
@Override
@ -659,7 +659,7 @@ public class AwesomeBar extends GeckoActivity {
break;
}
case R.id.remove_history: {
(new UiAsyncTask<Void, Void, Void>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground(Void... params) {
BrowserDB.removeHistoryEntry(getContentResolver(), id);

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

@ -10,7 +10,6 @@ import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.util.UiAsyncTask;
import org.mozilla.gecko.util.GeckoBackgroundThread;
import org.mozilla.gecko.util.ThreadUtils;
import org.json.JSONArray;
@ -377,7 +376,7 @@ abstract public class BrowserApp extends GeckoApp
return;
}
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
BrowserDB.addReadingListItem(getContentResolver(), title, url);
@ -387,7 +386,7 @@ abstract public class BrowserApp extends GeckoApp
}
void handleReaderRemoved(final String url) {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
BrowserDB.removeReadingListItemWithURL(getContentResolver(), url);
@ -1198,7 +1197,7 @@ abstract public class BrowserApp extends GeckoApp
item.setIcon(drawable);
}
else if (info.icon.startsWith("jar:") || info.icon.startsWith("file://")) {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
try {
@ -1548,7 +1547,7 @@ abstract public class BrowserApp extends GeckoApp
return;
}
(new UiAsyncTask<Void, Void, Boolean>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Boolean>(ThreadUtils.getBackgroundHandler()) {
@Override
public synchronized Boolean doInBackground(Void... params) {
// Check to see how many times the app has been launched.
@ -1575,7 +1574,7 @@ abstract public class BrowserApp extends GeckoApp
}
private void resetFeedbackLaunchCount() {
GeckoBackgroundThread.post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public synchronized void run() {
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
@ -1585,7 +1584,7 @@ abstract public class BrowserApp extends GeckoApp
}
private void getLastUrl() {
(new UiAsyncTask<Void, Void, String>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, String>(ThreadUtils.getBackgroundHandler()) {
@Override
public synchronized String doInBackground(Void... params) {
// Get the most recent URL stored in browser history.

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

@ -9,7 +9,7 @@
package org.mozilla.gecko;
import org.mozilla.gecko.util.GeckoBackgroundThread;
import org.mozilla.gecko.util.ThreadUtils;
import android.app.Activity;
import android.content.Context;
@ -45,7 +45,7 @@ public final class Distribution {
*/
public static void init(final Context context, final String packagePath) {
// Read/write preferences and files on the background thread.
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
// Bail if we've already initialized the distribution.

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

@ -112,7 +112,7 @@ public class Favicons {
return -1;
}
LoadFaviconTask task = new LoadFaviconTask(GeckoAppShell.getHandler(), pageUrl, faviconUrl, persist, listener);
LoadFaviconTask task = new LoadFaviconTask(ThreadUtils.getBackgroundHandler(), pageUrl, faviconUrl, persist, listener);
long taskId = task.getId();
mLoadTasks.put(taskId, task);

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

@ -43,7 +43,7 @@ public class GeckoAccessibility {
}));
public static void updateAccessibilitySettings () {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
JSONObject ret = new JSONObject();
@ -130,7 +130,7 @@ public class GeckoAccessibility {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
// Before Jelly Bean we send events directly from here while spoofing the source by setting
// the package and class name manually.
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
sendDirectAccessibilityEvent(eventType, message);

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

@ -15,7 +15,6 @@ import org.mozilla.gecko.gfx.PluginLayer;
import org.mozilla.gecko.gfx.PointUtils;
import org.mozilla.gecko.updater.UpdateService;
import org.mozilla.gecko.updater.UpdateServiceHelper;
import org.mozilla.gecko.util.GeckoBackgroundThread;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.GeckoEventResponder;
import org.mozilla.gecko.util.ThreadUtils;
@ -626,7 +625,7 @@ abstract public class GeckoApp
}
void handleFaviconRequest(final String url) {
(new UiAsyncTask<Void, Void, String>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, String>(ThreadUtils.getBackgroundHandler()) {
@Override
public String doInBackground(Void... params) {
return Favicons.getInstance().getFaviconUrlForPageUrl(url);
@ -802,7 +801,7 @@ abstract public class GeckoApp
@Override
public void run() {
Toast.makeText(GeckoApp.mAppContext, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
BrowserDB.addBookmark(GeckoApp.mAppContext.getContentResolver(), title, url);
@ -1104,7 +1103,7 @@ abstract public class GeckoApp
notification.setLatestEventInfo(mAppContext, fileName, progText, emptyIntent );
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.show();
new UiAsyncTask<Void, Void, Boolean>(GeckoAppShell.getHandler()){
new UiAsyncTask<Void, Void, Boolean>(ThreadUtils.getBackgroundHandler()) {
@Override
protected Boolean doInBackground(Void... params) {
@ -1440,7 +1439,7 @@ abstract public class GeckoApp
mPrivateBrowsingSession = savedInstanceState.getString(SAVED_STATE_PRIVATE_SESSION);
}
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
SharedPreferences prefs =
@ -1545,7 +1544,7 @@ abstract public class GeckoApp
Uri data = intent.getData();
if (data != null && "http".equals(data.getScheme())) {
startupAction = StartupAction.PREFETCH;
GeckoAppShell.getHandler().post(new PrefetchRunnable(data.toString()));
ThreadUtils.postToBackgroundThread(new PrefetchRunnable(data.toString()));
}
Tabs.registerOnTabsChangedListener(this);
@ -1706,7 +1705,7 @@ abstract public class GeckoApp
// End of the startup of our Java App
mJavaUiStartupTimer.stop();
GeckoAppShell.getHandler().postDelayed(new Runnable() {
ThreadUtils.getBackgroundHandler().postDelayed(new Runnable() {
@Override
public void run() {
// Sync settings need Gecko to be loaded, so
@ -1949,7 +1948,7 @@ abstract public class GeckoApp
// User may have enabled/disabled accessibility.
GeckoAccessibility.updateAccessibilitySettings();
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
SharedPreferences prefs =
@ -1995,7 +1994,7 @@ abstract public class GeckoApp
// In some way it's sad that Android will trigger StrictMode warnings
// here as the whole point is to save to disk while the activity is not
// interacting with the user.
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
SharedPreferences prefs =
@ -2017,7 +2016,7 @@ abstract public class GeckoApp
@Override
public void onRestart()
{
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
SharedPreferences prefs =
@ -2213,7 +2212,7 @@ abstract public class GeckoApp
if (profileDir != null) {
final GeckoApp app = GeckoApp.mAppContext;
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
ProfileMigrator profileMigrator = new ProfileMigrator(app);

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

@ -12,7 +12,6 @@ import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.gfx.PanZoomController;
import org.mozilla.gecko.mozglue.GeckoLoader;
import org.mozilla.gecko.util.EventDispatcher;
import org.mozilla.gecko.util.GeckoBackgroundThread;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.ThreadUtils;
@ -49,7 +48,6 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
@ -256,10 +254,6 @@ public class GeckoAppShell
}
}
public static Handler getHandler() {
return GeckoBackgroundThread.getHandler();
}
public static void runGecko(String apkPath, String args, String url, String type) {
Looper.prepare();
@ -608,7 +602,7 @@ public class GeckoAppShell
public static void createShortcut(final String aTitle, final String aURI, final String aUniqueURI,
final Bitmap aIcon, final String aType)
{
getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
// the intent to be launched by the shortcut
@ -645,7 +639,7 @@ public class GeckoAppShell
}
public static void removeShortcut(final String aTitle, final String aURI, final String aUniqueURI, final String aType) {
getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
// the intent to be launched by the shortcut
@ -680,7 +674,7 @@ public class GeckoAppShell
// On uninstall, we need to do a couple of things:
// 1. nuke the running app process.
// 2. nuke the profile that was assigned to that webapp
getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
int index = WebAppAllocator.getInstance(GeckoApp.mAppContext).releaseIndexForApp(uniqueURI);
@ -1117,7 +1111,7 @@ public class GeckoAppShell
// Note: the main looper won't work because it may be blocked on the
// gecko thread, which is most likely this thread
static String getClipboardText() {
getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
@SuppressWarnings("deprecation")
public void run() {
@ -1151,7 +1145,7 @@ public class GeckoAppShell
}
static void setClipboardText(final String text) {
getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
@SuppressWarnings("deprecation")
public void run() {
@ -1852,7 +1846,7 @@ public class GeckoAppShell
}
static void markUriVisited(final String uri) { // invoked from native JNI code
getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GlobalHistory.getInstance().add(uri);
@ -1861,7 +1855,7 @@ public class GeckoAppShell
}
static void setUriTitle(final String uri, final String title) { // invoked from native JNI code
getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GlobalHistory.getInstance().update(uri, title);

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

@ -6,6 +6,7 @@
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.util.ThreadUtils;
import android.database.Cursor;
import android.net.Uri;
@ -39,7 +40,7 @@ class GlobalHistory {
private boolean mProcessing; // = false // whether or not the runnable is queued/working
private GlobalHistory() {
mHandler = GeckoAppShell.getHandler();
mHandler = ThreadUtils.getBackgroundHandler();
mPendingUris = new LinkedList<String>();
mVisitedCache = new SoftReference<Set<String>>(null);
mNotifierRunnable = new Runnable() {

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

@ -7,6 +7,7 @@ package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.util.ThreadUtils;
import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
@ -105,7 +106,7 @@ class MemoryMonitor extends BroadcastReceiver {
if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(intent.getAction())) {
Log.d(LOGTAG, "Device storage is low");
mStoragePressure = true;
GeckoAppShell.getHandler().post(new StorageReducer(context));
ThreadUtils.postToBackgroundThread(new StorageReducer(context));
} else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(intent.getAction())) {
Log.d(LOGTAG, "Device storage is ok");
mStoragePressure = false;
@ -178,9 +179,9 @@ class MemoryMonitor extends BroadcastReceiver {
synchronized void start() {
if (mPosted) {
// cancel the old one before scheduling a new one
GeckoAppShell.getHandler().removeCallbacks(this);
ThreadUtils.getBackgroundHandler().removeCallbacks(this);
}
GeckoAppShell.getHandler().postDelayed(this, DECREMENT_DELAY);
ThreadUtils.getBackgroundHandler().postDelayed(this, DECREMENT_DELAY);
mPosted = true;
}
@ -193,7 +194,7 @@ class MemoryMonitor extends BroadcastReceiver {
}
// need to keep decrementing
GeckoAppShell.getHandler().postDelayed(this, DECREMENT_DELAY);
ThreadUtils.getBackgroundHandler().postDelayed(this, DECREMENT_DELAY);
}
}
@ -207,7 +208,7 @@ class MemoryMonitor extends BroadcastReceiver {
public void run() {
// this might get run right on startup, if so wait 10 seconds and try again
if (!GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
GeckoAppShell.getHandler().postDelayed(this, 10000);
ThreadUtils.getBackgroundHandler().postDelayed(this, 10000);
return;
}

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

@ -5,6 +5,8 @@
package org.mozilla.gecko;
import org.mozilla.gecko.util.ThreadUtils;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
@ -184,7 +186,7 @@ class MultiChoicePreference extends DialogPreference {
mPrevValues = mValues.clone();
}
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < mEntryKeys.length; i++) {
@ -233,7 +235,7 @@ class MultiChoicePreference extends DialogPreference {
}
mValues = new boolean[entryCount];
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < entryCount; i++) {

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

@ -14,6 +14,7 @@ import org.mozilla.gecko.sqlite.SQLiteBridge;
import org.mozilla.gecko.sqlite.SQLiteBridgeException;
import org.mozilla.gecko.sync.setup.SyncAccounts;
import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters;
import org.mozilla.gecko.util.ThreadUtils;
import android.accounts.Account;
import android.content.ContentProviderOperation;
@ -609,7 +610,7 @@ public class ProfileMigrator {
final String clientName = mSyncSettingsMap.get("services.sync.client.name");
final String clientGuid = mSyncSettingsMap.get("services.sync.client.GUID");
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
if (userName == null || syncKey == null || syncPass == null) {
@ -637,7 +638,7 @@ public class ProfileMigrator {
}
protected void registerAndRequest() {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
requestValues();
@ -652,7 +653,7 @@ public class ProfileMigrator {
@Override
protected void onPostExecute(Boolean result) {
if (result.booleanValue()) {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
Log.i(LOGTAG, "Sync account already configured, skipping.");
@ -933,7 +934,7 @@ public class ProfileMigrator {
// GlobalHistory access communicates with Gecko
// and must run on its thread.
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
for (String url : placesHistory) {

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

@ -15,6 +15,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.gfx.Layer;
import org.mozilla.gecko.util.ThreadUtils;
import android.content.ContentResolver;
import android.graphics.Bitmap;
@ -163,7 +164,7 @@ public class Tab {
}
public void updateThumbnail(final Bitmap b) {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
if (b != null) {
@ -321,7 +322,7 @@ public class Tab {
}
void updateBookmark() {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
final String url = getURL();
@ -339,7 +340,7 @@ public class Tab {
}
public void addBookmark() {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
String url = getURL();
@ -352,7 +353,7 @@ public class Tab {
}
public void removeBookmark() {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
String url = getURL();
@ -549,7 +550,7 @@ public class Tab {
final String oldURL = getURL();
final Tab tab = this;
GeckoAppShell.getHandler().postDelayed(new Runnable() {
ThreadUtils.getBackgroundHandler().postDelayed(new Runnable() {
@Override
public void run() {
// tab.getURL() may return null

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

@ -6,8 +6,9 @@
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.sync.setup.SyncAccounts;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.ThreadUtils;
import org.json.JSONObject;
@ -106,7 +107,7 @@ public class Tabs implements GeckoEventListener {
};
// The listener will run on the background thread (see 2nd argument).
mAccountManager.addOnAccountsUpdatedListener(mAccountListener, GeckoAppShell.getHandler(), false);
mAccountManager.addOnAccountsUpdatedListener(mAccountListener, ThreadUtils.getBackgroundHandler(), false);
if (mContentObserver != null) {
BrowserDB.registerBookmarkObserver(getContentResolver(), mContentObserver);
@ -449,7 +450,7 @@ public class Tabs implements GeckoEventListener {
public void refreshThumbnails() {
final ThumbnailHelper helper = ThumbnailHelper.getInstance();
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
for (final Tab tab : mOrder) {
@ -553,7 +554,7 @@ public class Tabs implements GeckoEventListener {
public void persistAllTabs() {
final GeckoApp activity = getActivity();
final Iterable<Tab> tabs = getTabsInOrder();
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
boolean syncIsSetup = SyncAccounts.syncAccountsExist(activity);

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

@ -5,6 +5,7 @@
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask;
import org.json.JSONArray;
@ -73,11 +74,11 @@ public final class TabsAccessor {
if (listener == null)
return;
(new UiAsyncTask<Void, Void, List<RemoteTab>>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, List<RemoteTab>>(ThreadUtils.getBackgroundHandler()) {
@Override
protected List<RemoteTab> doInBackground(Void... unused) {
Uri uri = BrowserContract.Tabs.CONTENT_URI;
if (limit > 0) {
uri = uri.buildUpon()
.appendQueryParameter(BrowserContract.PARAM_LIMIT, String.valueOf(limit))

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

@ -10,7 +10,7 @@ import android.content.SharedPreferences;
import android.graphics.Bitmap;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.GeckoBackgroundThread;
import org.mozilla.gecko.util.ThreadUtils;
public class WebAppAllocator {
private final String LOGTAG = "GeckoWebAppAllocator";
@ -70,7 +70,7 @@ public class WebAppAllocator {
if (!mPrefs.contains(appKey(i))) {
// found unused index i
final int foundIndex = i;
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
int color = 0;
@ -118,7 +118,7 @@ public class WebAppAllocator {
}
public synchronized void releaseIndex(final int index) {
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
mPrefs.edit()

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

@ -177,7 +177,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
* Query for suggestions, but don't show them yet.
*/
private void primeSuggestions() {
GeckoAppShell.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
mSuggestClient.query(mSearchTerm);
@ -844,7 +844,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
if (urls.size() == 0)
return;
(new UiAsyncTask<Void, Void, Cursor>(GeckoAppShell.getHandler()) {
(new UiAsyncTask<Void, Void, Cursor>(ThreadUtils.getBackgroundHandler()) {
@Override
public Cursor doInBackground(Void... params) {
return BrowserDB.getFaviconsForUrls(getContentResolver(), urls);

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

@ -356,7 +356,7 @@ public class HistoryTab extends AwesomeBarTab {
if (mContentObserver == null) {
// Register an observer to update the history tab contents if they change.
mContentObserver = new ContentObserver(GeckoAppShell.getHandler()) {
mContentObserver = new ContentObserver(ThreadUtils.getBackgroundHandler()) {
@Override
public void onChange(boolean selfChange) {
mQueryTask = new HistoryQueryTask();

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

@ -38,8 +38,8 @@ import org.mozilla.gecko.db.DBUtils;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.ProfileMigrator;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.util.GeckoBackgroundThread;
import org.mozilla.gecko.util.GeckoJarReader;
import org.mozilla.gecko.util.ThreadUtils;
import android.app.SearchManager;
import android.content.ContentProvider;
@ -1026,7 +1026,7 @@ public class BrowserProvider extends ContentProvider {
}
// create icons in a separate thread to avoid blocking about:home on startup
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
try {
@ -1069,7 +1069,7 @@ public class BrowserProvider extends ContentProvider {
createBookmark(db, title, url, pos);
// create icons in a separate thread to avoid blocking about:home on startup
GeckoBackgroundThread.getHandler().post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
Bitmap icon = getDefaultFaviconFromPath(name);
@ -1993,7 +1993,7 @@ public class BrowserProvider extends ContentProvider {
public boolean onCreate() {
debug("Creating BrowserProvider");
GeckoBackgroundThread.post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
// Kick this off early. It is synchronized so that other callers will wait

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

@ -15,7 +15,7 @@ import org.mozilla.gecko.db.BrowserContract.Clients;
import org.mozilla.gecko.db.BrowserContract.Tabs;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.DBUtils;
import org.mozilla.gecko.util.GeckoBackgroundThread;
import org.mozilla.gecko.util.ThreadUtils;
import android.content.ContentProvider;
import android.content.ContentUris;
@ -289,7 +289,7 @@ public class TabsProvider extends ContentProvider {
public boolean onCreate() {
debug("Creating TabsProvider");
GeckoBackgroundThread.post(new Runnable() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
// Kick this off early. It is synchronized so that other callers will wait

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

@ -9,7 +9,7 @@ import android.os.Looper;
import java.util.concurrent.SynchronousQueue;
public final class GeckoBackgroundThread extends Thread {
final class GeckoBackgroundThread extends Thread {
private static final String LOOPER_NAME = "GeckoBackgroundThread";
// Guarded by 'this'.
@ -33,7 +33,7 @@ public final class GeckoBackgroundThread extends Thread {
}
// Get a Handler for a looper thread, or create one if it doesn't yet exist.
public static synchronized Handler getHandler() {
/*package*/ static synchronized Handler getHandler() {
if (sHandler == null) {
GeckoBackgroundThread lt = new GeckoBackgroundThread();
ThreadUtils.setBackgroundThread(lt);
@ -45,7 +45,7 @@ public final class GeckoBackgroundThread extends Thread {
return sHandler;
}
public static void post(Runnable runnable) {
/*package*/ static void post(Runnable runnable) {
Handler handler = getHandler();
if (handler == null) {
throw new IllegalStateException("No handler! Must have been interrupted. Not posting.");

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

@ -47,6 +47,14 @@ public final class ThreadUtils {
return sBackgroundThread;
}
public static Handler getBackgroundHandler() {
return GeckoBackgroundThread.getHandler();
}
public static void postToBackgroundThread(Runnable runnable) {
GeckoBackgroundThread.post(runnable);
}
public static void assertOnUiThread() {
assertOnThread(getUiThread());
}