Index: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
index 4c995129bbcf063066fac2ebe746de2b0f6c7c45..a58753d006fef1e574dacecbe36dae1e6fcd1bf6 100644 |
--- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
+++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
@@ -37,6 +37,11 @@ public class LibraryLoader { |
// One-way switch becomes true when the libraries are loaded. |
private static boolean sLoaded = false; |
+ // One-way switch becomes true when the native command line is initialized ( |
+ // by calling nativeInitCommandLine, which forwards to |
+ // InitCommandLine(...) in library_loader_hooks.cc). |
+ private static boolean sCommandLineInitialized = false; |
+ |
// One-way switch becomes true when the libraries are initialized ( |
// by calling nativeLibraryLoaded, which forwards to LibraryLoaded(...) in |
// library_loader_hooks.cc). |
@@ -83,7 +88,14 @@ public class LibraryLoader { |
return; |
} |
loadAlreadyLocked(context, shouldDeleteOldWorkaroundLibraries); |
- initializeAlreadyLocked(CommandLine.getJavaSwitchesOrNull()); |
+ |
+ // We can only call getJavaSwitchesOrNull if we have not yet |
+ // switched CommandLine to native. |
+ String[] switches = null; |
+ if (!sCommandLineInitialized) { |
+ switches = CommandLine.getJavaSwitchesOrNull(); |
+ } |
+ initializeAlreadyLocked(switches); |
} |
} |
@@ -200,13 +212,36 @@ public class LibraryLoader { |
} |
} |
+ /** |
+ * Set the native command line if it is has not been set yet. |
+ * If the command line is set already the arguments are ignored. |
+ * The library must have previously been loaded with loadNow. |
+ */ |
+ public static void ensureCommandLineInit(String[] initCommandLine) { |
bulach
2014/05/21 11:33:49
hmm... this method seems dangerous, it "ensures" b
hjd
2014/05/22 11:09:10
Yeah I felt bad writing that name... I've changed
|
+ synchronized (sLock) { |
+ ensureCommandLineInitAlreadyLocked(initCommandLine); |
+ } |
+ } |
+ |
+ private static void ensureCommandLineInitAlreadyLocked(String[] initCommandLine) { |
+ if (sCommandLineInitialized) { |
+ return; |
+ } |
+ nativeInitCommandLine(initCommandLine); |
bulach
2014/05/21 11:33:49
calling an unbound method throws some fairly crypt
hjd
2014/05/22 11:09:10
I added a lot of extra LoaderErrors and checked th
|
+ CommandLine.enableNativeProxy(); |
+ sCommandLineInitialized = true; |
+ } |
+ |
// Invoke base::android::LibraryLoaded in library_loader_hooks.cc |
private static void initializeAlreadyLocked(String[] initCommandLine) |
throws ProcessInitException { |
if (sInitialized) { |
return; |
} |
- if (!nativeLibraryLoaded(initCommandLine)) { |
+ |
+ ensureCommandLineInitAlreadyLocked(initCommandLine); |
+ |
+ if (!nativeLibraryLoaded()) { |
Log.e(TAG, "error calling nativeLibraryLoaded"); |
throw new ProcessInitException(LoaderErrors.LOADER_ERROR_FAILED_TO_REGISTER_JNI); |
} |
@@ -214,7 +249,6 @@ public class LibraryLoader { |
// shouldn't complain from now on (and in fact, it's used by the |
// following calls). |
sInitialized = true; |
- CommandLine.enableNativeProxy(); |
// From now on, keep tracing in sync with native. |
TraceEvent.registerNativeEnabledObserver(); |
@@ -228,13 +262,16 @@ public class LibraryLoader { |
nativeRecordNativeLibraryHack(sNativeLibraryHackWasUsed); |
} |
+ // Invokes InitCommandLine in library_loader_hooks.cc to set the native command line. |
+ private static native void nativeInitCommandLine(String[] commandLine); |
+ |
// Only methods needed before or during normal JNI registration are during System.OnLoad. |
// nativeLibraryLoaded is then called to register everything else. This process is called |
// "initialization". This method will be mapped (by generated code) to the LibraryLoaded |
// definition in base/android/library_loader/library_loader_hooks.cc. |
// |
// Return true on success and false on failure. |
- private static native boolean nativeLibraryLoaded(String[] initCommandLine); |
+ private static native boolean nativeLibraryLoaded(); |
// Method called to record statistics about the Chromium linker operation, |
// i.e. whether the library failed to be loaded at a fixed address, and |