| Index: base/android/java/src/org/chromium/base/library_loader/Linker.java
|
| diff --git a/base/android/java/src/org/chromium/base/library_loader/Linker.java b/base/android/java/src/org/chromium/base/library_loader/Linker.java
|
| index ac179cb59ff7d0ae03ece3025b48198b0b0755d9..cfe2c37faa2f4b708bd8c2993fe290ad11f5a245 100644
|
| --- a/base/android/java/src/org/chromium/base/library_loader/Linker.java
|
| +++ b/base/android/java/src/org/chromium/base/library_loader/Linker.java
|
| @@ -249,7 +249,7 @@ public abstract class Linker {
|
| *
|
| * @return true if native library linker tests are enabled.
|
| */
|
| - public static boolean areLinkerTestsEnabled() {
|
| + public static boolean areTestsEnabled() {
|
| return NativeLibraries.sEnableLinkerTests;
|
| }
|
|
|
| @@ -284,7 +284,7 @@ public abstract class Linker {
|
| *
|
| * @param type LINKER_IMPLEMENTATION_LEGACY or LINKER_IMPLEMENTATION_MODERN
|
| */
|
| - public static final void setLinkerImplementationForTesting(int type) {
|
| + public static final void setImplementationForTesting(int type) {
|
| // Sanity check. This method may only be called during tests.
|
| assertLinkerTestsAreEnabled();
|
| assertForTesting(type == LINKER_IMPLEMENTATION_LEGACY
|
| @@ -310,18 +310,21 @@ public abstract class Linker {
|
| *
|
| * @return LINKER_IMPLEMENTATION_LEGACY or LINKER_IMPLEMENTATION_MODERN
|
| */
|
| - public int getLinkerImplementationForTesting() {
|
| + public int getImplementationForTesting() {
|
| // Sanity check. This method may only be called during tests.
|
| assertLinkerTestsAreEnabled();
|
| - assertForTesting(sSingleton != null);
|
|
|
| - if (sSingleton instanceof ModernLinker) {
|
| - return LINKER_IMPLEMENTATION_MODERN;
|
| - } else if (sSingleton instanceof LegacyLinker) {
|
| - return LINKER_IMPLEMENTATION_LEGACY;
|
| + synchronized (sSingletonLock) {
|
| + assertForTesting(sSingleton != null);
|
| +
|
| + if (sSingleton instanceof ModernLinker) {
|
| + return LINKER_IMPLEMENTATION_MODERN;
|
| + } else if (sSingleton instanceof LegacyLinker) {
|
| + return LINKER_IMPLEMENTATION_LEGACY;
|
| + }
|
| + Log.e(TAG, "Invalid linker: " + sSingleton.getClass().getName());
|
| + return 0;
|
| }
|
| - Log.e(TAG, "Invalid linker: " + sSingleton.getClass().getName());
|
| - return 0;
|
| }
|
|
|
| /**
|
| @@ -350,7 +353,7 @@ public abstract class Linker {
|
| */
|
| public void setTestRunnerClassNameForTesting(String testRunnerClassName) {
|
| if (DEBUG) {
|
| - Log.i(TAG, "setTestRunnerByClassNameForTesting(" + testRunnerClassName + ") called");
|
| + Log.i(TAG, "setTestRunnerClassNameForTesting(" + testRunnerClassName + ") called");
|
| }
|
| // Sanity check. This method may only be called during tests.
|
| assertLinkerTestsAreEnabled();
|
| @@ -379,6 +382,42 @@ public abstract class Linker {
|
| }
|
|
|
| /**
|
| + * Set up the Linker for a test.
|
| + * Convenience function that calls setImplementationForTesting() to force an
|
| + * implementation, and then setTestRunnerClassNameForTesting() to set the test
|
| + * class name.
|
| + *
|
| + * On first call, instantiates a Linker of the requested type and sets its test
|
| + * runner class name. On subsequent calls, checks that the singleton produced by
|
| + * the first call matches the requested type and test runner class name.
|
| + */
|
| + public static void setupForTesting(int type, String testRunnerClassName) {
|
| + if (DEBUG) {
|
| + Log.i(TAG, "setupForTesting(" + type + ", " + testRunnerClassName + ") called");
|
| + }
|
| + // Sanity check. This method may only be called during tests.
|
| + assertLinkerTestsAreEnabled();
|
| +
|
| + synchronized (sSingletonLock) {
|
| + // If this is the first call, configure the Linker to the given type and test class.
|
| + if (sSingleton == null) {
|
| + setImplementationForTesting(type);
|
| + sSingleton.setTestRunnerClassNameForTesting(testRunnerClassName);
|
| + return;
|
| + }
|
| +
|
| + // If not the first call, check that the Linker configuration matches this request.
|
| + assertForTesting(sSingleton.getImplementationForTesting() == type);
|
| + String ourTestRunnerClassName = sSingleton.getTestRunnerClassNameForTesting();
|
| + if (testRunnerClassName == null) {
|
| + assertForTesting(ourTestRunnerClassName == null);
|
| + } else {
|
| + assertForTesting(ourTestRunnerClassName.equals(testRunnerClassName));
|
| + }
|
| + }
|
| + }
|
| +
|
| + /**
|
| * Instantiate and run the current TestRunner, if any. The TestRunner implementation
|
| * must be instantiated _after_ all libraries are loaded to ensure that its
|
| * native methods are properly registered.
|
| @@ -464,7 +503,7 @@ public abstract class Linker {
|
| * In a component build, the suffix ".cr" is added to each library name, so
|
| * if the initial load fails we retry with a suffix.
|
| */
|
| - protected void loadLinkerJNILibrary() {
|
| + protected static void loadLinkerJniLibrary() {
|
| String libName = "lib" + LINKER_JNI_LIBRARY + ".so";
|
| if (DEBUG) {
|
| Log.i(TAG, "Loading " + libName);
|
| @@ -546,7 +585,7 @@ public abstract class Linker {
|
| * Call this method to determine if the chromium project must load the library
|
| * directly from a zip file.
|
| */
|
| - public boolean isInZipFile() {
|
| + public static boolean isInZipFile() {
|
| // The auto-generated NativeLibraries.sUseLibraryInZipFile variable will be true
|
| // if the library remains embedded in the APK zip file on the target.
|
| return NativeLibraries.sUseLibraryInZipFile;
|
| @@ -557,7 +596,11 @@ public abstract class Linker {
|
| * use this linker. If not, System.loadLibrary() should be used to load
|
| * libraries instead.
|
| */
|
| - public abstract boolean isUsed();
|
| + public static boolean isUsed() {
|
| + // The auto-generated NativeLibraries.sUseLinker variable will be true if the
|
| + // build has not explicitly disabled Linker features.
|
| + return NativeLibraries.sUseLinker;
|
| + }
|
|
|
| /**
|
| * Call this method to determine if the linker will try to use shared RELROs
|
|
|