OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/android/library_loader/library_loader_hooks.h" |
| 6 |
| 7 #include "base/at_exit.h" |
| 8 #include "base/metrics/histogram.h" |
| 9 #include "jni/LibraryLoader_jni.h" |
| 10 |
| 11 namespace base { |
| 12 namespace android { |
| 13 |
| 14 namespace { |
| 15 |
| 16 base::AtExitManager* g_at_exit_manager = NULL; |
| 17 const char* g_library_version_number = ""; |
| 18 LibraryLoadedHook* g_registration_callback = NULL; |
| 19 |
| 20 } // namespace |
| 21 |
| 22 void SetLibraryLoadedHook(LibraryLoadedHook* func) { |
| 23 g_registration_callback = func; |
| 24 } |
| 25 |
| 26 static jboolean LibraryLoaded(JNIEnv* env, jclass clazz, |
| 27 jobjectArray init_command_line) { |
| 28 if(g_registration_callback == NULL) { |
| 29 return true; |
| 30 } |
| 31 return g_registration_callback(env, clazz, init_command_line); |
| 32 } |
| 33 |
| 34 static void RecordChromiumAndroidLinkerHistogram( |
| 35 JNIEnv* env, |
| 36 jclass clazz, |
| 37 jboolean loaded_at_fixed_address_failed, |
| 38 jboolean is_low_memory_device) { |
| 39 UMA_HISTOGRAM_BOOLEAN("ChromiumAndroidLinker.LoadedAtFixedAddressFailed", |
| 40 loaded_at_fixed_address_failed); |
| 41 UMA_HISTOGRAM_BOOLEAN("ChromiumAndroidLinker.IsLowMemoryDevice", |
| 42 is_low_memory_device); |
| 43 } |
| 44 |
| 45 void LibraryLoaderExitHook() { |
| 46 if (g_at_exit_manager) { |
| 47 delete g_at_exit_manager; |
| 48 g_at_exit_manager = NULL; |
| 49 } |
| 50 } |
| 51 |
| 52 bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { |
| 53 // We need the AtExitManager to be created at the very beginning. |
| 54 g_at_exit_manager = new base::AtExitManager(); |
| 55 |
| 56 return RegisterNativesImpl(env); |
| 57 } |
| 58 |
| 59 void SetVersionNumber(const char* version_number) { |
| 60 g_library_version_number = strdup(version_number); |
| 61 } |
| 62 |
| 63 jstring GetVersionNumber(JNIEnv* env, jclass clazz) { |
| 64 return env->NewStringUTF(g_library_version_number); |
| 65 } |
| 66 |
| 67 } // namespace android |
| 68 } // namespace base |
OLD | NEW |