mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 897162 - Lower Gecko thread priority when showing Top Sites page. r=lucasr
This commit is contained in:
parent
9fd472da4b
commit
c9dc3ae6fd
@ -108,6 +108,9 @@ public class TopSitesPage extends HomeFragment {
|
||||
// Max number of entries shown in the grid from the cursor.
|
||||
private int mMaxGridEntries;
|
||||
|
||||
// Time in ms until the Gecko thread is reset to normal priority.
|
||||
private static final long PRIORITY_RESET_TIMEOUT = 10000;
|
||||
|
||||
/**
|
||||
* Class to hold the bitmap of cached thumbnails/favicons.
|
||||
*/
|
||||
@ -359,6 +362,14 @@ public class TopSitesPage extends HomeFragment {
|
||||
@Override
|
||||
protected void load() {
|
||||
getLoaderManager().initLoader(LOADER_ID_TOP_SITES, null, mCursorLoaderCallbacks);
|
||||
|
||||
// Since this is the primary fragment that loads whenever about:home is
|
||||
// visited, we want to load it as quickly as possible. Heavy load on
|
||||
// the Gecko thread can slow down the time it takes for thumbnails to
|
||||
// appear, especially during startup (bug 897162). By minimizing the
|
||||
// Gecko thread priority, we ensure that the UI appears quickly. The
|
||||
// priority is reset to normal once thumbnails are loaded.
|
||||
ThreadUtils.reduceGeckoPriority(PRIORITY_RESET_TIMEOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -769,6 +780,10 @@ public class TopSitesPage extends HomeFragment {
|
||||
if (mGridAdapter != null) {
|
||||
mGridAdapter.updateThumbnails(thumbnails);
|
||||
}
|
||||
|
||||
// Once thumbnails have finished loading, the UI is ready. Reset
|
||||
// Gecko to normal priority.
|
||||
ThreadUtils.resetGeckoPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,9 @@ public final class ThreadUtils {
|
||||
public static MessageQueue sGeckoQueue;
|
||||
public static Thread sGeckoThread;
|
||||
|
||||
// Delayed Runnable that resets the Gecko thread priority.
|
||||
private static volatile Runnable sPriorityResetRunnable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class UiThreadBlockedException extends RuntimeException {
|
||||
public UiThreadBlockedException() {
|
||||
@ -127,4 +130,37 @@ public final class ThreadUtils {
|
||||
public static boolean isOnThread(Thread thread) {
|
||||
return (Thread.currentThread().getId() == thread.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces the priority of the Gecko thread, allowing other operations
|
||||
* (such as those related to the UI and database) to take precedence.
|
||||
*
|
||||
* Note that there are no guards in place to prevent multiple calls
|
||||
* to this method from conflicting with each other.
|
||||
*
|
||||
* @param timeout Timeout in ms after which the priority will be reset
|
||||
*/
|
||||
public static void reduceGeckoPriority(long timeout) {
|
||||
sGeckoThread.setPriority(Thread.MIN_PRIORITY);
|
||||
sPriorityResetRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
resetGeckoPriority();
|
||||
}
|
||||
};
|
||||
getUiHandler().postDelayed(sPriorityResetRunnable, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the priority of a thread whose priority has been reduced
|
||||
* by reduceGeckoPriority.
|
||||
*/
|
||||
public static void resetGeckoPriority() {
|
||||
if (sPriorityResetRunnable != null) {
|
||||
sGeckoThread.setPriority(Thread.NORM_PRIORITY);
|
||||
|
||||
getUiHandler().removeCallbacks(sPriorityResetRunnable);
|
||||
sPriorityResetRunnable = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user