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

Unified Diff: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java

Issue 598363003: Fix CommandLine initialization for Chrome & WebView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 6 years, 3 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 | « android_webview/javatests/src/org/chromium/android_webview/test/CommandLineTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 106b207bf3411b65ec03d4f954663e3bed89cc22..91e53678707f17b3b96a8b8bacaebe6ab07818de 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,10 @@ 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 Java command line is switched to
+ // native.
+ private static boolean sCommandLineSwitched = false;
+
// One-way switch becomes true when the libraries are initialized (
// by calling nativeLibraryLoaded, which forwards to LibraryLoaded(...) in
// library_loader_hooks.cc).
@@ -216,9 +220,6 @@ public class LibraryLoader {
startTime % 10000,
stopTime % 10000));
- nativeInitCommandLine(CommandLine.getJavaSwitchesOrNull());
- CommandLine.enableNativeProxy();
-
sLoaded = true;
}
} catch (UnsatisfiedLinkError e) {
@@ -235,12 +236,39 @@ public class LibraryLoader {
}
}
+ // The WebView requires the Command Line to be switched over before
+ // initialization is done. This is okay in the WebView's case since the
+ // JNI is already loaded by this point.
+ public static void switchCommandLineForWebView() {
+ synchronized (sLock) {
+ ensureCommandLineSwitchedAlreadyLocked();
+ }
+ }
+
+ // Switch the CommandLine over from Java to native if it hasn't already been done.
+ // This must happen after the code is loaded and after JNI is ready (since after the
+ // switch the Java CommandLine will delegate all calls the native CommandLine).
+ private static void ensureCommandLineSwitchedAlreadyLocked() {
+ assert sLoaded;
+ if (sCommandLineSwitched) {
+ return;
+ }
+ nativeInitCommandLine(CommandLine.getJavaSwitchesOrNull());
+ CommandLine.enableNativeProxy();
+ sCommandLineSwitched = true;
+ }
+
// Invoke base::android::LibraryLoaded in library_loader_hooks.cc
private static void initializeAlreadyLocked() throws ProcessInitException {
if (sInitialized) {
return;
}
+ // Setup the native command line if necessary.
+ if (!sCommandLineSwitched) {
+ nativeInitCommandLine(CommandLine.getJavaSwitchesOrNull());
+ }
+
if (!nativeLibraryLoaded()) {
Log.e(TAG, "error calling nativeLibraryLoaded");
throw new ProcessInitException(LoaderErrors.LOADER_ERROR_FAILED_TO_REGISTER_JNI);
@@ -250,6 +278,13 @@ public class LibraryLoader {
// following calls).
sInitialized = true;
+ // The Chrome JNI is registered by now so we can switch the Java
+ // command line over to delegating to native if it's necessary.
+ if (!sCommandLineSwitched) {
+ CommandLine.enableNativeProxy();
+ sCommandLineSwitched = true;
+ }
+
// From now on, keep tracing in sync with native.
TraceEvent.registerNativeEnabledObserver();
}
« no previous file with comments | « android_webview/javatests/src/org/chromium/android_webview/test/CommandLineTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698