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

Unified Diff: content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestUtils.java

Issue 2840303002: Making ChildProcessConnection only accessed from the launcher thread. (Closed)
Patch Set: Clean-up + sync Created 3 years, 8 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 | « content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestHelperService.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestUtils.java
diff --git a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestUtils.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..7884711d80e6fa5e8f52cba0252bce8ceef59956
--- /dev/null
+++ b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestUtils.java
@@ -0,0 +1,103 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content_shell_apk;
+
+import android.content.Context;
+
+import org.chromium.base.process_launcher.ChildProcessCreationParams;
+import org.chromium.base.process_launcher.FileDescriptorInfo;
+import org.chromium.base.process_launcher.IChildProcessService;
+import org.chromium.content.browser.BaseChildProcessConnection;
+import org.chromium.content.browser.ChildProcessLauncher;
+import org.chromium.content.browser.LauncherThread;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.Semaphore;
+
+/** An assortment of static methods used in tests that deal with launching child processes. */
+public final class ChildProcessLauncherTestUtils {
+ // Do not instanciate, use static methods instead.
+ private ChildProcessLauncherTestUtils() {}
+
+ public static void runOnLauncherThreadBlocking(final Runnable runnable) {
+ if (LauncherThread.runningOnLauncherThread()) {
+ runnable.run();
+ return;
+ }
+ final Semaphore done = new Semaphore(0);
+ LauncherThread.post(new Runnable() {
+ @Override
+ public void run() {
+ runnable.run();
+ done.release();
+ }
+ });
+ done.acquireUninterruptibly();
+ }
+
+ public static <R> R runOnLauncherAndGetResult(Callable<R> callable) {
+ if (LauncherThread.runningOnLauncherThread()) {
+ try {
+ return callable.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ try {
+ FutureTask<R> task = new FutureTask<R>(callable);
+ LauncherThread.post(task);
+ return task.get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static BaseChildProcessConnection startInternalForTesting(final Context context,
+ final String[] commandLine, final FileDescriptorInfo[] filesToMap,
+ final ChildProcessCreationParams params) {
+ return runOnLauncherAndGetResult(new Callable<BaseChildProcessConnection>() {
+ @Override
+ public BaseChildProcessConnection call() {
+ return ChildProcessLauncher.startInternal(context, commandLine,
+ 0 /* childProcessId */, filesToMap, null /* launchCallback */,
+ null /* childProcessCallback */, true /* inSandbox */,
+ false /* alwaysInForeground */, params);
+ }
+ });
+ }
+
+ // Retrieves the PID of the passed in connection on the launcher thread as to not assert.
+ public static int getConnectionPid(final BaseChildProcessConnection connection) {
+ return runOnLauncherAndGetResult(new Callable<Integer>() {
+ @Override
+ public Integer call() {
+ return connection.getPid();
+ }
+ });
+ }
+
+ // Retrieves the service number of the passed in connection on the launcher thread as to not
+ // assert.
+ public static int getConnectionServiceNumber(final BaseChildProcessConnection connection) {
+ return runOnLauncherAndGetResult(new Callable<Integer>() {
+ @Override
+ public Integer call() {
+ return connection.getServiceNumber();
+ }
+ });
+ }
+
+ // Retrieves the service of the passed in connection on the launcher thread as to not assert.
+ public static IChildProcessService getConnectionService(
+ final BaseChildProcessConnection connection) {
+ return runOnLauncherAndGetResult(new Callable<IChildProcessService>() {
+ @Override
+ public IChildProcessService call() {
+ return connection.getService();
+ }
+ });
+ }
+}
« no previous file with comments | « content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ChildProcessLauncherTestHelperService.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698