Bug 734893: Faster DB accessing with priority for GeckoAsyncTask. [r=mfinkle, r=blassey]

This commit is contained in:
Sriram Ramasubramanian 2012-03-19 10:53:14 -07:00
Родитель a3334f6957
Коммит 573f5cc1ea
2 изменённых файлов: 49 добавлений и 12 удалений

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

@ -41,15 +41,42 @@ package org.mozilla.gecko;
// We construct these off of the main thread, and we want that to run
// on the main UI thread, so this is a convenience class to do that
public abstract class GeckoAsyncTask<Params, Progress, Result> {
public static final int PRIORITY_NORMAL = 0;
public static final int PRIORITY_HIGH = 1;
private int mPriority;
public GeckoAsyncTask() {
mPriority = PRIORITY_NORMAL;
}
private class BackgroundTaskRunnable implements Runnable {
private Params[] mParams;
public BackgroundTaskRunnable(Params... params) {
mParams = params;
}
public void run() {
final Result result = doInBackground(mParams);
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
public void run() {
onPostExecute(result);
}
});
}
}
public void execute(final Params... params) {
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {
final Result result = doInBackground(params);
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
public void run() {
onPostExecute(result);
}});
}});
if (mPriority == PRIORITY_HIGH)
GeckoAppShell.getHandler().postAtFrontOfQueue(new BackgroundTaskRunnable(params));
else
GeckoAppShell.getHandler().post(new BackgroundTaskRunnable(params));
}
public GeckoAsyncTask<Params, Progress, Result> setPriority(int priority) {
mPriority = priority;
return this;
}
protected abstract Result doInBackground(Params... params);

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

@ -20,6 +20,10 @@ import android.util.Log;
public final class TabsAccessor {
private static final String LOGTAG = "GeckoTabsAccessor";
private static final String[] CLIENTS_AVAILABILITY_PROJECTION = new String[] {
BrowserContract.Clients.GUID
};
private static final String[] TABS_PROJECTION_COLUMNS = new String[] {
BrowserContract.Tabs.TITLE,
BrowserContract.Tabs.URL,
@ -35,6 +39,7 @@ public final class TabsAccessor {
NAME
};
private static final String CLIENTS_SELECTION = BrowserContract.Clients.GUID + " IS NOT NULL";
private static final String TABS_SELECTION = BrowserContract.Tabs.CLIENT_GUID + " IS NOT NULL";
public static class RemoteTab {
@ -60,9 +65,14 @@ public final class TabsAccessor {
(new GeckoAsyncTask<Void, Void, Boolean> () {
@Override
protected Boolean doInBackground(Void... unused) {
Cursor cursor = context.getContentResolver().query(BrowserContract.Clients.CONTENT_URI,
null,
null,
Uri uri = BrowserContract.Tabs.CONTENT_URI;
uri = uri.buildUpon()
.appendQueryParameter(BrowserContract.PARAM_LIMIT, "1")
.build();
Cursor cursor = context.getContentResolver().query(uri,
CLIENTS_AVAILABILITY_PROJECTION,
CLIENTS_SELECTION,
null,
null);
@ -80,7 +90,7 @@ public final class TabsAccessor {
protected void onPostExecute(Boolean availability) {
listener.areAvailable(availability);
}
}).execute();
}).setPriority(GeckoAsyncTask.PRIORITY_HIGH).execute();
}
// This method returns all tabs from all remote clients,