library_loader_hooks.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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
  3. // found in the LICENSE file.
  4. #ifndef BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOADER_HOOKS_H_
  5. #define BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOADER_HOOKS_H_
  6. #include <jni.h>
  7. #include "base/base_export.h"
  8. #include "base/callback.h"
  9. #include "base/command_line.h"
  10. #include "base/metrics/field_trial.h"
  11. namespace base {
  12. namespace android {
  13. // The process the shared library is loaded in.
  14. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.base.library_loader
  15. enum LibraryProcessType {
  16. // The LibraryLoad has not been initialized.
  17. PROCESS_UNINITIALIZED = 0,
  18. // Shared library is running in browser process.
  19. PROCESS_BROWSER = 1,
  20. // Shared library is running in child process.
  21. PROCESS_CHILD = 2,
  22. // Shared library is running in the app that uses webview.
  23. PROCESS_WEBVIEW = 3,
  24. // Shared library is running in child process as part of webview.
  25. PROCESS_WEBVIEW_CHILD = 4,
  26. // Shared library is running in the app that uses weblayer.
  27. PROCESS_WEBLAYER = 5,
  28. // Shared library is running in child process as part of weblayer.
  29. PROCESS_WEBLAYER_CHILD = 6,
  30. };
  31. // Returns the library process type this library was loaded for.
  32. BASE_EXPORT LibraryProcessType GetLibraryProcessType();
  33. // Whether fewer code should be prefetched, and no-readahead should be set.
  34. // Returns true on low-end devices, where this speeds up startup, and false
  35. // elsewhere, where it slows it down. See
  36. // https://bugs.chromium.org/p/chromium/issues/detail?id=758566#c71 for details.
  37. BASE_EXPORT bool IsUsingOrderfileOptimization();
  38. typedef bool NativeInitializationHook(LibraryProcessType library_process_type);
  39. BASE_EXPORT void SetNativeInitializationHook(
  40. NativeInitializationHook native_initialization_hook);
  41. typedef void NonMainDexJniRegistrationHook();
  42. BASE_EXPORT void SetNonMainDexJniRegistrationHook(
  43. NonMainDexJniRegistrationHook jni_registration_hook);
  44. // Record any pending renderer histogram value as histograms. Pending values
  45. // are set by
  46. // JNI_LibraryLoader_RegisterChromiumAndroidLinkerRendererHistogram().
  47. BASE_EXPORT void RecordLibraryLoaderRendererHistograms();
  48. // Typedef for hook function to be called (indirectly from Java) once the
  49. // libraries are loaded. The hook function should register the JNI bindings
  50. // required to start the application. It should return true for success and
  51. // false for failure.
  52. // Note: this can't use base::Callback because there is no way of initializing
  53. // the default callback without using static objects, which we forbid.
  54. typedef bool LibraryLoadedHook(JNIEnv* env,
  55. jclass clazz,
  56. LibraryProcessType library_process_type);
  57. // Set the hook function to be called (from Java) once the libraries are loaded.
  58. // SetLibraryLoadedHook may only be called from JNI_OnLoad. The hook function
  59. // should register the JNI bindings required to start the application.
  60. BASE_EXPORT void SetLibraryLoadedHook(LibraryLoadedHook* func);
  61. // Pass the version name to the loader. This used to check that the library
  62. // version matches the version expected by Java before completing JNI
  63. // registration.
  64. // Note: argument must remain valid at least until library loading is complete.
  65. BASE_EXPORT void SetVersionNumber(const char* version_number);
  66. // Call on exit to delete the AtExitManager which OnLibraryLoadedOnUIThread
  67. // created.
  68. BASE_EXPORT void LibraryLoaderExitHook();
  69. // Initialize AtExitManager, this must be done at the begining of loading
  70. // shared library.
  71. void InitAtExitManager();
  72. } // namespace android
  73. } // namespace base
  74. #endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOADER_HOOKS_H_