Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/android/library_loader/library_loader_hooks.h" | 5 #include "base/android/library_loader/library_loader_hooks.h" |
| 6 | 6 |
| 7 #include "base/android/command_line_android.h" | 7 #include "base/android/command_line_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/android/library_loader/library_load_from_apk_status_codes.h" | 9 #include "base/android/library_loader/library_load_from_apk_status_codes.h" |
| 10 #include "base/android/library_loader/library_prefetcher.h" | 10 #include "base/android/library_loader/library_prefetcher.h" |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "jni/LibraryLoader_jni.h" | 14 #include "jni/LibraryLoader_jni.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 namespace android { | 17 namespace android { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 base::AtExitManager* g_at_exit_manager = NULL; | 21 base::AtExitManager* g_at_exit_manager = NULL; |
| 22 const char* g_library_version_number = ""; | 22 const char* g_library_version_number = ""; |
| 23 LibraryLoadedHook* g_registration_callback = NULL; | 23 LibraryLoadedHook* g_registration_callback = NULL; |
| 24 NativeInitializationHook* g_native_initialization_hook = NULL; | |
| 24 | 25 |
| 25 enum RendererHistogramCode { | 26 enum RendererHistogramCode { |
| 26 // Renderer load at fixed address success, fail, or not attempted. | 27 // Renderer load at fixed address success, fail, or not attempted. |
| 27 // Renderers do not attempt to load at at fixed address if on a | 28 // Renderers do not attempt to load at at fixed address if on a |
| 28 // low-memory device on which browser load at fixed address has already | 29 // low-memory device on which browser load at fixed address has already |
| 29 // failed. | 30 // failed. |
| 30 LFA_SUCCESS = 0, | 31 LFA_SUCCESS = 0, |
| 31 LFA_BACKOFF_USED = 1, | 32 LFA_BACKOFF_USED = 1, |
| 32 LFA_NOT_ATTEMPTED = 2, | 33 LFA_NOT_ATTEMPTED = 2, |
| 33 | 34 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 } | 143 } |
| 143 | 144 |
| 144 static void RegisterLibraryPreloaderRendererHistogram( | 145 static void RegisterLibraryPreloaderRendererHistogram( |
| 145 JNIEnv* env, | 146 JNIEnv* env, |
| 146 const JavaParamRef<jobject>& jcaller, | 147 const JavaParamRef<jobject>& jcaller, |
| 147 jint status) { | 148 jint status) { |
| 148 g_library_preloader_renderer_histogram_code = status; | 149 g_library_preloader_renderer_histogram_code = status; |
| 149 g_library_preloader_renderer_histogram_code_registered = true; | 150 g_library_preloader_renderer_histogram_code_registered = true; |
| 150 } | 151 } |
| 151 | 152 |
| 153 void SetNativeInitializationHook( | |
| 154 NativeInitializationHook native_initialization_hook) { | |
| 155 g_native_initialization_hook = native_initialization_hook; | |
| 156 } | |
| 157 | |
| 152 void RecordLibraryLoaderRendererHistograms() { | 158 void RecordLibraryLoaderRendererHistograms() { |
| 153 RecordChromiumAndroidLinkerRendererHistogram(); | 159 RecordChromiumAndroidLinkerRendererHistogram(); |
| 154 RecordLibraryPreloaderRendereHistogram(); | 160 RecordLibraryPreloaderRendereHistogram(); |
| 155 } | 161 } |
| 156 | 162 |
| 157 void SetLibraryLoadedHook(LibraryLoadedHook* func) { | 163 void SetLibraryLoadedHook(LibraryLoadedHook* func) { |
| 158 g_registration_callback = func; | 164 g_registration_callback = func; |
| 159 } | 165 } |
| 160 | 166 |
| 161 static void InitCommandLine( | 167 static void InitCommandLine( |
| 162 JNIEnv* env, | 168 JNIEnv* env, |
| 163 const JavaParamRef<jobject>& jcaller, | 169 const JavaParamRef<jobject>& jcaller, |
| 164 const JavaParamRef<jobjectArray>& init_command_line) { | 170 const JavaParamRef<jobjectArray>& init_command_line) { |
| 165 InitNativeCommandLineFromJavaArray(env, init_command_line); | 171 InitNativeCommandLineFromJavaArray(env, init_command_line); |
| 166 } | 172 } |
| 167 | 173 |
| 168 static jboolean LibraryLoaded(JNIEnv* env, | 174 static jboolean LibraryLoaded(JNIEnv* env, |
| 169 const JavaParamRef<jobject>& jcaller) { | 175 const JavaParamRef<jobject>& jcaller) { |
| 176 if (g_native_initialization_hook && !g_native_initialization_hook()) { | |
| 177 return false; | |
| 178 } | |
| 170 if (g_registration_callback == NULL) { | 179 if (g_registration_callback == NULL) { |
|
Torne
2017/01/03 12:13:50
g_registration_callback already appears to be the
Tobias Sargeant
2017/01/04 00:24:53
I started doing this, and removing the callback ch
| |
| 171 return true; | 180 return true; |
| 172 } | 181 } |
| 173 return g_registration_callback(env, NULL); | 182 return g_registration_callback(env, NULL); |
| 174 } | 183 } |
| 175 | 184 |
| 176 void LibraryLoaderExitHook() { | 185 void LibraryLoaderExitHook() { |
| 177 if (g_at_exit_manager) { | 186 if (g_at_exit_manager) { |
| 178 delete g_at_exit_manager; | 187 delete g_at_exit_manager; |
| 179 g_at_exit_manager = NULL; | 188 g_at_exit_manager = NULL; |
| 180 } | 189 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 210 return static_cast<LibraryProcessType>( | 219 return static_cast<LibraryProcessType>( |
| 211 Java_LibraryLoader_getLibraryProcessType(env)); | 220 Java_LibraryLoader_getLibraryProcessType(env)); |
| 212 } | 221 } |
| 213 | 222 |
| 214 void InitAtExitManager() { | 223 void InitAtExitManager() { |
| 215 g_at_exit_manager = new base::AtExitManager(); | 224 g_at_exit_manager = new base::AtExitManager(); |
| 216 } | 225 } |
| 217 | 226 |
| 218 } // namespace android | 227 } // namespace android |
| 219 } // namespace base | 228 } // namespace base |
| OLD | NEW |