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.
7 #include "base/android/base_jni_onload.h"
8 #include "base/android/jni_android.h"
9 #include "base/android/library_loader/library_loader_hooks.h"
10 #include "base/bind.h"
11 #include "components/resource_provider/jni/Main_jni.h"
12 #include "net/android/net_jni_registrar.h"
15 bool RegisterJNI(JNIEnv
* env
) {
16 return net::android::RegisterJni(env
);
25 // This is called by the VM when the shared library is first loaded.
26 JNI_EXPORT jint
JNI_OnLoad(JavaVM
* vm
, void* reserved
) {
27 std::vector
<base::android::RegisterCallback
> register_callbacks
;
28 register_callbacks
.push_back(base::Bind(&RegisterJNI
));
29 register_callbacks
.push_back(
30 base::Bind(&resource_provider::RegisterNativesImpl
));
32 std::vector
<base::android::InitCallback
> init_callbacks
;
33 init_callbacks
.push_back(base::Bind(&Init
));
35 if (!base::android::OnJNIOnLoadRegisterJNI(vm
, register_callbacks
) ||
36 !base::android::OnJNIOnLoadInit(init_callbacks
)) {
40 // There cannot be two AtExitManagers at the same time. Remove the one from
41 // LibraryLoader as ApplicationRunnerChromium also uses one.
42 base::android::LibraryLoaderExitHook();
44 return JNI_VERSION_1_4
;
47 extern "C" JNI_EXPORT
void InitApplicationContext(
48 const base::android::JavaRef
<jobject
>& context
) {
49 JNIEnv
* env
= base::android::AttachCurrentThread();
50 base::android::InitApplicationContext(env
, context
);
51 resource_provider::Java_Main_init(
52 env
, base::android::GetApplicationContext());