Java Code Examples for org.chromium.base.ThreadUtils#runningOnUiThread()

The following examples show how to use org.chromium.base.ThreadUtils#runningOnUiThread() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecordUserAction.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void record(final String action) {
    if (sDisabledBy != null) return;

    if (ThreadUtils.runningOnUiThread()) {
        nativeRecordUserAction(action);
        return;
    }

    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            nativeRecordUserAction(action);
        }
    });
}
 
Example 2
Source File: AsyncTask.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Waits if necessary for the computation to complete, and then
 * retrieves its result.
 *
 * @return The computed result.
 *
 * @throws CancellationException If the computation was cancelled.
 * @throws ExecutionException If the computation threw an exception.
 * @throws InterruptedException If the current thread was interrupted
 *         while waiting.
 */
@DoNotInline
public final Result get() throws InterruptedException, ExecutionException {
    Result r;
    if (getStatus() != Status.FINISHED && ThreadUtils.runningOnUiThread()) {
        StackTraceElement[] stackTrace = new Exception().getStackTrace();
        String caller = "";
        if (stackTrace.length > 1) {
            caller = stackTrace[1].getClassName() + '.' + stackTrace[1].getMethodName() + '.';
        }
        TraceEvent te = null;
        try  {
            te = TraceEvent.scoped(caller + "AsyncTask.get");
            r = mFuture.get();
        } finally {
            if (te != null) {
                try {
                    te.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    } else {
        r = mFuture.get();
    }
    return r;
}
 
Example 3
Source File: ChromeBrowserProvider.java    From delion with Apache License 2.0 5 votes vote down vote up
private static boolean isInUiThread() {
    if (!ThreadUtils.runningOnUiThread()) return false;

    if (!"REL".equals(Build.VERSION.CODENAME)) {
        throw new IllegalStateException("Shouldn't run in the UI thread");
    }

    Log.w(TAG, "ChromeBrowserProvider methods cannot be called from the UI thread.");
    return true;
}
 
Example 4
Source File: ChromeBrowserProvider.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private static boolean isInUiThread() {
    if (!ThreadUtils.runningOnUiThread()) return false;

    if (!"REL".equals(Build.VERSION.CODENAME)) {
        throw new IllegalStateException("Shouldn't run in the UI thread");
    }

    Log.w(TAG, "ChromeBrowserProvider methods cannot be called from the UI thread.");
    return true;
}
 
Example 5
Source File: RecordUserAction.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public static void record(final String action) {
    if (sDisabledBy != null) return;

    if (ThreadUtils.runningOnUiThread()) {
        nativeRecordUserAction(action);
        return;
    }

    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            nativeRecordUserAction(action);
        }
    });
}
 
Example 6
Source File: ChromeBrowserProvider.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static boolean isInUiThread() {
    if (!ThreadUtils.runningOnUiThread()) return false;

    if (!"REL".equals(Build.VERSION.CODENAME)) {
        throw new IllegalStateException("Shouldn't run in the UI thread");
    }

    Log.w(TAG, "ChromeBrowserProvider methods cannot be called from the UI thread.");
    return true;
}
 
Example 7
Source File: WebContentsImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void destroy() {
    if (!ThreadUtils.runningOnUiThread()) {
        throw new IllegalStateException("Attempting to destroy WebContents on non-UI thread");
    }
    if (mNativeWebContentsAndroid != 0) nativeDestroyWebContents(mNativeWebContentsAndroid);
}
 
Example 8
Source File: ChromeBrowserProvider.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static boolean isInUiThread() {
    if (!ThreadUtils.runningOnUiThread()) return false;

    if (!"REL".equals(Build.VERSION.CODENAME)) {
        throw new IllegalStateException("Shouldn't run in the UI thread");
    }

    Log.w(TAG, "ChromeBrowserProvider methods cannot be called from the UI thread.");
    return true;
}
 
Example 9
Source File: ChromeBrowserProvider.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static boolean isInUiThread() {
    if (!ThreadUtils.runningOnUiThread()) return false;

    if (!"REL".equals(Build.VERSION.CODENAME)) {
        throw new IllegalStateException("Shouldn't run in the UI thread");
    }

    Log.w(TAG, "ChromeBrowserProvider methods cannot be called from the UI thread.");
    return true;
}
 
Example 10
Source File: ThreadedInputConnection.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected boolean runningOnUiThread() {
    return ThreadUtils.runningOnUiThread();
}