library_loader_hooks.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // Shared library is running in a non-embedded WebView process.
  31. PROCESS_WEBVIEW_NONEMBEDDED = 7,
  32. };
  33. // Returns the library process type this library was loaded for.
  34. BASE_EXPORT LibraryProcessType GetLibraryProcessType();
  35. // Whether fewer code should be prefetched, and no-readahead should be set.
  36. // Returns true on low-end devices, where this speeds up startup, and false
  37. // elsewhere, where it slows it down. See
  38. // https://bugs.chromium.org/p/chromium/issues/detail?id=758566#c71 for details.
  39. BASE_EXPORT bool IsUsingOrderfileOptimization();
  40. typedef bool NativeInitializationHook(LibraryProcessType library_process_type);
  41. BASE_EXPORT void SetNativeInitializationHook(
  42. NativeInitializationHook native_initialization_hook);
  43. typedef void NonMainDexJniRegistrationHook();
  44. BASE_EXPORT void SetNonMainDexJniRegistrationHook(
  45. NonMainDexJniRegistrationHook jni_registration_hook);
  46. // Record any pending renderer histogram value as histograms. Pending values
  47. // are set by
  48. // JNI_LibraryLoader_RegisterChromiumAndroidLinkerRendererHistogram().
  49. BASE_EXPORT void RecordLibraryLoaderRendererHistograms();
  50. // Typedef for hook function to be called (indirectly from Java) once the
  51. // libraries are loaded. The hook function should register the JNI bindings
  52. // required to start the application. It should return true for success and
  53. // false for failure.
  54. // Note: this can't use base::{Once, Repeating}Callback because there is no
  55. // way of initializing the default callback without using static objects, which
  56. // we forbid.
  57. typedef bool LibraryLoadedHook(JNIEnv* env,
  58. jclass clazz,
  59. LibraryProcessType library_process_type);
  60. // Set the hook function to be called (from Java) once the libraries are loaded.
  61. // SetLibraryLoadedHook may only be called from JNI_OnLoad. The hook function
  62. // should register the JNI bindings required to start the application.
  63. BASE_EXPORT void SetLibraryLoadedHook(LibraryLoadedHook* func);
  64. // Call on exit to delete the AtExitManager which OnLibraryLoadedOnUIThread
  65. // created.
  66. BASE_EXPORT void LibraryLoaderExitHook();
  67. // Initialize AtExitManager, this must be done at the begining of loading
  68. // shared library.
  69. void InitAtExitManager();
  70. } // namespace android
  71. } // namespace base
  72. #endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOADER_HOOKS_H_