Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.gecko;
7 import java.util.concurrent.SynchronousQueue;
8 import java.util.concurrent.TimeUnit;
10 import android.app.Activity;
12 public final class RobocopUtils {
13 private static final int MAX_WAIT_MS = 20000;
15 private RobocopUtils() {}
17 public static void runOnUiThreadSync(Activity activity, final Runnable runnable) {
18 final SynchronousQueue syncQueue = new SynchronousQueue();
19 activity.runOnUiThread(
20 new Runnable() {
21 public void run() {
22 runnable.run();
23 try {
24 syncQueue.put(new Object());
25 } catch (InterruptedException e) {
26 FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR, e);
27 }
28 }
29 });
30 try {
31 // Wait for the UiThread code to finish running
32 if (syncQueue.poll(MAX_WAIT_MS, TimeUnit.MILLISECONDS) == null) {
33 FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR,
34 "time-out waiting for UI thread");
35 FennecNativeDriver.logAllStackTraces(FennecNativeDriver.LogLevel.ERROR);
36 }
37 } catch (InterruptedException e) {
38 FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR, e);
39 }
40 }
41 }