Chromium Code Reviews| 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 9dc77fc8c006cfdb5c1c5c9d40327833f75f7cd2..c9a3b085a3af3170e10a435b600de0854709890a 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 |
| @@ -4,6 +4,7 @@ |
| package org.chromium.base.library_loader; |
| +import android.content.Context; |
| import android.os.SystemClock; |
| import android.util.Log; |
| @@ -41,6 +42,11 @@ public class LibraryLoader { |
| // library_loader_hooks.cc). |
| private static boolean sInitialized = false; |
| + // One-way switch becomes true if the system library loading failed, |
| + // and the right native library was found and loaded by the hack. |
| + // The flag is used to report UMA stats later. |
| + public static boolean sNativeLibraryHack = false; |
| + |
| // TODO(cjhopman): Remove this once it's unused. |
| /** |
| * Doesn't do anything. |
| @@ -52,13 +58,14 @@ public class LibraryLoader { |
| /** |
| * This method blocks until the library is fully loaded and initialized. |
| */ |
| - public static void ensureInitialized() throws ProcessInitException { |
| + public static void ensureInitialized(Context context, boolean isBrowserProcess) |
|
klobag.chromium
2014/03/19 17:23:46
can we change the name of isBrowserProcess? As in
Feng Qian
2014/03/19 17:52:51
Per discussion, rename to 'shouldApplyNativeLibrar
|
| + throws ProcessInitException { |
| synchronized (sLock) { |
| if (sInitialized) { |
| // Already initialized, nothing to do. |
| return; |
| } |
| - loadAlreadyLocked(); |
| + loadAlreadyLocked(context, isBrowserProcess); |
| initializeAlreadyLocked(CommandLine.getJavaSwitchesOrNull()); |
| } |
| } |
| @@ -81,9 +88,10 @@ public class LibraryLoader { |
| * |
| * @throws ProcessInitException if the native library failed to load. |
| */ |
| - public static void loadNow() throws ProcessInitException { |
| + public static void loadNow(Context context, boolean isBrowserProcess) |
| + throws ProcessInitException { |
| synchronized (sLock) { |
| - loadAlreadyLocked(); |
| + loadAlreadyLocked(context, isBrowserProcess); |
| } |
| } |
| @@ -103,7 +111,8 @@ public class LibraryLoader { |
| // Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code |
| - private static void loadAlreadyLocked() throws ProcessInitException { |
| + private static void loadAlreadyLocked(Context context, boolean isBrowserProcess) |
| + throws ProcessInitException { |
| try { |
| if (!sLoaded) { |
| assert !sInitialized; |
| @@ -118,8 +127,22 @@ public class LibraryLoader { |
| Log.i(TAG, "Loading: " + library); |
| if (useChromiumLinker) |
| Linker.loadLibrary(library); |
| - else |
| - System.loadLibrary(library); |
| + else { |
| + try { |
| + System.loadLibrary(library); |
| + if (isBrowserProcess) { |
| + LibraryLoaderHelper.deleteWorkaroundLibraries(context); |
| + } |
| + } catch (UnsatisfiedLinkError e) { |
| + // Try to load from backup directory. |
| + if (LibraryLoaderHelper.tryLoadLibraryUsingWorkaround( |
| + context, library, isBrowserProcess)) { |
| + sNativeLibraryHack = true; |
| + } else { |
| + throw e; |
| + } |
| + } |
| + } |
| } |
| if (useChromiumLinker) |
| Linker.finishLibraryLoad(); |
| @@ -142,10 +165,8 @@ public class LibraryLoader { |
| if (!NativeLibraries.VERSION_NUMBER.equals(nativeGetVersionNumber())) { |
| throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_WRONG_VERSION); |
| } |
| - |
| } |
| - |
| // Invoke base::android::LibraryLoaded in library_loader_hooks.cc |
| private static void initializeAlreadyLocked(String[] initCommandLine) |
| throws ProcessInitException { |