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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.mojo.shell;
6
7 import android.app.Activity;
8 import android.content.Context;
9 import android.util.Log;
10
11 import org.chromium.base.CalledByNative;
12 import org.chromium.base.JNINamespace;
13
14 import java.io.File;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
19 /**
20 * A placeholder class to call native functions.
21 **/
22 @JNINamespace("mojo::shell")
23 public class ShellMain {
24 private static final String TAG = "ShellMain";
25
26 // Directory where applications bundled with the shell will be extracted.
27 private static final String LOCAL_APP_DIRECTORY = "local_apps";
28 // Individual applications bundled with the shell as assets.
29 private static final String NETWORK_LIBRARY_APP = "network_service.mojo";
30 // The mojo_shell library is also an executable run in forked processes when running
31 // multi-process.
32 private static final String MOJO_SHELL_EXECUTABLE = "libmojo_shell.so";
33
34 /**
35 * A guard flag for calling nativeInit() only once.
36 **/
37 private static boolean sInitialized = false;
38
39 /**
40 * Initializes the native system.
41 **/
42 static void ensureInitialized(Context applicationContext, String[] parameter s) {
43 if (sInitialized) return;
44 try {
45 FileHelper.extractFromAssets(applicationContext, NETWORK_LIBRARY_APP ,
46 getLocalAppsDir(applicationContext), false);
47 File mojoShell = new File(applicationContext.getApplicationInfo().na tiveLibraryDir,
48 MOJO_SHELL_EXECUTABLE);
49
50 List<String> parametersList = new ArrayList<String>();
51 // Program name.
52 if (parameters != null) {
53 parametersList.addAll(Arrays.asList(parameters));
54 }
55
56 nativeInit(applicationContext, mojoShell.getAbsolutePath(),
57 parametersList.toArray(new String[parametersList.size()]),
58 getLocalAppsDir(applicationContext).getAbsolutePath(),
59 getTmpDir(applicationContext).getAbsolutePath());
60 sInitialized = true;
61 } catch (Exception e) {
62 Log.e(TAG, "ShellMain initialization failed.", e);
63 throw new RuntimeException(e);
64 }
65 }
66
67 /**
68 * Starts the specified application in the specified context.
69 *
70 * @return <code>true</code> if an application has been launched.
71 **/
72 static boolean start() {
73 return nativeStart();
74 }
75
76 /**
77 * Adds the given URL to the set of mojo applications to run on start.
78 */
79 static void addApplicationURL(String url) {
80 nativeAddApplicationURL(url);
81 }
82
83 private static File getLocalAppsDir(Context context) {
84 return context.getDir(LOCAL_APP_DIRECTORY, Context.MODE_PRIVATE);
85 }
86
87 private static File getTmpDir(Context context) {
88 return new File(context.getCacheDir(), "tmp");
89 }
90
91 @CalledByNative
92 private static void finishActivity(Activity activity) {
93 activity.finish();
94 }
95
96 /**
97 * Initializes the native system. This API should be called only once per pr ocess.
98 **/
99 private static native void nativeInit(Context context, String mojoShellPath,
100 String[] parameters, String bundledAppsDirectory, String tmpDir);
101
102 private static native boolean nativeStart();
103
104 private static native void nativeAddApplicationURL(String url);
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698