diff options
60 files changed, 685 insertions, 487 deletions
diff --git a/android_webview/java/generated_src/org/chromium/content/app/NativeLibraries.java b/android_webview/java/generated_src/org/chromium/base/library_loader/NativeLibraries.java index c01bea5..2bb1460 100644 --- a/android_webview/java/generated_src/org/chromium/content/app/NativeLibraries.java +++ b/android_webview/java/generated_src/org/chromium/base/library_loader/NativeLibraries.java @@ -1,15 +1,18 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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; +package org.chromium.base.library_loader; +/** + * This class defines the native libraries and loader options required by webview + */ public class NativeLibraries { - // Set to true to use the content linker. Only useful to save memory + // Set to true to use the chromium linker. Only useful to save memory // on multi-process content-based projects. Always disabled for the Android Webview. public static boolean USE_LINKER = false; - // Set to true to enable content linker test support. NEVER enable this for the + // Set to true to enable chromium linker test support. NEVER enable this for the // Android webview. public static boolean ENABLE_LINKER_TESTS = false; diff --git a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java index 16e7348..6f6404a 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java +++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java @@ -8,9 +8,9 @@ import android.content.Context; import org.chromium.base.PathUtils; import org.chromium.base.ThreadUtils; -import org.chromium.content.app.LibraryLoader; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.browser.BrowserStartupController; -import org.chromium.content.common.ProcessInitException; /** * Wrapper for the steps needed to initialize the java and native sides of webview chromium. diff --git a/android_webview/lib/main/webview_entry_point.cc b/android_webview/lib/main/webview_entry_point.cc index 7038416..1eefd52 100644 --- a/android_webview/lib/main/webview_entry_point.cc +++ b/android_webview/lib/main/webview_entry_point.cc @@ -6,6 +6,7 @@ #include "android_webview/native/android_webview_jni_registrar.h" #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" +#include "base/android/library_loader/library_loader_hooks.h" #include "components/navigation_interception/component_jni_registrar.h" #include "components/web_contents_delegate_android/component_jni_registrar.h" #include "content/public/app/android_library_loader_hooks.h" @@ -23,9 +24,12 @@ static base::android::RegistrationMethod // This is called by the VM when the shared library is first loaded. // Most of the initialization is done in LibraryLoadedOnMainThread(), not here. JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + + base::android::SetLibraryLoadedHook(&content::LibraryLoaded); + base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!content::RegisterLibraryLoaderEntryHook(env)) + if (!base::android::RegisterLibraryLoaderEntryHook(env)) return -1; // Register content JNI functions now, rather than waiting until 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 new file mode 100644 index 0000000..59bba30 --- /dev/null +++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java @@ -0,0 +1,188 @@ +// Copyright 2014 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.base.library_loader; + +import android.util.Log; + +import org.chromium.base.CommandLine; +import org.chromium.base.JNINamespace; +import org.chromium.base.SysUtils; +import org.chromium.base.TraceEvent; + +/** + * 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 libraries may be loaded and initialized from any thread. Synchronization + * primitives are used to ensure that overlapping requests from different + * threads are handled sequentially. + * + * See also base/android/library_loader/library_loader_hooks.cc, which contains + * the native counterpart to this class. + */ +@JNINamespace("base::android") +public class LibraryLoader { + private static final String TAG = "LibraryLoader"; + + // Guards all access to the libraries + private static final Object sLock = new Object(); + + // One-way switch becomes true when the libraries are loaded. + private static boolean sLoaded = false; + + // 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. + /** + * Doesn't do anything. + */ + @Deprecated + public static void setLibraryToLoad(String library) { + } + + /** + * This method blocks until the library is fully loaded and initialized. + */ + public static void ensureInitialized() throws ProcessInitException { + synchronized (sLock) { + if (sInitialized) { + // Already initialized, nothing to do. + return; + } + loadAlreadyLocked(); + initializeAlreadyLocked(CommandLine.getJavaSwitchesOrNull()); + } + } + + /** + * Checks if library is fully loaded and initialized. + */ + public static boolean isInitialized() { + synchronized (sLock) { + return sInitialized; + } + } + + /** + * Loads the library and blocks until the load completes. The caller is responsible + * for subsequently calling ensureInitialized(). + * May be called on any thread, but should only be called once. Note the thread + * this is called on will be the thread that runs the native code's static initializers. + * See the comment in doInBackground() for more considerations on this. + * + * @throws ProcessInitException if the native library failed to load. + */ + public static void loadNow() throws ProcessInitException { + synchronized (sLock) { + loadAlreadyLocked(); + } + } + + + /** + * initializes the library here and now: must be called on the thread that the + * native will call its "main" thread. The library must have previously been + * loaded with loadNow. + * @param initCommandLine The command line arguments that native command line will + * be initialized with. + */ + public static void initialize(String[] initCommandLine) throws ProcessInitException { + synchronized (sLock) { + initializeAlreadyLocked(initCommandLine); + } + } + + + // Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code + private static void loadAlreadyLocked() throws ProcessInitException { + try { + if (!sLoaded) { + assert !sInitialized; + + long startTime = System.currentTimeMillis(); + boolean useChromiumLinker = Linker.isUsed(); + + if (useChromiumLinker) + Linker.prepareLibraryLoad(); + + for (String library : NativeLibraries.LIBRARIES) { + Log.i(TAG, "Loading: " + library); + if (useChromiumLinker) + Linker.loadLibrary(library); + else + System.loadLibrary(library); + } + if (useChromiumLinker) + Linker.finishLibraryLoad(); + long stopTime = System.currentTimeMillis(); + Log.i(TAG, String.format("Time to load native libraries: %d ms (timestamps %d-%d)", + stopTime - startTime, + startTime % 10000, + stopTime % 10000)); + sLoaded = true; + } + } catch (UnsatisfiedLinkError e) { + throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_LOAD_FAILED, e); + } + // Check that the version of the library we have loaded matches the version we expect + Log.i(TAG, String.format( + "Expected native library version number \"%s\"," + + "actual native library version number \"%s\"", + NativeLibraries.VERSION_NUMBER, + nativeGetVersionNumber())); + 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 { + if (sInitialized) { + return; + } + if (!nativeLibraryLoaded(initCommandLine)) { + Log.e(TAG, "error calling nativeLibraryLoaded"); + throw new ProcessInitException(LoaderErrors.LOADER_ERROR_FAILED_TO_REGISTER_JNI); + } + // From this point on, native code is ready to use and checkIsReady() + // shouldn't complain from now on (and in fact, it's used by the + // following calls). + sInitialized = true; + CommandLine.enableNativeProxy(); + TraceEvent.setEnabledToMatchNative(); + // Record histogram for the Chromium linker. + if (Linker.isUsed()) + nativeRecordChromiumAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(), + SysUtils.isLowEndDevice()); + } + + // 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); + + // Method called to record statistics about the Chromium linker operation, + // i.e. whether the library failed to be loaded at a fixed address, and + // whether the device is 'low-memory'. + private static native void nativeRecordChromiumAndroidLinkerHistogram( + boolean loadedAtFixedAddressFailed, + boolean isLowMemoryDevice); + + // Get the version of the native library. This is needed so that we can check we + // have the right version before initializing the (rest of the) JNI. + private static native String nativeGetVersionNumber(); +} diff --git a/content/public/android/java/src/org/chromium/content/app/Linker.java b/base/android/java/src/org/chromium/base/library_loader/Linker.java index 417d261..51bc0e5 100644 --- a/content/public/android/java/src/org/chromium/content/app/Linker.java +++ b/base/android/java/src/org/chromium/base/library_loader/Linker.java @@ -1,8 +1,8 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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; +package org.chromium.base.library_loader; import android.os.Bundle; import android.os.Parcel; @@ -104,7 +104,7 @@ import java.util.Map; * - A service process shall call either initServiceProcess() or * disableSharedRelros() early (i.e. before any loadLibrary() call). * Otherwise, the linker considers that it is running inside the browser - * process. This is because various content-based projects have vastly + * process. This is because various Chromium projects have vastly * different initialization paths. * * disableSharedRelros() completely disables shared RELROs, and loadLibrary() @@ -115,7 +115,7 @@ import java.util.Map; * * - The browser is in charge of deciding where in memory each library should * be loaded. This address must be passed to each service process (see - * LinkerParams.java for a helper class to do so). + * ChromiumLinkerParams.java in content for a helper class to do so). * * - The browser will also generate shared RELROs for each library it loads. * More specifically, by default when in the browser process, the linker @@ -151,7 +151,7 @@ import java.util.Map; public class Linker { // Log tag for this class. This must match the name of the linker's native library. - private static final String TAG = "content_android_linker"; + private static final String TAG = "chromium_android_linker"; // Set to true to enable debug logs. private static final boolean DEBUG = false; @@ -350,12 +350,12 @@ public class Linker { } /** - * Call this method to determine if this content-based project must + * Call this method to determine if this chromium project must * use this linker. If not, System.loadLibrary() should be used to load * libraries instead. */ public static boolean isUsed() { - // Only GYP targets that are APKs and have the 'use_content_linker' variable + // Only GYP targets that are APKs and have the 'use_chromium_linker' variable // defined as 1 will use this linker. For all others (the default), the // auto-generated NativeLibraries.USE_LINKER variable will be false. if (!NativeLibraries.USE_LINKER) @@ -904,7 +904,7 @@ public class Linker { try { ParcelFileDescriptor.adoptFd(mRelroFd).close(); } catch (java.io.IOException e) { - if (DEBUG) Log.e(TAG, "Failed to close fd: " + mRelroFd); + if (DEBUG) Log.e(TAG, "Failed to close fd: " + mRelroFd); } mRelroFd = -1; } @@ -1009,5 +1009,5 @@ public class Linker { // Used to pass the shared RELRO Bundle through Binder. public static final String EXTRA_LINKER_SHARED_RELROS = - "org.chromium.content.common.linker.shared_relros"; + "org.chromium.base.android.linker.shared_relros"; } diff --git a/base/android/java/src/org/chromium/base/library_loader/LoaderErrors.java b/base/android/java/src/org/chromium/base/library_loader/LoaderErrors.java new file mode 100644 index 0000000..3133953 --- /dev/null +++ b/base/android/java/src/org/chromium/base/library_loader/LoaderErrors.java @@ -0,0 +1,21 @@ +// Copyright 2014 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.base.library_loader; + +/** + * These are the possible failures from the LibraryLoader + */ +public class LoaderErrors { + // TODO(aberent) These were originally in content/common/result_codes_list.h + // although they are never used on the c++ side, or in places where they + // could be confused with other result codes. A copy must remain there, and the + // values must be identical, until the downstream patch to use this new class + // lands. + public static final int LOADER_ERROR_NORMAL_COMPLETION = 0; + public static final int LOADER_ERROR_FAILED_TO_REGISTER_JNI = 4; + public static final int LOADER_ERROR_NATIVE_LIBRARY_LOAD_FAILED = 5; + public static final int LOADER_ERROR_NATIVE_LIBRARY_WRONG_VERSION = 6; + public static final int LOADER_ERROR_NATIVE_STARTUP_FAILED = 7; +} diff --git a/base/android/java/src/org/chromium/base/library_loader/ProcessInitException.java b/base/android/java/src/org/chromium/base/library_loader/ProcessInitException.java new file mode 100644 index 0000000..d7f82fb --- /dev/null +++ b/base/android/java/src/org/chromium/base/library_loader/ProcessInitException.java @@ -0,0 +1,28 @@ +// Copyright 2014 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.base.library_loader; + +/** + * The exception that is thrown when the intialization of a process was failed. + * TODO (aberent) the real code of this has to stay in + * org.chromium.content.common.ProcessInitException until the downstream Android + * code has switched to using this class. + */ +public class ProcessInitException extends org.chromium.content.common.ProcessInitException { + /** + * @param errorCode This will be one of the LoaderErrors error codes. + */ + public ProcessInitException(int errorCode) { + super(errorCode); + } + + /** + * @param errorCode This will be one of the LoaderErrors error codes. + * @param throwable The wrapped throwable obj. + */ + public ProcessInitException(int errorCode, Throwable throwable) { + super(errorCode, throwable); + } +} diff --git a/content/public/android/java/src/org/chromium/content/common/ProcessInitException.java b/base/android/java/src/org/chromium/content/common/ProcessInitException.java index 0ebbb17..33c7a30 100644 --- a/content/public/android/java/src/org/chromium/content/common/ProcessInitException.java +++ b/base/android/java/src/org/chromium/content/common/ProcessInitException.java @@ -1,26 +1,30 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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.common; +import org.chromium.base.library_loader.LoaderErrors; + /** * The exception that is thrown when the intialization of a process was failed. + * TODO(aberent) Remove this once the downstream patch lands, and move this code to base. + * In advance of its deletion this has been moved into the base directory structure, to + * allow org.chromium.base.library_loader.ProcessInitException to derive from it. This + * will go away as soon as the downstream patch lands. */ public class ProcessInitException extends Exception { - private int mErrorCode = 0; + private int mErrorCode = LoaderErrors.LOADER_ERROR_NORMAL_COMPLETION; /** - * @param errorCode The error code could be one from content/public/common/result_codes.h - * or embedder. + * @param errorCode This will be one of the LoaderErrors error codes. */ public ProcessInitException(int errorCode) { mErrorCode = errorCode; } /** - * @param errorCode The error code could be one from content/public/common/result_codes.h - * or embedder. + * @param errorCode This will be one of the LoaderErrors error codes. * @param throwable The wrapped throwable obj. */ public ProcessInitException(int errorCode, Throwable throwable) { diff --git a/content/public/android/java/templates/NativeLibraries.template b/base/android/java/templates/NativeLibraries.template index dd710cd..da375c6 100644 --- a/content/public/android/java/templates/NativeLibraries.template +++ b/base/android/java/templates/NativeLibraries.template @@ -1,8 +1,8 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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; +package org.chromium.base.library_loader; public class NativeLibraries { /** @@ -13,16 +13,16 @@ public class NativeLibraries { * - This template is used to generate several distinct, but similar * files used in different contexts: * - * o .../gen/templates/org/chromium/content/app/NativeLibraries.java + * o .../gen/templates/org/chromium/base/library_loader/NativeLibraries.java * - * This file is used to build content.jar, which is the library - * jar used by several content-based projects. However, the + * This file is used to build base.jar, which is the library + * jar used by chromium projects. However, the * corresponding NativeLibraries.class file will _not_ be part - * of the final content.jar. + * of the final base.jar. * * o .../$PROJECT/native_libraries_java/NativeLibraries.java * - * This file is used to build a content-based APK (e.g. $PROJECT + * This file is used to build an APK (e.g. $PROJECT * could be 'content_shell_apk'). Its content will depend on * this target's specific build configuration, and differ from * the source file above. @@ -32,29 +32,30 @@ public class NativeLibraries { * will be put into the final output file, and used at runtime. * * - If the variables were defined as 'final', their value would be - * optimized out inside of 'content.jar', and could not be specialized - * for every content-based program. + * optimized out inside of 'base.jar', and could not be specialized + * for every chromium program. This, however, doesn't apply to arrays of + * strings, which can be defined as final. * * This exotic scheme is used to avoid injecting project-specific, or - * even build-specific, values into the content layer. E.g. this is + * even build-specific, values into the base layer. E.g. this is * how the component build is supported on Android without modifying * the sources of each and every Chromium-based target. */ - // Set to true to enable the use of the content Linker. -#if defined(ENABLE_CONTENT_LINKER) + // Set to true to enable the use of the Chromium Linker. +#if defined(ENABLE_CHROMIUM_LINKER) public static boolean USE_LINKER = true; #else public static boolean USE_LINKER = false; #endif -#if defined(ENABLE_CONTENT_LINKER_TESTS) +#if defined(ENABLE_CHROMIUM_LINKER_TESTS) public static boolean ENABLE_LINKER_TESTS = true; #else public static boolean ENABLE_LINKER_TESTS = false; #endif // 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 + // by LibraryLoader.java. The base 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). @@ -64,11 +65,8 @@ public class NativeLibraries { #include <native_libraries_array.h> ; // This is the expected version of the 'main' native library, which is the one that - // implements the initial set of content JNI functions including - // content::nativeGetVersionName() - // Note(aberent): This is logically final, but making it final breaks the build, since it - // lets other Java components read its value at compile time rather than at run time, hence - // reading it from the wrong class file. + // implements the initial set of base JNI functions including + // base::android::nativeGetVersionName() static String VERSION_NUMBER #include <native_libraries_version.h> ; diff --git a/content/public/android/java/templates/native_libraries_array.h b/base/android/java/templates/native_libraries_array.h index 19d14f9..41aeb79 100644 --- a/content/public/android/java/templates/native_libraries_array.h +++ b/base/android/java/templates/native_libraries_array.h @@ -1,8 +1,8 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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 +// This is a placeholder for compiling base_java. The base 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/public/android/java/templates/native_libraries_version.h b/base/android/java/templates/native_libraries_version.h index a461784..48cd1f4 100644 --- a/content/public/android/java/templates/native_libraries_version.h +++ b/base/android/java/templates/native_libraries_version.h @@ -1,8 +1,8 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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 +// This is a placeholder for compiling base_java. The base java library // is compiled with no native_library version defined, and then the build system // creates a version of the file with the real native_library_version (which // changes based upon which .apk is being built). diff --git a/base/android/library_loader/library_loader_hooks.cc b/base/android/library_loader/library_loader_hooks.cc new file mode 100644 index 0000000..8fa16df --- /dev/null +++ b/base/android/library_loader/library_loader_hooks.cc @@ -0,0 +1,68 @@ +// Copyright 2014 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. + +#include "base/android/library_loader/library_loader_hooks.h" + +#include "base/at_exit.h" +#include "base/metrics/histogram.h" +#include "jni/LibraryLoader_jni.h" + +namespace base { +namespace android { + +namespace { + +base::AtExitManager* g_at_exit_manager = NULL; +const char* g_library_version_number = ""; +LibraryLoadedHook* g_registration_callback = NULL; + +} // namespace + +void SetLibraryLoadedHook(LibraryLoadedHook* func) { + g_registration_callback = func; +} + +static jboolean LibraryLoaded(JNIEnv* env, jclass clazz, + jobjectArray init_command_line) { + if(g_registration_callback == NULL) { + return true; + } + return g_registration_callback(env, clazz, init_command_line); +} + +static void RecordChromiumAndroidLinkerHistogram( + JNIEnv* env, + jclass clazz, + jboolean loaded_at_fixed_address_failed, + jboolean is_low_memory_device) { + UMA_HISTOGRAM_BOOLEAN("ChromiumAndroidLinker.LoadedAtFixedAddressFailed", + loaded_at_fixed_address_failed); + UMA_HISTOGRAM_BOOLEAN("ChromiumAndroidLinker.IsLowMemoryDevice", + is_low_memory_device); +} + +void LibraryLoaderExitHook() { + if (g_at_exit_manager) { + delete g_at_exit_manager; + g_at_exit_manager = NULL; + } +} + +bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { + // We need the AtExitManager to be created at the very beginning. + g_at_exit_manager = new base::AtExitManager(); + + return RegisterNativesImpl(env); +} + +void SetVersionNumber(const char* version_number) { + g_library_version_number = strdup(version_number); +} + +jstring GetVersionNumber(JNIEnv* env, jclass clazz) { + return env->NewStringUTF(g_library_version_number); +} + +} // namespace android +} // namespace base diff --git a/base/android/library_loader/library_loader_hooks.h b/base/android/library_loader/library_loader_hooks.h new file mode 100644 index 0000000..06709f6 --- /dev/null +++ b/base/android/library_loader/library_loader_hooks.h @@ -0,0 +1,51 @@ +// Copyright 2014 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. + +#ifndef BASE_ANDROID_LIBRARY_LOADER_HOOKS_H_ +#define BASE_ANDROID_LIBRARY_LOADER_HOOKS_H_ + +#include <jni.h> + +#include "base/base_export.h" + +namespace base { +namespace android { + +// Registers the callbacks that allows the entry point of the library to be +// exposed to the calling java code. This handles only registering the +// the callbacks needed by the loader. Any application specific JNI bindings +// should happen once the native library has fully loaded, either in the library +// loaded hook function or later. +BASE_EXPORT bool RegisterLibraryLoaderEntryHook(JNIEnv* env); + +// Typedef for hook function to be called (indirectly from Java) once the +// libraries are loaded. The hook function should register the JNI bindings +// required to start the application. It should return true for success and +// false for failure. +// Note: this can't use base::Callback because there is no way of initializing +// the default callback without using static objects, which we forbid. +typedef bool LibraryLoadedHook(JNIEnv* env, + jclass clazz, + jobjectArray init_command_line); + +// Set the hook function to be called (from Java) once the libraries are loaded. +// SetLibraryLoadedHook may only be called from JNI_OnLoad. The hook function +// should register the JNI bindings required to start the application. + +BASE_EXPORT void SetLibraryLoadedHook(LibraryLoadedHook* func); + +// Pass the version name to the loader. This used to check that the library +// version matches the version expected by Java before completing JNI +// registration. +// Note: argument must remain valid at least until library loading is complete. +BASE_EXPORT void SetVersionNumber(const char* version_number); + +// Call on exit to delete the AtExitManager which OnLibraryLoadedOnUIThread +// created. +BASE_EXPORT void LibraryLoaderExitHook(); + +} // namespace android +} // namespace base + +#endif // BASE_ANDROID_LIBRARY_LOADER_HOOKS_H_ diff --git a/base/android/linker/DEPS b/base/android/linker/DEPS new file mode 100644 index 0000000..15c3afb --- /dev/null +++ b/base/android/linker/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + # This code cannot depend on anything from base/ + "-base", +] diff --git a/content/common/android/linker/linker_jni.cc b/base/android/linker/linker_jni.cc index 7db9fea..0222e49 100644 --- a/content/common/android/linker/linker_jni.cc +++ b/base/android/linker/linker_jni.cc @@ -1,10 +1,10 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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 the Android-specific content linker, a tiny shared library +// This is the Android-specific Chromium linker, a tiny shared library // implementing a custom dynamic linker that can be used to load the -// real content-based libraries (e.g. libcontentshell.so). +// real Chromium libraries (e.g. libcontentshell.so). // The main point of this linker is to be able to share the RELRO // section of libcontentshell.so (or equivalent) between the browser and @@ -24,7 +24,7 @@ // in base/ which hasn't been loaded yet. #define DEBUG 0 -#define TAG "content_android_linker" +#define TAG "chromium_android_linker" #if DEBUG #define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) @@ -154,7 +154,7 @@ struct LibInfo_class { bool Init(JNIEnv* env) { jclass clazz; if (!InitClassReference( - env, "org/chromium/content/app/Linker$LibInfo", &clazz)) { + env, "org/chromium/base/library_loader/Linker$LibInfo", &clazz)) { return false; } @@ -221,7 +221,7 @@ crazy_context_t* GetCrazyContext() { return s_crazy_context; } -// Load a library with the content linker. This will also call its +// Load a library with the chromium linker. This will also call its // JNI_OnLoad() method, which shall register its methods. Note that // lazy native method resolution will _not_ work after this, because // Dalvik uses the system's dlsym() which won't see the new library, @@ -387,7 +387,7 @@ const JNINativeMethod kNativeMethods[] = { "(" "Ljava/lang/String;" "J" - "Lorg/chromium/content/app/Linker$LibInfo;" + "Lorg/chromium/base/library_loader/Linker$LibInfo;" ")" "Z", reinterpret_cast<void*>(&LoadLibrary)}, @@ -395,14 +395,14 @@ const JNINativeMethod kNativeMethods[] = { "(" "Ljava/lang/String;" "J" - "Lorg/chromium/content/app/Linker$LibInfo;" + "Lorg/chromium/base/library_loader/Linker$LibInfo;" ")" "Z", reinterpret_cast<void*>(&CreateSharedRelro)}, {"nativeUseSharedRelro", "(" "Ljava/lang/String;" - "Lorg/chromium/content/app/Linker$LibInfo;" + "Lorg/chromium/base/library_loader/Linker$LibInfo;" ")" "Z", reinterpret_cast<void*>(&UseSharedRelro)}, @@ -434,7 +434,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) { // Register native methods. jclass linker_class; if (!InitClassReference( - env, "org/chromium/content/app/Linker", &linker_class)) + env, "org/chromium/base/library_loader/Linker", &linker_class)) return -1; LOG_INFO("%s: Registering native methods", __FUNCTION__); diff --git a/base/base.gyp b/base/base.gyp index 9779333..4269485 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -1258,6 +1258,7 @@ 'android/java/src/org/chromium/base/ContentUriUtils.java', 'android/java/src/org/chromium/base/CpuFeatures.java', 'android/java/src/org/chromium/base/ImportantFileWriterAndroid.java', + 'android/java/src/org/chromium/base/library_loader/LibraryLoader.java', 'android/java/src/org/chromium/base/MemoryPressureListener.java', 'android/java/src/org/chromium/base/JavaHandlerThread.java', 'android/java/src/org/chromium/base/PathService.java', @@ -1287,14 +1288,31 @@ 'includes': [ '../build/jni_generator.gypi' ], }, { + 'target_name': 'base_native_libraries_gen', + 'type': 'none', + 'sources': [ + 'android/java/templates/NativeLibraries.template', + ], + 'variables': { + 'package_name': 'org/chromium/base/library_loader', + 'include_path': 'android/java/templates', + 'template_deps': [ + 'android/java/templates/native_libraries_array.h' + ], + }, + 'includes': [ '../build/android/java_cpp_template.gypi' ], + }, + { 'target_name': 'base_java', 'type': 'none', 'variables': { 'java_in_dir': '../base/android/java', + 'jar_excluded_classes': [ '*/NativeLibraries.class' ], }, 'dependencies': [ 'base_java_activity_state', 'base_java_memory_pressure_level_list', + 'base_native_libraries_gen', ], 'includes': [ '../build/java.gypi' ], 'conditions': [ @@ -1367,6 +1385,24 @@ }, 'includes': [ '../build/java.gypi' ], }, + { + 'target_name': 'chromium_android_linker', + 'type': 'shared_library', + 'conditions': [ + ['android_webview_build == 0', { + # Avoid breaking the webview build because it doesn't have + # <(android_ndk_root)/crazy_linker.gyp. Note that it never uses + # the linker anyway. + 'sources': [ + 'android/linker/linker_jni.cc', + ], + 'dependencies': [ + '<(android_ndk_root)/crazy_linker.gyp:crazy_linker', + ], + }], + ], + }, + ], }], ['OS == "win"', { diff --git a/base/base.gypi b/base/base.gypi index 29e8e46..8c025de 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -61,6 +61,10 @@ 'android/jni_registrar.h', 'android/jni_string.cc', 'android/jni_string.h', + 'android/library_loader/library_loader_hooks.cc', + 'android/library_loader/library_loader_hooks.h', + 'android/library_loader/results_codes.h', + 'android/library_loader/results_codes_list.h', 'android/memory_pressure_listener_android.cc', 'android/memory_pressure_listener_android.h', 'android/java_handler_thread.cc', diff --git a/build/all.gyp b/build/all.gyp index 893d13f..ee50dca 100644 --- a/build/all.gyp +++ b/build/all.gyp @@ -733,7 +733,7 @@ '../components/components_tests.gyp:components_unittests', '../content/content_shell_and_tests.gyp:content_browsertests', '../content/content_shell_and_tests.gyp:content_gl_tests', - '../content/content_shell_and_tests.gyp:content_linker_test_apk', + '../content/content_shell_and_tests.gyp:chromium_linker_test_apk', '../content/content_shell_and_tests.gyp:content_shell_test_apk', '../content/content_shell_and_tests.gyp:content_unittests', '../gpu/gpu.gyp:gl_tests', diff --git a/build/android/findbugs_filter/findbugs_exclude.xml b/build/android/findbugs_filter/findbugs_exclude.xml index f300db1..2dc7f53 100644 --- a/build/android/findbugs_filter/findbugs_exclude.xml +++ b/build/android/findbugs_filter/findbugs_exclude.xml @@ -19,7 +19,7 @@ In particular, ~ at the start of a string means it's a regex. </Match> <!-- Ignore bugs in NativeLibraries.java (the auto-generation confuses findbugs). --> <Match> - <Class name="~org\.chromium\.content\..*\.NativeLibraries.*?" /> + <Class name="~org\.chromium\.base\..*\.NativeLibraries.*?" /> </Match> <!-- Ignore bugs in CleanupReferenceTest.java (redundant null check) diff --git a/build/android/findbugs_filter/findbugs_known_bugs.txt b/build/android/findbugs_filter/findbugs_known_bugs.txt index 739790f..0aab535 100644 --- a/build/android/findbugs_filter/findbugs_known_bugs.txt +++ b/build/android/findbugs_filter/findbugs_known_bugs.txt @@ -1,3 +1,5 @@ +H B Nm: The class name org.chromium.base.library_loader.ProcessInitException shadows the simple name of the superclass org.chromium.content.common.ProcessInitException At ProcessInitException.java +H B Nm: The class name org.chromium.content.app.LibraryLoader shadows the simple name of the superclass org.chromium.base.library_loader.LibraryLoader At LibraryLoader.java H C EC: Using pointer equality to compare a JavaBridgeCoercionTest$CustomType with a JavaBridgeCoercionTest$CustomType2 in org.chromium.content.browser.JavaBridgeCoercionTest.testPassJavaObject() At JavaBridgeCoercionTest.java H P Bx: Boxing/unboxing to parse a primitive org.chromium.content.browser.ViewportTest.evaluateIntegerValue(String) At ViewportTest.java M B RV: Exceptional return value of java.io.File.delete() ignored in org.chromium.base.test.util.TestFileUtil.deleteFile(String) At TestFileUtil.java diff --git a/build/android/pylib/linker/test_case.py b/build/android/pylib/linker/test_case.py index febab92..7eed8287 100644 --- a/build/android/pylib/linker/test_case.py +++ b/build/android/pylib/linker/test_case.py @@ -29,7 +29,7 @@ To build and run the linker tests, do the following: - ninja -C out/Debug content_linker_test_apk + ninja -C out/Debug chromium_linker_test_apk build/android/test_runner.py linker """ @@ -47,13 +47,13 @@ from pylib.base import base_test_result ResultType = base_test_result.ResultType -_PACKAGE_NAME = 'org.chromium.content_linker_test_apk' -_ACTIVITY_NAME = '.ContentLinkerTestActivity' -_COMMAND_LINE_FILE = '/data/local/tmp/content-linker-test-command-line' +_PACKAGE_NAME = 'org.chromium.chromium_linker_test_apk' +_ACTIVITY_NAME = '.ChromiumLinkerTestActivity' +_COMMAND_LINE_FILE = '/data/local/tmp/chromium-linker-test-command-line' # Path to the Linker.java source file. _LINKER_JAVA_SOURCE_PATH = ( - 'content/public/android/java/src/org/chromium/content/app/Linker.java') + 'base/android/java/src/org/chromium/base/library_loader/Linker.java') # A regular expression used to extract the browser shared RELRO configuration # from the Java source file above. @@ -64,9 +64,9 @@ _RE_LINKER_BROWSER_CONFIG = re.compile( # Logcat filters used during each test. Only the 'chromium' one is really # needed, but the logs are added to the TestResult in case of error, and -# it is handy to have the 'content_android_linker' ones as well when +# it is handy to have the 'chromium_android_linker' ones as well when # troubleshooting. -_LOGCAT_FILTERS = [ '*:s', 'chromium:v', 'content_android_linker:v' ] +_LOGCAT_FILTERS = [ '*:s', 'chromium:v', 'chromium_android_linker:v' ] #_LOGCAT_FILTERS = [ '*:v' ] ## DEBUG # Regular expression used to match status lines in logcat. diff --git a/build/android/pylib/linker/test_runner.py b/build/android/pylib/linker/test_runner.py index b9eb0b4..c9b7dd9 100644 --- a/build/android/pylib/linker/test_runner.py +++ b/build/android/pylib/linker/test_runner.py @@ -17,7 +17,7 @@ from pylib.utils import apk_helper # Name of the Android package to install for this to work. -_PACKAGE_NAME = 'ContentLinkerTest' +_PACKAGE_NAME = 'ChromiumLinkerTest' class LinkerExceptionTestResult(base_test_result.BaseTestResult): diff --git a/build/android/test_runner.py b/build/android/test_runner.py index 30e23b6..a8a3969 100755 --- a/build/android/test_runner.py +++ b/build/android/test_runner.py @@ -538,7 +538,7 @@ def _RunLinkerTests(options, devices): report_results.LogFull( results=results, test_type='Linker test', - test_package='ContentLinkerTest') + test_package='ChromiumLinkerTest') return exit_code diff --git a/build/android/tests/multiple_proguards/src/dummy/NativeLibraries.java b/build/android/tests/multiple_proguards/src/dummy/NativeLibraries.java new file mode 100644 index 0000000..edf71d7 --- /dev/null +++ b/build/android/tests/multiple_proguards/src/dummy/NativeLibraries.java @@ -0,0 +1,16 @@ +// Copyright 2014 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.base.library_loader; + +/** + * This is a complete dummy, required because base now requires a version of + * NativeLibraries to build, but doesn't include it in its jar file. + */ +public class NativeLibraries { + public static boolean USE_LINKER = false; + public static boolean ENABLE_LINKER_TESTS = false; + static final String[] LIBRARIES = {}; + static String VERSION_NUMBER = ""; +} diff --git a/build/java_apk.gypi b/build/java_apk.gypi index 036d569..499e29b 100644 --- a/build/java_apk.gypi +++ b/build/java_apk.gypi @@ -48,11 +48,11 @@ # strings.xml files, if any. # library_manifest_paths'- Paths to additional AndroidManifest.xml files from # libraries. -# use_content_linker - Enable the content dynamic linker that allows sharing the +# use_chromium_linker - Enable the content dynamic linker that allows sharing the # RELRO section of the native libraries between the different processes. -# enable_content_linker_tests - Enable the content dynamic linker test support +# enable_chromium_linker_tests - Enable the content dynamic linker test support # code. This allows a test APK to inject a Linker.TestRunner instance at -# runtime. Should only be used by the content_linker_test_apk target!! +# runtime. Should only be used by the chromium_linker_test_apk target!! # never_lint - Set to 1 to not run lint on this target. { 'variables': { @@ -81,10 +81,7 @@ 'compile_input_paths': [], 'package_input_paths': [], 'ordered_libraries_file': '<(intermediate_dir)/native_libraries.json', - # TODO(cjhopman): build/ shouldn't refer to content/. The libraryloader and - # nativelibraries template should be moved out of content/ (to base/?). - # http://crbug.com/225101 - 'native_libraries_template': '<(DEPTH)/content/public/android/java/templates/NativeLibraries.template', + 'native_libraries_template': '<(DEPTH)/base/android/java/templates/NativeLibraries.template', 'native_libraries_java_dir': '<(intermediate_dir)/native_libraries_java/', 'native_libraries_java_file': '<(native_libraries_java_dir)/NativeLibraries.java', 'native_libraries_java_stamp': '<(intermediate_dir)/native_libraries_java.stamp', @@ -126,8 +123,11 @@ 'variables': { 'native_lib_target%': '', 'native_lib_version_name%': '', + # TODO (aberent) remove use_content_linker once downstream Android has + # been switched to use_chromium_linker. 'use_content_linker%': 0, - 'enable_content_linker_tests%': 0, + 'use_chromium_linker%' : 0, + 'enable_chromium_linker_tests%': 0, 'is_test_apk%': 0, }, 'conditions': [ @@ -151,7 +151,8 @@ 'native_lib_target%': '', 'native_lib_version_name%': '', 'use_content_linker%': 0, - 'enable_content_linker_tests%': 0, + 'use_chromium_linker%' : 0, + 'enable_chromium_linker_tests%': 0, 'emma_instrument': '<(emma_instrument)', 'apk_package_native_libs_dir': '<(apk_package_native_libs_dir)', 'unsigned_standalone_apk_path': '<(unsigned_standalone_apk_path)', @@ -185,9 +186,9 @@ '<(DEPTH)/build/android/setup.gyp:copy_system_libraries', ], }], - ['use_content_linker == 1', { + ['use_content_linker == 1 or use_chromium_linker == 1', { 'dependencies': [ - '<(DEPTH)/content/content.gyp:content_android_linker', + '<(DEPTH)/base/base.gyp:chromium_android_linker', ], }], ['native_lib_target != ""', { @@ -217,10 +218,10 @@ { 'variables': { 'conditions': [ - ['use_content_linker == 1', { + ['use_content_linker == 1 or use_chromium_linker == 1', { 'variables': { 'linker_input_libraries': [ - '<(SHARED_LIB_DIR)/libcontent_android_linker.>(android_product_extension)', + '<(SHARED_LIB_DIR)/libchromium_android_linker.>(android_product_extension)', ], } }, { @@ -261,10 +262,10 @@ 'action_name': 'native_libraries_<(_target_name)', 'variables': { 'conditions': [ - ['use_content_linker == 1', { + ['use_content_linker == 1 or use_chromium_linker == 1', { 'variables': { 'linker_gcc_preprocess_defines': [ - '--defines', 'ENABLE_CONTENT_LINKER', + '--defines', 'ENABLE_CHROMIUM_LINKER', ], } }, { @@ -272,10 +273,10 @@ 'linker_gcc_preprocess_defines': [], }, }], - ['enable_content_linker_tests == 1', { + ['enable_chromium_linker_tests == 1', { 'variables': { 'linker_tests_gcc_preprocess_defines': [ - '--defines', 'ENABLE_CONTENT_LINKER_TESTS', + '--defines', 'ENABLE_CHROMIUM_LINKER_TESTS', ], } }, { diff --git a/chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java index 8201472..2c7510e 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/ChromiumSyncAdapter.java @@ -18,8 +18,8 @@ import com.google.common.annotations.VisibleForTesting; import com.google.protos.ipc.invalidation.Types; import org.chromium.base.ThreadUtils; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.browser.BrowserStartupController; -import org.chromium.content.common.ProcessInitException; import java.util.concurrent.Semaphore; diff --git a/chrome/android/testshell/java/src/org/chromium/chrome/testshell/ChromiumTestShellActivity.java b/chrome/android/testshell/java/src/org/chromium/chrome/testshell/ChromiumTestShellActivity.java index 8dc2ca9..69ab9e6 100644 --- a/chrome/android/testshell/java/src/org/chromium/chrome/testshell/ChromiumTestShellActivity.java +++ b/chrome/android/testshell/java/src/org/chromium/chrome/testshell/ChromiumTestShellActivity.java @@ -21,6 +21,7 @@ import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.BaseSwitches; import org.chromium.base.CommandLine; import org.chromium.base.MemoryPressureListener; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.chrome.browser.DevToolsServer; import org.chromium.chrome.browser.appmenu.AppMenuHandler; import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; @@ -31,7 +32,6 @@ import org.chromium.content.browser.ActivityContentVideoViewClient; import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.ContentView; import org.chromium.content.browser.DeviceUtils; -import org.chromium.content.common.ProcessInitException; import org.chromium.printing.PrintingController; import org.chromium.sync.signin.ChromeSigninController; import org.chromium.ui.base.ActivityWindowAndroid; diff --git a/chrome/android/testshell/java/src/org/chromium/chrome/testshell/signin/AccountsChangedReceiver.java b/chrome/android/testshell/java/src/org/chromium/chrome/testshell/signin/AccountsChangedReceiver.java index 34f810a..3d1db3f 100644 --- a/chrome/android/testshell/java/src/org/chromium/chrome/testshell/signin/AccountsChangedReceiver.java +++ b/chrome/android/testshell/java/src/org/chromium/chrome/testshell/signin/AccountsChangedReceiver.java @@ -12,10 +12,10 @@ import android.content.Intent; import android.util.Log; import org.chromium.base.ThreadUtils; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.signin.OAuth2TokenService; import org.chromium.content.browser.BrowserStartupController; -import org.chromium.content.common.ProcessInitException; import org.chromium.sync.signin.ChromeSigninController; /** diff --git a/chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java b/chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java index 6b1785f..e481db2 100644 --- a/chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java +++ b/chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java @@ -16,11 +16,11 @@ import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; import org.chromium.base.CommandLine; import org.chromium.base.ThreadUtils; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.chrome.test.util.ApplicationData; import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; -import org.chromium.content.common.ProcessInitException; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/chrome/app/android/chrome_android_initializer.cc b/chrome/app/android/chrome_android_initializer.cc index de84812..57dcb5e 100644 --- a/chrome/app/android/chrome_android_initializer.cc +++ b/chrome/app/android/chrome_android_initializer.cc @@ -5,6 +5,7 @@ #include "chrome/app/android/chrome_android_initializer.h" #include "base/android/jni_android.h" +#include "base/android/library_loader/library_loader_hooks.h" #include "base/logging.h" #include "chrome/app/android/chrome_main_delegate_android.h" #include "chrome/common/chrome_version_info.h" @@ -15,13 +16,14 @@ jint RunChrome(JavaVM* vm, ChromeMainDelegateAndroid* main_delegate) { base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!content::RegisterLibraryLoaderEntryHook(env)) + if (!base::android::RegisterLibraryLoaderEntryHook(env)) return -1; // Pass the library version number to content so that we can check it from the // Java side before continuing initialization chrome::VersionInfo vi; - content::SetVersionNumber(vi.Version().c_str()); + base::android::SetLibraryLoadedHook(&content::LibraryLoaded); + base::android::SetVersionNumber(vi.Version().c_str()); DCHECK(main_delegate); content::SetContentMainDelegate(main_delegate); diff --git a/content/app/android/child_process_service.cc b/content/app/android/child_process_service.cc index 308246e..dae54e5 100644 --- a/content/app/android/child_process_service.cc +++ b/content/app/android/child_process_service.cc @@ -8,6 +8,7 @@ #include <cpu-features.h> #include "base/android/jni_array.h" +#include "base/android/library_loader/library_loader_hooks.h" #include "base/android/memory_pressure_listener_android.h" #include "base/logging.h" #include "base/posix/global_descriptors.h" @@ -127,7 +128,7 @@ void InitChildProcess(JNIEnv* env, void ExitChildProcess(JNIEnv* env, jclass clazz) { VLOG(0) << "ChildProcessService: Exiting child process."; - LibraryLoaderExitHook(); + base::android::LibraryLoaderExitHook(); _exit(0); } diff --git a/content/app/android/library_loader_hooks.cc b/content/app/android/library_loader_hooks.cc index 275a5d7..868017c 100644 --- a/content/app/android/library_loader_hooks.cc +++ b/content/app/android/library_loader_hooks.cc @@ -9,13 +9,11 @@ #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" #include "base/android/jni_string.h" -#include "base/at_exit.h" #include "base/base_switches.h" #include "base/command_line.h" #include "base/debug/trace_event.h" #include "base/files/file_path.h" #include "base/logging.h" -#include "base/metrics/histogram.h" #include "base/strings/string_util.h" #include "base/tracked_objects.h" #include "content/app/android/app_jni_registrar.h" @@ -25,7 +23,6 @@ #include "content/common/content_constants_internal.h" #include "content/public/common/content_switches.h" #include "content/public/common/result_codes.h" -#include "jni/LibraryLoader_jni.h" #include "media/base/android/media_jni_registrar.h" #include "net/android/net_jni_registrar.h" #include "ui/base/android/ui_base_jni_registrar.h" @@ -35,11 +32,6 @@ namespace content { -namespace { -base::AtExitManager* g_at_exit_manager = NULL; -const char* g_library_version_number = ""; -} - bool EnsureJniRegistered(JNIEnv* env) { static bool g_jni_init_done = false; @@ -83,7 +75,7 @@ bool EnsureJniRegistered(JNIEnv* env) { return true; } -static jint LibraryLoaded(JNIEnv* env, jclass clazz, +bool LibraryLoaded(JNIEnv* env, jclass clazz, jobjectArray init_command_line) { base::android::InitNativeCommandLineFromJavaArray(env, init_command_line); @@ -125,43 +117,7 @@ static jint LibraryLoaded(JNIEnv* env, jclass clazz, VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() << ", default verbosity = " << logging::GetVlogVerbosity(); - if (!EnsureJniRegistered(env)) - return RESULT_CODE_FAILED_TO_REGISTER_JNI; - - return 0; -} - -static void RecordContentAndroidLinkerHistogram( - JNIEnv* env, - jclass clazz, - jboolean loaded_at_fixed_address_failed, - jboolean is_low_memory_device) { - UMA_HISTOGRAM_BOOLEAN("ContentAndroidLinker.LoadedAtFixedAddressFailed", - loaded_at_fixed_address_failed); - UMA_HISTOGRAM_BOOLEAN("ContentAndroidLinker.IsLowMemoryDevice", - is_low_memory_device); -} - -void LibraryLoaderExitHook() { - if (g_at_exit_manager) { - delete g_at_exit_manager; - g_at_exit_manager = NULL; - } -} - -bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { - // We need the AtExitManager to be created at the very beginning. - g_at_exit_manager = new base::AtExitManager(); - - return RegisterNativesImpl(env); -} - -void SetVersionNumber(const char* version_number) { - g_library_version_number = strdup(version_number); -} - -jstring GetVersionNumber(JNIEnv* env, jclass clazz) { - return env->NewStringUTF(g_library_version_number); + return EnsureJniRegistered(env); } } // namespace content diff --git a/content/common/android/linker/DEPS b/content/common/android/linker/DEPS deleted file mode 100644 index 220b4c4..0000000 --- a/content/common/android/linker/DEPS +++ /dev/null @@ -1,5 +0,0 @@ -include_rules = [ - # This code cannot depend on anything from base/ or content/ - "-base", - "-content", -] diff --git a/content/content.gyp b/content/content.gyp index cf3a307..c7afe15 100644 --- a/content/content.gyp +++ b/content/content.gyp @@ -371,21 +371,6 @@ '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': [ @@ -400,11 +385,9 @@ 'result_codes_java', 'speech_recognition_error_java', 'top_controls_state_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', @@ -508,24 +491,6 @@ ], 'includes': [ 'content_jni.gypi' ], }, - { - 'target_name': 'content_android_linker', - 'type': 'shared_library', - 'conditions': [ - ['android_webview_build == 0', { - # Avoid breaking the webview build because it doesn't have - # <(android_ndk_root)/crazy_linker.gyp. Note that it never uses - # the linker anyway. - 'sources': [ - 'common/android/linker/linker_jni.cc', - ], - 'dependencies': [ - '<(android_ndk_root)/crazy_linker.gyp:crazy_linker', - ], - }], - ], - }, - ], }], # OS == "android" ], diff --git a/content/content_jni.gypi b/content/content_jni.gypi index 6eddf01..8c02b52 100644 --- a/content/content_jni.gypi +++ b/content/content_jni.gypi @@ -10,7 +10,6 @@ 'sources': [ 'public/android/java/src/org/chromium/content/app/ChildProcessService.java', 'public/android/java/src/org/chromium/content/app/ContentMain.java', - 'public/android/java/src/org/chromium/content/app/LibraryLoader.java', 'public/android/java/src/org/chromium/content/browser/accessibility/BrowserAccessibilityManager.java', 'public/android/java/src/org/chromium/content/browser/BrowserStartupController.java', 'public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 6a7be8c..955fe03 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -1386,46 +1386,46 @@ 'includes': [ '../build/java_apk.gypi' ], }, { - 'target_name': 'content_linker_test_apk', + 'target_name': 'chromium_linker_test_apk', 'type': 'none', 'dependencies': [ - 'content_android_linker_test', + 'chromium_android_linker_test', 'content.gyp:content_java', 'content_shell_java', ], 'variables': { - 'apk_name': 'ContentLinkerTest', + 'apk_name': 'ChromiumLinkerTest', 'java_in_dir': 'shell/android/linker_test_apk', 'resource_dir': 'shell/android/linker_test_apk/res', - 'native_lib_target': 'libcontent_android_linker_test', + 'native_lib_target': 'libchromium_android_linker_test', 'additional_input_paths': ['<(PRODUCT_DIR)/content_shell/assets/content_shell.pak'], 'asset_location': '<(PRODUCT_DIR)/content_shell/assets', - 'use_content_linker': '1', - 'enable_content_linker_tests': '1', + 'use_chromium_linker': '1', + 'enable_chromium_linker_tests': '1', }, 'includes': [ '../build/java_apk.gypi' ], }, { - 'target_name': 'content_android_linker_test', + 'target_name': 'chromium_android_linker_test', 'type': 'shared_library', 'defines!': ['CONTENT_IMPLEMENTATION'], 'dependencies': [ - 'content_android_linker_test_jni_headers', + 'chromium_android_linker_test_jni_headers', 'content_shell_lib', # Required to include "content/public/browser/android/compositor.h" - # in content_linker_test_android.cc :-( + # in chromium_linker_test_android.cc :-( '../skia/skia.gyp:skia', ], 'sources': [ - 'shell/android/linker_test_apk/content_linker_test_android.cc', - 'shell/android/linker_test_apk/content_linker_test_linker_tests.cc', + 'shell/android/linker_test_apk/chromium_linker_test_android.cc', + 'shell/android/linker_test_apk/chromium_linker_test_linker_tests.cc', ], }, { - 'target_name': 'content_android_linker_test_jni_headers', + 'target_name': 'chromium_android_linker_test_jni_headers', 'type': 'none', 'sources': [ - 'shell/android/linker_test_apk/src/org/chromium/content_linker_test_apk/LinkerTests.java', + 'shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/LinkerTests.java', ], 'variables': { 'jni_gen_package': 'content/shell', 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 2898d42..769249e 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 @@ -18,11 +18,13 @@ import android.view.Surface; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.Linker; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.browser.ChildProcessConnection; import org.chromium.content.browser.ChildProcessLauncher; import org.chromium.content.common.IChildProcessCallback; import org.chromium.content.common.IChildProcessService; -import org.chromium.content.common.ProcessInitException; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicReference; @@ -53,7 +55,7 @@ public class ChildProcessService extends Service { private ArrayList<Integer> mFileIds; private ArrayList<ParcelFileDescriptor> mFileFds; // Linker-specific parameters for this child process service. - private LinkerParams mLinkerParams; + private ChromiumLinkerParams mLinkerParams; private static AtomicReference<Context> sContext = new AtomicReference<Context>(null); private boolean mLibraryInitialized = false; @@ -196,6 +198,7 @@ public class ChildProcessService extends Service { mMainThread.wait(); } } catch (InterruptedException e) { + // Ignore } } // Try to shutdown the MainThread gracefully, but it might not @@ -216,7 +219,7 @@ public class ChildProcessService extends Service { ChildProcessConnection.EXTRA_COMMAND_LINE); mLinkerParams = null; if (Linker.isUsed()) - mLinkerParams = new LinkerParams(intent); + mLinkerParams = new ChromiumLinkerParams(intent); mIsBound = true; mMainThread.notifyAll(); } diff --git a/content/public/android/java/src/org/chromium/content/app/LinkerParams.java b/content/public/android/java/src/org/chromium/content/app/ChromiumLinkerParams.java index 5a405f2..2152627 100644 --- a/content/public/android/java/src/org/chromium/content/app/LinkerParams.java +++ b/content/public/android/java/src/org/chromium/content/app/ChromiumLinkerParams.java @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. @@ -8,10 +8,10 @@ import android.content.Intent; /** * A class to hold information passed from the browser process to each - * service one when using the content linker. For more information, read the + * service one when using the chromium linker. For more information, read the * technical notes in Linker.java. */ -public class LinkerParams { +public class ChromiumLinkerParams { // Use this base address to load native shared libraries. If 0, ignore other members. public final long mBaseLoadAddress; @@ -31,7 +31,7 @@ public class LinkerParams { private static final String EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME = "org.chromium.content.common.linker_params.test_runner_class_name"; - public LinkerParams(long baseLoadAddress, + public ChromiumLinkerParams(long baseLoadAddress, boolean waitForSharedRelro, String testRunnerClassName) { mBaseLoadAddress = baseLoadAddress; @@ -44,7 +44,7 @@ public class LinkerParams { * @param intent An Intent, its content must have been populated by a previous * call to addIntentExtras(). */ - public LinkerParams(Intent intent) { + public ChromiumLinkerParams(Intent intent) { mBaseLoadAddress = intent.getLongExtra(EXTRA_LINKER_PARAMS_BASE_LOAD_ADDRESS, 0); mWaitForSharedRelro = intent.getBooleanExtra( EXTRA_LINKER_PARAMS_WAIT_FOR_SHARED_RELRO, false); diff --git a/content/public/android/java/src/org/chromium/content/app/ContentApplication.java b/content/public/android/java/src/org/chromium/content/app/ContentApplication.java index e0f49a9..7b6f50e 100644 --- a/content/public/android/java/src/org/chromium/content/app/ContentApplication.java +++ b/content/public/android/java/src/org/chromium/content/app/ContentApplication.java @@ -8,6 +8,7 @@ import android.os.Looper; import android.os.MessageQueue; import org.chromium.base.BaseChromiumApplication; +import org.chromium.base.library_loader.LibraryLoader; import org.chromium.content.browser.TracingControllerAndroid; /** 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 635a153..3bf8399 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 @@ -1,192 +1,13 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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; -import android.util.Log; - -import org.chromium.base.CommandLine; -import org.chromium.base.JNINamespace; -import org.chromium.base.SysUtils; -import org.chromium.base.TraceEvent; -import org.chromium.content.common.ProcessInitException; -import org.chromium.content.common.ResultCodes; - /** - * 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 libraries may be loaded and initialized from any thread. Synchronization - * primitives are used to ensure that overlapping requests from different - * threads are handled sequentially. - * - * See also content/app/android/library_loader_hooks.cc, which contains - * the native counterpart to this class. + * Shim class for real LibraryLoader to simplify moving the real class + * TODO(aberent) remove once all code references LibraryLoader in new location. */ -@JNINamespace("content") -public class LibraryLoader { - private static final String TAG = "LibraryLoader"; - - // Guards all access to the libraries - private static final Object sLock = new Object(); - - // One-way switch becomes true when the libraries are loaded. - private static boolean sLoaded = false; - - // 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. - /** - * Doesn't do anything. - */ - @Deprecated - public static void setLibraryToLoad(String library) { - } - - /** - * This method blocks until the library is fully loaded and initialized. - */ - public static void ensureInitialized() throws ProcessInitException { - synchronized (sLock) { - if (sInitialized) { - // Already initialized, nothing to do. - return; - } - loadAlreadyLocked(); - initializeAlreadyLocked(CommandLine.getJavaSwitchesOrNull()); - } - } - - /** - * Checks if library is fully loaded and initialized. - */ - public static boolean isInitialized() { - synchronized (sLock) { - return sInitialized; - } - } - - /** - * Loads the library and blocks until the load completes. The caller is responsible - * for subsequently calling ensureInitialized(). - * May be called on any thread, but should only be called once. Note the thread - * this is called on will be the thread that runs the native code's static initializers. - * See the comment in doInBackground() for more considerations on this. - * - * @throws ProcessInitException if the native library failed to load. - */ - public static void loadNow() throws ProcessInitException { - synchronized (sLock) { - loadAlreadyLocked(); - } - } - - - /** - * initializes the library here and now: must be called on the thread that the - * native will call its "main" thread. The library must have previously been - * loaded with loadNow. - * @param initCommandLine The command line arguments that native command line will - * be initialized with. - */ - static void initialize(String[] initCommandLine) throws ProcessInitException { - synchronized (sLock) { - initializeAlreadyLocked(initCommandLine); - } - } - - - // Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code - private static void loadAlreadyLocked() throws ProcessInitException { - try { - if (!sLoaded) { - assert !sInitialized; - - long startTime = System.currentTimeMillis(); - boolean useContentLinker = Linker.isUsed(); - - if (useContentLinker) - Linker.prepareLibraryLoad(); - - for (String library : NativeLibraries.LIBRARIES) { - Log.i(TAG, "Loading: " + library); - if (useContentLinker) - Linker.loadLibrary(library); - else - System.loadLibrary(library); - } - if (useContentLinker) - Linker.finishLibraryLoad(); - long stopTime = System.currentTimeMillis(); - Log.i(TAG, String.format("Time to load native libraries: %d ms (timestamps %d-%d)", - stopTime - startTime, - startTime % 10000, - stopTime % 10000)); - sLoaded = true; - } - } catch (UnsatisfiedLinkError e) { - throw new ProcessInitException(ResultCodes.RESULT_CODE_NATIVE_LIBRARY_LOAD_FAILED, e); - } - // Check that the version of the library we have loaded matches the version we expect - Log.i(TAG, String.format( - "Expected native library version number \"%s\"," + - "actual native library version number \"%s\"", - NativeLibraries.VERSION_NUMBER, - nativeGetVersionNumber())); - if (!NativeLibraries.VERSION_NUMBER.equals(nativeGetVersionNumber())) { - throw new ProcessInitException(ResultCodes.RESULT_CODE_NATIVE_LIBRARY_WRONG_VERSION); - } - - } - - - // Invoke content::LibraryLoaded in library_loader_hooks.cc - private static void initializeAlreadyLocked(String[] initCommandLine) - throws ProcessInitException { - if (sInitialized) { - return; - } - int resultCode = nativeLibraryLoaded(initCommandLine); - if (resultCode != 0) { - Log.e(TAG, "error calling nativeLibraryLoaded"); - throw new ProcessInitException(resultCode); - } - // From this point on, native code is ready to use and checkIsReady() - // shouldn't complain from now on (and in fact, it's used by the - // following calls). - sInitialized = true; - CommandLine.enableNativeProxy(); - TraceEvent.setEnabledToMatchNative(); - // Record histogram for the content linker. - if (Linker.isUsed()) - nativeRecordContentAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(), - SysUtils.isLowEndDevice()); - } - - // 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 content/app/android/library_loader_hooks.cc. - // - // Return 0 on success, otherwise return the error code from - // content/public/common/result_codes.h. - private static native int nativeLibraryLoaded(String[] initCommandLine); - - // Method called to record statistics about the content linker operation, - // i.e. whether the library failed to be loaded at a fixed address, and - // whether the device is 'low-memory'. - private static native void nativeRecordContentAndroidLinkerHistogram( - boolean loadedAtFixedAddressFailed, - boolean isLowMemoryDevice); +public class LibraryLoader extends org.chromium.base.library_loader.LibraryLoader { - // Get the version of the native library. This is needed so that we can check we - // have the right version before initializing the (rest of the) JNI. - private static native String nativeGetVersionNumber(); } diff --git a/content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java b/content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java index 403c906..be5e2f9 100644 --- a/content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java +++ b/content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java @@ -13,10 +13,10 @@ import com.google.common.annotations.VisibleForTesting; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; import org.chromium.base.ThreadUtils; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.LoaderErrors; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.app.ContentMain; -import org.chromium.content.app.LibraryLoader; -import org.chromium.content.common.ProcessInitException; -import org.chromium.content.common.ResultCodes; import java.util.ArrayList; import java.util.List; @@ -37,6 +37,9 @@ import java.util.List; @JNINamespace("content") public class BrowserStartupController { + /** + * This provides the interface to the callbacks for successful or failed startup + */ public interface StartupCallback { void onSuccess(boolean alreadyStarted); void onFailure(); @@ -196,7 +199,7 @@ public class BrowserStartupController { // Startup should now be complete assert mStartupDone; if (!mStartupSuccess) { - throw new ProcessInitException(ResultCodes.RESULT_CODE_NATIVE_STARTUP_FAILED); + throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_STARTUP_FAILED); } } @@ -268,7 +271,13 @@ public class BrowserStartupController { // Normally Main.java will have already loaded the library asynchronously, we only need // to load it here if we arrived via another flow, e.g. bookmark access & sync setup. - LibraryLoader.ensureInitialized(); + // TODO(aberent): This try/catch is temporary code to ease landing the change. It can + // be removed once the downstream changes have landed + try { + LibraryLoader.ensureInitialized(); + } catch (org.chromium.base.library_loader.ProcessInitException e) { + throw new ProcessInitException(e.getErrorCode()); + } // TODO(yfriedman): Remove dependency on a command line flag for this. DeviceUtils.addDeviceSpecificUserAgentSwitch(mContext); diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java index fea34e2..da441d1ad 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java @@ -16,9 +16,9 @@ import android.util.Log; import org.chromium.base.CpuFeatures; import org.chromium.base.ThreadUtils; import org.chromium.base.TraceEvent; +import org.chromium.base.library_loader.Linker; import org.chromium.content.app.ChildProcessService; -import org.chromium.content.app.Linker; -import org.chromium.content.app.LinkerParams; +import org.chromium.content.app.ChromiumLinkerParams; import org.chromium.content.common.IChildProcessCallback; import org.chromium.content.common.IChildProcessService; @@ -64,7 +64,7 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection { private int mStrongBindingCount = 0; // Linker-related parameters. - private LinkerParams mLinkerParams = null; + private ChromiumLinkerParams mLinkerParams = null; private static final String TAG = "ChildProcessConnection"; @@ -183,13 +183,13 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection { ChildProcessConnectionImpl(Context context, int number, boolean inSandbox, ChildProcessConnection.DeathCallback deathCallback, Class<? extends ChildProcessService> serviceClass, - LinkerParams linkerParams) { + ChromiumLinkerParams chromiumLinkerParams) { mContext = context; mServiceNumber = number; mInSandbox = inSandbox; mDeathCallback = deathCallback; mServiceClass = serviceClass; - mLinkerParams = linkerParams; + mLinkerParams = chromiumLinkerParams; mInitialBinding = new ChildServiceConnection(Context.BIND_AUTO_CREATE); mStrongBinding = new ChildServiceConnection( Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT); 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 01ec12a..d44163f 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 @@ -13,9 +13,9 @@ import com.google.common.annotations.VisibleForTesting; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; import org.chromium.base.ThreadUtils; +import org.chromium.base.library_loader.Linker; import org.chromium.content.app.ChildProcessService; -import org.chromium.content.app.Linker; -import org.chromium.content.app.LinkerParams; +import org.chromium.content.app.ChromiumLinkerParams; import org.chromium.content.app.PrivilegedProcessService; import org.chromium.content.app.SandboxedProcessService; import org.chromium.content.common.IChildProcessCallback; @@ -86,7 +86,7 @@ public class ChildProcessLauncher { public ChildProcessConnection allocate( Context context, ChildProcessConnection.DeathCallback deathCallback, - LinkerParams linkerParams) { + ChromiumLinkerParams chromiumLinkerParams) { synchronized (mConnectionLock) { if (mFreeConnectionIndices.isEmpty()) { Log.w(TAG, "Ran out of service."); @@ -95,7 +95,7 @@ public class ChildProcessLauncher { int slot = mFreeConnectionIndices.remove(0); assert mChildProcessConnections[slot] == null; mChildProcessConnections[slot] = new ChildProcessConnectionImpl(context, slot, - mInSandbox, deathCallback, mChildClass, linkerParams); + mInSandbox, deathCallback, mChildClass, chromiumLinkerParams); return mChildProcessConnections[slot]; } } @@ -145,7 +145,7 @@ public class ChildProcessLauncher { } private static ChildProcessConnection allocateConnection(Context context, - boolean inSandbox, LinkerParams linkerParams) { + boolean inSandbox, ChromiumLinkerParams chromiumLinkerParams) { ChildProcessConnection.DeathCallback deathCallback = new ChildProcessConnection.DeathCallback() { @Override @@ -154,13 +154,14 @@ public class ChildProcessLauncher { } }; sConnectionAllocated = true; - return getConnectionAllocator(inSandbox).allocate(context, deathCallback, linkerParams); + return getConnectionAllocator(inSandbox).allocate(context, deathCallback, + chromiumLinkerParams); } private static boolean sLinkerInitialized = false; private static long sLinkerLoadAddress = 0; - private static LinkerParams getLinkerParamsForNewConnection() { + private static ChromiumLinkerParams getLinkerParamsForNewConnection() { if (!sLinkerInitialized) { if (Linker.isUsed()) { sLinkerLoadAddress = Linker.getBaseLoadAddress(); @@ -176,15 +177,16 @@ public class ChildProcessLauncher { // Always wait for the shared RELROs in service processes. final boolean waitForSharedRelros = true; - return new LinkerParams(sLinkerLoadAddress, + return new ChromiumLinkerParams(sLinkerLoadAddress, waitForSharedRelros, Linker.getTestRunnerClassName()); } private static ChildProcessConnection allocateBoundConnection(Context context, String[] commandLine, boolean inSandbox) { - LinkerParams linkerParams = getLinkerParamsForNewConnection(); - ChildProcessConnection connection = allocateConnection(context, inSandbox, linkerParams); + ChromiumLinkerParams chromiumLinkerParams = getLinkerParamsForNewConnection(); + ChildProcessConnection connection = + allocateConnection(context, inSandbox, chromiumLinkerParams); if (connection != null) { connection.start(commandLine); } diff --git a/content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java b/content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java index 188aa08..b9d9f26 100644 --- a/content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java +++ b/content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java @@ -9,10 +9,13 @@ import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.SmallTest; import org.chromium.base.ThreadUtils; +import org.chromium.base.library_loader.LoaderErrors; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.test.util.AdvancedMockContext; -import org.chromium.content.common.ProcessInitException; -import org.chromium.content.common.ResultCodes; +/** + * Test of BrowserStartupController + */ public class BrowserStartupControllerTest extends InstrumentationTestCase { private TestBrowserStartupController mController; @@ -26,7 +29,8 @@ public class BrowserStartupControllerTest extends InstrumentationTestCase { @Override void prepareToStartBrowserProcess(int numRenderers) throws ProcessInitException { if (!mLibraryLoadSucceeds) { - throw new ProcessInitException(ResultCodes.RESULT_CODE_NATIVE_LIBRARY_LOAD_FAILED); + throw new ProcessInitException( + LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_LOAD_FAILED); } } diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java index 12d6f04..a0a3d4e 100644 --- a/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java +++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java @@ -8,12 +8,15 @@ import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.MediumTest; import org.chromium.base.CommandLine; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.test.util.Feature; -import org.chromium.content.app.LibraryLoader; -import org.chromium.content.common.ProcessInitException; import org.chromium.content_shell_apk.ContentShellActivity; import org.chromium.content_shell_apk.ContentShellApplication; +/** + * Test class for command lines. + */ public class ContentCommandLineTest extends InstrumentationTestCase { // A reference command line. Note that switch2 is [brea\d], switch3 is [and "butter"], // and switch4 is [a "quoted" 'food'!] diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java index 31be5e9..66c17e0f 100644 --- a/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java +++ b/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java @@ -8,9 +8,9 @@ import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.SmallTest; import org.chromium.base.ImportantFileWriterAndroid; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.test.util.Feature; -import org.chromium.content.app.LibraryLoader; -import org.chromium.content.common.ProcessInitException; import org.chromium.content_shell_apk.ContentShellApplication; import java.io.DataInputStream; diff --git a/content/public/app/android_library_loader_hooks.h b/content/public/app/android_library_loader_hooks.h index 2ec5a19..b815f08 100644 --- a/content/public/app/android_library_loader_hooks.h +++ b/content/public/app/android_library_loader_hooks.h @@ -12,25 +12,17 @@ namespace content { -// Registers the callbacks that allows the entry point of the library to be -// exposed to the calling java code. This handles only registering the content -// specific callbacks. Any application specific JNI bindings should happen -// once the native library has fully loaded. -CONTENT_EXPORT bool RegisterLibraryLoaderEntryHook(JNIEnv* env); - // Register all content JNI functions now, rather than waiting for the process -// of fully loading the native library to complete. This must only be called -// during JNI_OnLoad. +// of fully loading the native library to complete. CONTENT_EXPORT bool EnsureJniRegistered(JNIEnv* env); -// Pass the version name to Content. This used to check that the library version -// matches the version expected by Java before completing JNI registration. -// Note: argument must remain valid at least until library loading is complete. -CONTENT_EXPORT void SetVersionNumber(const char* version_number); - -// Call on exit to delete the AtExitManager which OnLibraryLoadedOnUIThread -// created. -CONTENT_EXPORT void LibraryLoaderExitHook(); +// Do the intialization of content needed immediately after the native library +// has loaded. +// This is designed to be used as a hook function to be passed to +// base::android::SetLibraryLoadedHook +CONTENT_EXPORT bool LibraryLoaded(JNIEnv* env, + jclass clazz, + jobjectArray init_command_line); } // namespace content diff --git a/content/shell/android/browsertests_apk/content_browser_tests_android.cc b/content/shell/android/browsertests_apk/content_browser_tests_android.cc index 0acff50..d4dd0b2 100644 --- a/content/shell/android/browsertests_apk/content_browser_tests_android.cc +++ b/content/shell/android/browsertests_apk/content_browser_tests_android.cc @@ -12,6 +12,7 @@ #include "base/android/fifo_utils.h" #include "base/android/jni_android.h" #include "base/android/jni_string.h" +#include "base/android/library_loader/library_loader_hooks.h" #include "base/android/scoped_java_ref.h" #include "base/base_switches.h" #include "base/command_line.h" @@ -98,10 +99,13 @@ static void RunTests(JNIEnv* env, // This is called by the VM when the shared library is first loaded. JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + + base::android::SetLibraryLoadedHook(&content::LibraryLoaded); + base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!content::RegisterLibraryLoaderEntryHook(env)) + if (!base::android::RegisterLibraryLoaderEntryHook(env)) return -1; if (!content::android::RegisterShellJni(env)) diff --git a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java index be36d6e..f00dfd1 100644 --- a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java +++ b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java @@ -12,13 +12,16 @@ import android.view.LayoutInflater; import android.view.View; import org.chromium.base.JNINamespace; -import org.chromium.content.app.LibraryLoader; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.browser.BrowserStartupController; -import org.chromium.content.common.ProcessInitException; import org.chromium.content_shell.ShellManager; import org.chromium.ui.base.ActivityWindowAndroid; import org.chromium.ui.base.WindowAndroid; +/** + * Android activity for running content browser tests + */ @JNINamespace("content") public class ContentBrowserTestsActivity extends Activity { private static final String TAG = "ChromeBrowserTestsActivity"; diff --git a/content/shell/android/linker_test_apk/AndroidManifest.xml b/content/shell/android/linker_test_apk/AndroidManifest.xml index 815bab5..94a3488 100644 --- a/content/shell/android/linker_test_apk/AndroidManifest.xml +++ b/content/shell/android/linker_test_apk/AndroidManifest.xml @@ -7,14 +7,14 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.chromium.content_linker_test_apk"> + package="org.chromium.chromium_linker_test_apk"> <permission android:name="org.chromium.content_shell.permission.SANDBOX" android:protectionLevel="signature" /> - <application android:name="ContentLinkerTestApplication" - android:label="ContentLinkerTest"> - <activity android:name="ContentLinkerTestActivity" + <application android:name="ChromiumLinkerTestApplication" + android:label="ChromiumLinkerTest"> + <activity android:name="ChromiumLinkerTestActivity" android:launchMode="singleTask" android:theme="@android:style/Theme.Holo.Light.NoActionBar" android:configChanges="orientation|keyboardHidden|keyboard|screenSize" diff --git a/content/shell/android/linker_test_apk/content_linker_test_android.cc b/content/shell/android/linker_test_apk/chromium_linker_test_android.cc index 42c01d0..5173128 100644 --- a/content/shell/android/linker_test_apk/content_linker_test_android.cc +++ b/content/shell/android/linker_test_apk/chromium_linker_test_android.cc @@ -1,25 +1,29 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" +#include "base/android/library_loader/library_loader_hooks.h" #include "base/basictypes.h" #include "base/debug/debugger.h" #include "base/logging.h" #include "content/public/app/android_library_loader_hooks.h" #include "content/public/app/content_main.h" #include "content/public/browser/android/compositor.h" -#include "content/shell/android/linker_test_apk/content_linker_test_linker_tests.h" +#include "content/shell/android/linker_test_apk/chromium_linker_test_linker_tests.h" #include "content/shell/android/shell_jni_registrar.h" #include "content/shell/app/shell_main_delegate.h" // This is called by the VM when the shared library is first loaded. JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + + base::android::SetLibraryLoadedHook(&content::LibraryLoaded); + base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!content::RegisterLibraryLoaderEntryHook(env)) + if (!base::android::RegisterLibraryLoaderEntryHook(env)) return -1; // To be called only from the UI thread. If loading the library is done on diff --git a/content/shell/android/linker_test_apk/content_linker_test_linker_tests.cc b/content/shell/android/linker_test_apk/chromium_linker_test_linker_tests.cc index c970ff6..0e95828 100644 --- a/content/shell/android/linker_test_apk/content_linker_test_linker_tests.cc +++ b/content/shell/android/linker_test_apk/chromium_linker_test_linker_tests.cc @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. @@ -8,7 +8,7 @@ // can // thus use base/ and the C++ STL. -#include "content/shell/android/linker_test_apk/content_linker_test_linker_tests.h" +#include "content/shell/android/linker_test_apk/chromium_linker_test_linker_tests.h" #include <errno.h> #include <sys/mman.h> diff --git a/content/shell/android/linker_test_apk/chromium_linker_test_linker_tests.h b/content/shell/android/linker_test_apk/chromium_linker_test_linker_tests.h new file mode 100644 index 0000000..4d44077 --- /dev/null +++ b/content/shell/android/linker_test_apk/chromium_linker_test_linker_tests.h @@ -0,0 +1,16 @@ +// Copyright 2014 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. + +#ifndef CONTENT_SHELL_ANDROID_LINKER_TEST_APK_CHROMIUM_LINKER_TEST_LINKER_TESTS_H +#define CONTENT_SHELL_ANDROID_LINKER_TEST_APK_CHROMIUM_LINKER_TEST_LINKER_TESTS_H + +#include <jni.h> + +namespace content { + +bool RegisterLinkerTestsJni(JNIEnv* env); + +} // namespace content + +#endif // CONTENT_SHELL_ANDROID_LINKER_TEST_APK_CHROMIUM_LINKER_TEST_LINKER_TESTS_H diff --git a/content/shell/android/linker_test_apk/content_linker_test_linker_tests.h b/content/shell/android/linker_test_apk/content_linker_test_linker_tests.h deleted file mode 100644 index 3fcfa2d..0000000 --- a/content/shell/android/linker_test_apk/content_linker_test_linker_tests.h +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -#ifndef CONTENT_SHELL_ANDROID_LINKER_TEST_APK_CONTENT_LINKER_TEST_LINKER_TESTS_H -#define CONTENT_SHELL_ANDROID_LINKER_TEST_APK_CONTENT_LINKER_TEST_LINKER_TESTS_H - -#include <jni.h> - -namespace content { - -bool RegisterLinkerTestsJni(JNIEnv* env); - -} // namespace content - -#endif // CONTENT_SHELL_ANDROID_LINKER_TEST_APK_CONTENT_LINKER_TEST_LINKER_TESTS_H diff --git a/content/shell/android/linker_test_apk/src/org/chromium/content_linker_test_apk/ContentLinkerTestActivity.java b/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestActivity.java index 7a2a46e..b3bca6b 100644 --- a/content/shell/android/linker_test_apk/src/org/chromium/content_linker_test_apk/ContentLinkerTestActivity.java +++ b/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestActivity.java @@ -1,8 +1,8 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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_linker_test_apk; +package org.chromium.chromium_linker_test_apk; import android.app.Activity; import android.content.Context; @@ -14,12 +14,12 @@ import android.view.View; import org.chromium.base.BaseSwitches; import org.chromium.base.CommandLine; -import org.chromium.content.app.LibraryLoader; -import org.chromium.content.app.Linker; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.Linker; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.ContentView; import org.chromium.content.browser.ContentViewClient; -import org.chromium.content.common.ProcessInitException; import org.chromium.content_shell.Shell; import org.chromium.content_shell.ShellManager; import org.chromium.ui.base.ActivityWindowAndroid; @@ -28,11 +28,11 @@ import org.chromium.ui.base.WindowAndroid; /** * Test activity used for verifying the different configuration options for the ContentLinker. */ -public class ContentLinkerTestActivity extends Activity { +public class ChromiumLinkerTestActivity extends Activity { public static final String COMMAND_LINE_FILE = - "/data/local/tmp/content-linker-test-command-line"; + "/data/local/tmp/chromium-linker-test-command-line"; - private static final String TAG = "ContentLinkerTestActivity"; + private static final String TAG = "ChromiumLinkerTestActivity"; public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; @@ -87,7 +87,7 @@ public class ContentLinkerTestActivity extends Activity { try { LibraryLoader.ensureInitialized(); } catch (ProcessInitException e) { - Log.i(TAG, "Cannot load content_linker_test:" + e); + Log.i(TAG, "Cannot load chromium_linker_test:" + e); } // Now, start a new renderer process by creating a new view. @@ -173,10 +173,6 @@ public class ContentLinkerTestActivity extends Activity { mWindowAndroid.onActivityResult(requestCode, resultCode, data); } - private static String getUrlFromIntent(Intent intent) { - return intent != null ? intent.getDataString() : null; - } - private static String[] getCommandLineParamsFromIntent(Intent intent) { return intent != null ? intent.getStringArrayExtra(COMMAND_LINE_ARGS_KEY) : null; } diff --git a/content/shell/android/linker_test_apk/src/org/chromium/content_linker_test_apk/ContentLinkerTestApplication.java b/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestApplication.java index ae1a728..252198a 100644 --- a/content/shell/android/linker_test_apk/src/org/chromium/content_linker_test_apk/ContentLinkerTestApplication.java +++ b/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestApplication.java @@ -1,19 +1,21 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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_linker_test_apk; +package org.chromium.chromium_linker_test_apk; import android.app.Application; import org.chromium.base.PathUtils; -import org.chromium.content.app.LibraryLoader; import org.chromium.content.browser.ResourceExtractor; -public class ContentLinkerTestApplication extends Application { +/** + * Application for testing the Chromium Linker + */ +public class ChromiumLinkerTestApplication extends Application { private static final String[] MANDATORY_PAK_FILES = new String[] {"content_shell.pak"}; - private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "content_linker_test"; + private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chromium_linker_test"; @Override public void onCreate() { diff --git a/content/shell/android/linker_test_apk/src/org/chromium/content_linker_test_apk/LinkerTests.java b/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/LinkerTests.java index 6713643..b48b035 100644 --- a/content/shell/android/linker_test_apk/src/org/chromium/content_linker_test_apk/LinkerTests.java +++ b/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/LinkerTests.java @@ -1,22 +1,25 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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_linker_test_apk; +package org.chromium.chromium_linker_test_apk; import android.util.Log; import org.chromium.base.JNINamespace; -import org.chromium.content.app.Linker; +import org.chromium.base.library_loader.Linker; -// A class that is only used in linker test APK to perform runtime checks -// in the current process. +/** + * A class that is only used in linker test APK to perform runtime checks + * in the current process. + */ @JNINamespace("content") public class LinkerTests implements Linker.TestRunner { private static final String TAG = "LinkerTests"; public LinkerTests() {} + @Override public boolean runChecks(int memoryDeviceConfig, boolean isBrowserProcess) { boolean checkSharedRelro; diff --git a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java index 6534da4..0e5aa74 100644 --- a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java +++ b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java @@ -16,7 +16,8 @@ import android.widget.Toast; import org.chromium.base.BaseSwitches; import org.chromium.base.CommandLine; import org.chromium.base.MemoryPressureListener; -import org.chromium.content.app.LibraryLoader; +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.browser.ActivityContentVideoViewClient; import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.ContentVideoViewClient; @@ -24,7 +25,6 @@ import org.chromium.content.browser.ContentView; import org.chromium.content.browser.ContentViewClient; import org.chromium.content.browser.DeviceUtils; import org.chromium.content.common.ContentSwitches; -import org.chromium.content.common.ProcessInitException; import org.chromium.content_shell.Shell; import org.chromium.content_shell.ShellManager; import org.chromium.ui.base.ActivityWindowAndroid; diff --git a/content/shell/android/shell_library_loader.cc b/content/shell/android/shell_library_loader.cc index 599e421..142d9ef 100644 --- a/content/shell/android/shell_library_loader.cc +++ b/content/shell/android/shell_library_loader.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/android/jni_android.h" +#include "base/android/jni_registrar.h" +#include "base/android/library_loader/library_loader_hooks.h" #include "base/basictypes.h" #include "base/debug/debugger.h" #include "base/logging.h" -#include "base/android/jni_android.h" -#include "base/android/jni_registrar.h" #include "content/public/app/android_library_loader_hooks.h" #include "content/public/app/content_main.h" #include "content/public/browser/android/compositor.h" @@ -15,10 +16,13 @@ // This is called by the VM when the shared library is first loaded. JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + + base::android::SetLibraryLoadedHook(&content::LibraryLoaded); + base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!content::RegisterLibraryLoaderEntryHook(env)) + if (!base::android::RegisterLibraryLoaderEntryHook(env)) return -1; // To be called only from the UI thread. If loading the library is done on diff --git a/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java b/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java index 9063ee3..1d29bcd 100644 --- a/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java +++ b/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 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. @@ -12,12 +12,13 @@ import android.util.Log; import org.chromium.base.PathUtils; import org.chromium.base.PowerMonitor; -// TODO(cjhopman): This should not refer to content. NativeLibraries should be moved to base. -import org.chromium.content.app.NativeLibraries; +import org.chromium.base.library_loader.NativeLibraries; -// Android's NativeActivity is mostly useful for pure-native code. -// Our tests need to go up to our own java classes, which is not possible using -// the native activity class loader. +/** + * Android's NativeActivity is mostly useful for pure-native code. + * Our tests need to go up to our own java classes, which is not possible using + * the native activity class loader. + */ public class ChromeNativeTestActivity extends Activity { private static final String TAG = "ChromeNativeTestActivity"; private static final String EXTRA_RUN_IN_SUB_THREAD = "RunInSubThread"; @@ -68,7 +69,7 @@ public class ChromeNativeTestActivity extends Activity { } private void loadLibraries() { - for (String library: NativeLibraries.LIBRARIES) { + for (String library : NativeLibraries.LIBRARIES) { Log.i(TAG, "loading: " + library); System.loadLibrary(library); Log.i(TAG, "loaded: " + library); |