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

Unified Diff: mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 9 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
Index: mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java
diff --git a/mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java b/mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java
new file mode 100644
index 0000000000000000000000000000000000000000..1f55fa2c86776366a1b887e3f90d2a46f8325e57
--- /dev/null
+++ b/mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java
@@ -0,0 +1,105 @@
+// Copyright 2013 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.mojo.shell;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.Log;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A placeholder class to call native functions.
+ **/
+@JNINamespace("mojo::shell")
+public class ShellMain {
+ private static final String TAG = "ShellMain";
+
+ // Directory where applications bundled with the shell will be extracted.
+ private static final String LOCAL_APP_DIRECTORY = "local_apps";
+ // Individual applications bundled with the shell as assets.
+ private static final String NETWORK_LIBRARY_APP = "network_service.mojo";
+ // The mojo_shell library is also an executable run in forked processes when running
+ // multi-process.
+ private static final String MOJO_SHELL_EXECUTABLE = "libmojo_shell.so";
+
+ /**
+ * A guard flag for calling nativeInit() only once.
+ **/
+ private static boolean sInitialized = false;
+
+ /**
+ * Initializes the native system.
+ **/
+ static void ensureInitialized(Context applicationContext, String[] parameters) {
+ if (sInitialized) return;
+ try {
+ FileHelper.extractFromAssets(applicationContext, NETWORK_LIBRARY_APP,
+ getLocalAppsDir(applicationContext), false);
+ File mojoShell = new File(applicationContext.getApplicationInfo().nativeLibraryDir,
+ MOJO_SHELL_EXECUTABLE);
+
+ List<String> parametersList = new ArrayList<String>();
+ // Program name.
+ if (parameters != null) {
+ parametersList.addAll(Arrays.asList(parameters));
+ }
+
+ nativeInit(applicationContext, mojoShell.getAbsolutePath(),
+ parametersList.toArray(new String[parametersList.size()]),
+ getLocalAppsDir(applicationContext).getAbsolutePath(),
+ getTmpDir(applicationContext).getAbsolutePath());
+ sInitialized = true;
+ } catch (Exception e) {
+ Log.e(TAG, "ShellMain initialization failed.", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Starts the specified application in the specified context.
+ *
+ * @return <code>true</code> if an application has been launched.
+ **/
+ static boolean start() {
+ return nativeStart();
+ }
+
+ /**
+ * Adds the given URL to the set of mojo applications to run on start.
+ */
+ static void addApplicationURL(String url) {
+ nativeAddApplicationURL(url);
+ }
+
+ private static File getLocalAppsDir(Context context) {
+ return context.getDir(LOCAL_APP_DIRECTORY, Context.MODE_PRIVATE);
+ }
+
+ private static File getTmpDir(Context context) {
+ return new File(context.getCacheDir(), "tmp");
+ }
+
+ @CalledByNative
+ private static void finishActivity(Activity activity) {
+ activity.finish();
+ }
+
+ /**
+ * Initializes the native system. This API should be called only once per process.
+ **/
+ private static native void nativeInit(Context context, String mojoShellPath,
+ String[] parameters, String bundledAppsDirectory, String tmpDir);
+
+ private static native boolean nativeStart();
+
+ private static native void nativeAddApplicationURL(String url);
+}

Powered by Google App Engine
This is Rietveld 408576698