summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorcjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-01 23:12:33 +0000
committercjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-01 23:12:33 +0000
commitb50a8b536ce7f2707293966deee3d2816c773392 (patch)
tree0d794ed9f79d49c8e5f6f7ce1495e2c131663725 /content
parent043e41762215cd4c6d93880d6c381adcd9e818aa (diff)
downloadchromium_src-b50a8b536ce7f2707293966deee3d2816c773392.zip
chromium_src-b50a8b536ce7f2707293966deee3d2816c773392.tar.gz
chromium_src-b50a8b536ce7f2707293966deee3d2816c773392.tar.bz2
Make the build control what library(/ies) to load
At build time, we know what native libraries an apk needs to load. Instead of requiring those .apks to specify this again in code, instead generate a .java file containing a list of the libraries to load. This is done using a pattern similar to resources, content_java is built with a placeholder NativeLibraries.java (i.e. without an actual value for its libraries list). The corresponding .class file is not included in content_java.jar. Then, when building an apk we generate the "real" NativeLibraries.java (with the real String[]) and include that in the .apk. This is designed to also support the component build, where, we will have to calculate the list of libraries at build time, and sort them in dependency order (because Android's linker, for some reason, doesn't do that itself). BUG=158821 TBR=brettw@chromium.org Review URL: https://chromiumcodereview.appspot.com/12939021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191695 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/content.gyp17
-rw-r--r--content/public/android/java/src/org/chromium/content/app/ChildProcessService.java9
-rw-r--r--content/public/android/java/src/org/chromium/content/app/LibraryLoader.java57
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java7
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java6
-rw-r--r--content/public/android/java/templates/NativeLibraries.template17
-rw-r--r--content/public/android/java/templates/native_libraries_array.h8
-rw-r--r--content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsApplication.java2
-rw-r--r--content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellApplication.java2
9 files changed, 60 insertions, 65 deletions
diff --git a/content/content.gyp b/content/content.gyp
index 1068b7e..6f7104f 100644
--- a/content/content.gyp
+++ b/content/content.gyp
@@ -301,6 +301,21 @@
'includes': [ '../build/java_aidl.gypi' ],
},
{
+ 'target_name': 'content_native_libraries_gen',
+ 'type': 'none',
+ 'sources': [
+ 'public/android/java/templates/NativeLibraries.template',
+ ],
+ 'variables': {
+ 'package_name': 'org/chromium/content/app',
+ 'include_path': 'public/android/java/templates',
+ 'template_deps': [
+ 'public/android/java/templates/native_libraries_array.h'
+ ],
+ },
+ 'includes': [ '../build/android/java_cpp_template.gypi' ],
+ },
+ {
'target_name': 'content_java',
'type': 'none',
'dependencies': [
@@ -312,9 +327,11 @@
'content_common',
'page_transition_types_java',
'result_codes_java',
+ 'content_native_libraries_gen',
],
'variables': {
'java_in_dir': '../content/public/android/java',
+ 'jar_excluded_classes': [ '*/NativeLibraries.class' ],
'has_java_resources': 1,
'R_package': 'org.chromium.content',
'R_package_relpath': 'org/chromium/content',
diff --git a/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java b/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java
index 240cf5b..3d85310 100644
--- a/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java
+++ b/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java
@@ -46,7 +46,6 @@ public class ChildProcessService extends Service {
// This is the native "Main" thread for the renderer / utility process.
private Thread mMainThread;
// Parameters received via IPC, only accessed while holding the mMainThread monitor.
- private String mNativeLibraryName; // Must be passed in via the bind command.
private String[] mCommandLineParams;
private int mCpuCount;
private long mCpuFeatures;
@@ -113,12 +112,6 @@ public class ChildProcessService extends Service {
@Override
public void run() {
try {
- synchronized (mMainThread) {
- while (mNativeLibraryName == null) {
- mMainThread.wait();
- }
- }
- LibraryLoader.setLibraryToLoad(mNativeLibraryName);
try {
LibraryLoader.loadNow();
} catch (ProcessInitException e) {
@@ -193,8 +186,6 @@ public class ChildProcessService extends Service {
stopSelf();
synchronized (mMainThread) {
- mNativeLibraryName = intent.getStringExtra(
- ChildProcessConnection.EXTRA_NATIVE_LIBRARY_NAME);
mCommandLineParams = intent.getStringArrayExtra(
ChildProcessConnection.EXTRA_COMMAND_LINE);
mMainThread.notifyAll();
diff --git a/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java b/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java
index abd1ef1..edde50a 100644
--- a/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java
+++ b/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java
@@ -14,17 +14,15 @@ import org.chromium.content.common.ResultCodes;
import org.chromium.content.common.TraceEvent;
/**
- * This class provides functionality to load and register the native library.
- * Callers are allowed to separate loading the library from initializing it.
- * This may be an advantage for Android Webview, where the library can be loaded
+ * This class provides functionality to load and register the native libraries.
+ * Callers are allowed to separate loading the libraries from initializing them.
+ * This may be an advantage for Android Webview, where the libraries can be loaded
* by the zygote process, but then needs per process initialization after the
* application processes are forked from the zygote process.
*
- * The library may be loaded and initialized from any thread. Synchronization
+ * The libraries may be loaded and initialized from any thread. Synchronization
* primitives are used to ensure that overlapping requests from different
- * threads are handled sequentially; however, care must still be taken to
- * ensure that {@link #setLibraryToLoad(String)} is called prior to invoking
- * {@link #loadNow()} or {@link #ensureInitialized()}.
+ * threads are handled sequentially.
*
* See also content/app/android/library_loader_hooks.cc, which contains
* the native counterpart to this class.
@@ -33,45 +31,23 @@ import org.chromium.content.common.TraceEvent;
public class LibraryLoader {
private static final String TAG = "LibraryLoader";
- // The name of the library that will be loaded. Ideally this is a
- // write-once, read-many value, but for the sake of unit tests
- // we allow it to be mutated arbitrarily.
- private static String sLibrary = null;
-
- // Guards all access to the library
+ // Guards all access to the libraries
private static final Object sLock = new Object();
- // One-way switch becomes true when the library is loaded.
+ // One-way switch becomes true when the libraries are loaded.
private static boolean sLoaded = false;
- // One-way switch becomes true when the library is initialized (
+ // One-way switch becomes true when the libraries are initialized (
// by calling nativeLibraryLoaded, which forwards to LibraryLoaded(...) in
// library_loader_hooks.cc).
private static boolean sInitialized = false;
-
+ // TODO(cjhopman): Remove this once it's unused.
/**
- * Sets the library name that is to be loaded. This must be called prior to the library being
- * loaded the first time. Outside of testing, this should only be called once.
- *
- * @param library The name of the library to be loaded (without the lib prefix).
+ * Doesn't do anything.
*/
+ @Deprecated
public static void setLibraryToLoad(String library) {
- synchronized(sLock) {
- if (TextUtils.equals(sLibrary, library)) return;
-
- assert !sLoaded : "Setting the library must happen before load is called.";
- sLibrary = library;
- }
- }
-
- /**
- * @return The name of the native library set to be loaded.
- */
- public static String getLibraryToLoad() {
- synchronized(sLock) {
- return sLibrary;
- }
}
/**
@@ -121,15 +97,14 @@ public class LibraryLoader {
// Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code
private static void loadAlreadyLocked() throws ProcessInitException {
- if (sLibrary == null) {
- assert false : "No library specified to load. Call setLibraryToLoad before first.";
- }
try {
if (!sLoaded) {
assert !sInitialized;
- Log.i(TAG, "loading: " + sLibrary);
- System.loadLibrary(sLibrary);
- Log.i(TAG, "loaded: " + sLibrary);
+ for (String sLibrary: NativeLibraries.libraries) {
+ Log.i(TAG, "loading: " + sLibrary);
+ System.loadLibrary(sLibrary);
+ Log.i(TAG, "loaded: " + sLibrary);
+ }
sLoaded = true;
}
} catch (UnsatisfiedLinkError e) {
diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java
index ce9a164..cfd5f54 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java
@@ -36,8 +36,6 @@ public class ChildProcessConnection implements ServiceConnection {
// Names of items placed in the bind intent or connection bundle.
public static final String EXTRA_COMMAND_LINE =
"com.google.android.apps.chrome.extra.command_line";
- public static final String EXTRA_NATIVE_LIBRARY_NAME =
- "com.google.android.apps.chrome.extra.native_library_name";
// Note the FDs may only be passed in the connection bundle.
public static final String EXTRA_FILES_PREFIX =
"com.google.android.apps.chrome.extra.extraFile_";
@@ -128,19 +126,16 @@ public class ChildProcessConnection implements ServiceConnection {
* to setup the connection parameters. (These methods are separated to allow the client
* to pass whatever parameters they have available here, and complete the remainder
* later while reducing the connection setup latency).
- * @param nativeLibraryName The name of the shared native library to be loaded for the
- * child process.
* @param commandLine (Optional) Command line for the child process. If omitted, then
* the command line parameters must instead be passed to setupConnection().
*/
- void bind(String nativeLibraryName, String[] commandLine) {
+ void bind(String[] commandLine) {
synchronized(mUiThreadLock) {
TraceEvent.begin();
assert !ThreadUtils.runningOnUiThread();
final Intent intent = createServiceBindIntent();
- intent.putExtra(EXTRA_NATIVE_LIBRARY_NAME, nativeLibraryName);
if (commandLine != null) {
intent.putExtra(EXTRA_COMMAND_LINE, commandLine);
}
diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java
index 5ddc008..92669a6 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java
@@ -18,7 +18,6 @@ import org.chromium.base.ThreadUtils;
import org.chromium.content.app.ChildProcessService;
import org.chromium.content.app.PrivilegedProcessService;
import org.chromium.content.app.SandboxedProcessService;
-import org.chromium.content.app.LibraryLoader;
import org.chromium.content.common.IChildProcessCallback;
import org.chromium.content.common.IChildProcessService;
@@ -155,10 +154,7 @@ public class ChildProcessLauncher {
String[] commandLine, boolean inSandbox) {
ChildProcessConnection connection = allocateConnection(context, inSandbox);
if (connection != null) {
- String libraryName = LibraryLoader.getLibraryToLoad();
- assert libraryName != null : "Attempting to launch a child process without first "
- + "calling LibraryLoader.setLibraryToLoad";
- connection.bind(libraryName, commandLine);
+ connection.bind(commandLine);
}
return connection;
}
diff --git a/content/public/android/java/templates/NativeLibraries.template b/content/public/android/java/templates/NativeLibraries.template
new file mode 100644
index 0000000..a7ce76d
--- /dev/null
+++ b/content/public/android/java/templates/NativeLibraries.template
@@ -0,0 +1,17 @@
+// 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.content.app;
+
+public class NativeLibraries {
+ // This is the list of native libraries to be loaded (in the correct order)
+ // by LibraryLoader.java. The content java library is compiled with no
+ // array defined, and then the build system creates a version of the file
+ // with the real list of libraries required (which changes based upon which
+ // .apk is being built).
+ static String[] libraries
+#include <native_libraries_array.h>
+ ;
+}
+
diff --git a/content/public/android/java/templates/native_libraries_array.h b/content/public/android/java/templates/native_libraries_array.h
new file mode 100644
index 0000000..a86c574
--- /dev/null
+++ b/content/public/android/java/templates/native_libraries_array.h
@@ -0,0 +1,8 @@
+// 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.
+
+// This is a placeholder for compiling content_java. The content java library
+// is compiled with no array defined, and then the build system creates a
+// version of the file with the real list of libraries required (which changes
+// based upon which .apk is being built).
diff --git a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsApplication.java b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsApplication.java
index 315a17e..c850636 100644
--- a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsApplication.java
+++ b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsApplication.java
@@ -12,7 +12,6 @@ import org.chromium.content.browser.ResourceExtractor;
public class ContentBrowserTestsApplication extends Application {
- private static final String NATIVE_LIBRARY = "content_browsertests";
private static final String[] MANDATORY_PAK_FILES = new String[] {"content_shell.pak"};
private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "content_shell";
@@ -24,7 +23,6 @@ public class ContentBrowserTestsApplication extends Application {
public static void initializeApplicationParameters() {
ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES);
- LibraryLoader.setLibraryToLoad(NATIVE_LIBRARY);
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
}
diff --git a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellApplication.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellApplication.java
index 6d79070..ddbe76f 100644
--- a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellApplication.java
+++ b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellApplication.java
@@ -16,7 +16,6 @@ import org.chromium.content.browser.ResourceExtractor;
*/
public class ContentShellApplication extends Application {
- private static final String NATIVE_LIBRARY = "content_shell_content_view";
private static final String[] MANDATORY_PAK_FILES = new String[] {"content_shell.pak"};
private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "content_shell";
@@ -28,7 +27,6 @@ public class ContentShellApplication extends Application {
public static void initializeApplicationParameters() {
ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES);
- LibraryLoader.setLibraryToLoad(NATIVE_LIBRARY);
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
}