зеркало из https://github.com/mozilla/gecko-dev.git
Bug 734893: Faster DB accessing with priority for GeckoAsyncTask. [r=mfinkle, r=blassey]
This commit is contained in:
Родитель
a3334f6957
Коммит
573f5cc1ea
|
@ -41,15 +41,42 @@ package org.mozilla.gecko;
|
||||||
// We construct these off of the main thread, and we want that to run
|
// 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
|
// on the main UI thread, so this is a convenience class to do that
|
||||||
public abstract class GeckoAsyncTask<Params, Progress, Result> {
|
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) {
|
public void execute(final Params... params) {
|
||||||
GeckoAppShell.getHandler().post(new Runnable() {
|
if (mPriority == PRIORITY_HIGH)
|
||||||
public void run() {
|
GeckoAppShell.getHandler().postAtFrontOfQueue(new BackgroundTaskRunnable(params));
|
||||||
final Result result = doInBackground(params);
|
else
|
||||||
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
|
GeckoAppShell.getHandler().post(new BackgroundTaskRunnable(params));
|
||||||
public void run() {
|
}
|
||||||
onPostExecute(result);
|
|
||||||
}});
|
public GeckoAsyncTask<Params, Progress, Result> setPriority(int priority) {
|
||||||
}});
|
mPriority = priority;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Result doInBackground(Params... params);
|
protected abstract Result doInBackground(Params... params);
|
||||||
|
|
|
@ -20,6 +20,10 @@ import android.util.Log;
|
||||||
public final class TabsAccessor {
|
public final class TabsAccessor {
|
||||||
private static final String LOGTAG = "GeckoTabsAccessor";
|
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[] {
|
private static final String[] TABS_PROJECTION_COLUMNS = new String[] {
|
||||||
BrowserContract.Tabs.TITLE,
|
BrowserContract.Tabs.TITLE,
|
||||||
BrowserContract.Tabs.URL,
|
BrowserContract.Tabs.URL,
|
||||||
|
@ -35,6 +39,7 @@ public final class TabsAccessor {
|
||||||
NAME
|
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";
|
private static final String TABS_SELECTION = BrowserContract.Tabs.CLIENT_GUID + " IS NOT NULL";
|
||||||
|
|
||||||
public static class RemoteTab {
|
public static class RemoteTab {
|
||||||
|
@ -60,9 +65,14 @@ public final class TabsAccessor {
|
||||||
(new GeckoAsyncTask<Void, Void, Boolean> () {
|
(new GeckoAsyncTask<Void, Void, Boolean> () {
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... unused) {
|
protected Boolean doInBackground(Void... unused) {
|
||||||
Cursor cursor = context.getContentResolver().query(BrowserContract.Clients.CONTENT_URI,
|
Uri uri = BrowserContract.Tabs.CONTENT_URI;
|
||||||
null,
|
uri = uri.buildUpon()
|
||||||
null,
|
.appendQueryParameter(BrowserContract.PARAM_LIMIT, "1")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Cursor cursor = context.getContentResolver().query(uri,
|
||||||
|
CLIENTS_AVAILABILITY_PROJECTION,
|
||||||
|
CLIENTS_SELECTION,
|
||||||
null,
|
null,
|
||||||
null);
|
null);
|
||||||
|
|
||||||
|
@ -80,7 +90,7 @@ public final class TabsAccessor {
|
||||||
protected void onPostExecute(Boolean availability) {
|
protected void onPostExecute(Boolean availability) {
|
||||||
listener.areAvailable(availability);
|
listener.areAvailable(availability);
|
||||||
}
|
}
|
||||||
}).execute();
|
}).setPriority(GeckoAsyncTask.PRIORITY_HIGH).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method returns all tabs from all remote clients,
|
// This method returns all tabs from all remote clients,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче