Chromium Code Reviews| Index: base/android/library_loader/library_loader_hooks.cc |
| 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 0000000000000000000000000000000000000000..000016d86a9143c5aacf13703b9814ea47feff78 |
| --- /dev/null |
| +++ b/base/android/library_loader/library_loader_hooks.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 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 = ""; |
| +LibraryLoaderHook* g_jni_registration_callback = NULL; |
| + |
| +} // namespace |
| + |
| +void SetLibraryLoadedHook(LibraryLoaderHook* func) { |
| + g_jni_registration_callback = func; |
|
Yaron
2014/01/17 02:18:25
Don't think this needs to refer to "jni"
aberent
2014/01/30 17:46:05
Done.
|
| +} |
| + |
| +static jboolean LibraryLoaded(JNIEnv* env, jclass clazz, |
| + jobjectArray init_command_line) { |
| + return g_jni_registration_callback(env, clazz, init_command_line); |
| +} |
| + |
| +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); |
| +} |
| + |
| +} // namespace android |
| +} // namespace base |