Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(958)

Unified Diff: base/android/java/src/org/chromium/base/ThreadUtils.java

Issue 10913284: Reduce number of temporory objects created posting tasks (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/src/org/chromium/base/ThreadUtils.java
diff --git a/base/android/java/src/org/chromium/base/ThreadUtils.java b/base/android/java/src/org/chromium/base/ThreadUtils.java
index ca31c3df0abc7eac5e8f108a58f8826282bc1093..b827a0b6c0b49914cebdcfe8f357fec32fc2b915 100644
--- a/base/android/java/src/org/chromium/base/ThreadUtils.java
+++ b/base/android/java/src/org/chromium/base/ThreadUtils.java
@@ -103,7 +103,11 @@ public class ThreadUtils {
* @param r The Runnable to run
*/
public static void runOnUiThread(Runnable r) {
- runOnUiThread(new FutureTask<Void>(r, null));
+ if (runningOnUiThread()) {
+ r.run();
+ } else {
+ LazyHolder.sUiThreadHandler.post(r);
+ }
}
/**
@@ -114,7 +118,7 @@ public class ThreadUtils {
* @return The queried task (to aid inline construction)
*/
public static <T> FutureTask<T> postOnUiThread(FutureTask<T> task) {
- new Handler(Looper.getMainLooper()).post(task);
+ LazyHolder.sUiThreadHandler.post(task);
return task;
}
@@ -131,4 +135,8 @@ public class ThreadUtils {
public static boolean runningOnUiThread() {
return Looper.getMainLooper() == Looper.myLooper();
}
+
+ private static class LazyHolder {
+ private static Handler sUiThreadHandler = new Handler(Looper.getMainLooper());
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698