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