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/base_jni_registrar.h" | 5 #include <vector> |
6 | |
7 #include "base/android/base_jni_onload.h" | |
6 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/library_loader/library_loader_hooks.h" | |
10 #include "base/bind.h" | |
7 #include "net/android/net_jni_registrar.h" | 11 #include "net/android/net_jni_registrar.h" |
8 | 12 |
13 namespace { | |
14 bool RegisterJNI(JNIEnv* env) { | |
15 return net::android::RegisterJni(env); | |
16 } | |
17 | |
18 bool Init() { | |
19 return true; | |
20 } | |
21 } // namespace | |
22 | |
23 | |
24 // This is called by the VM when the shared library is first loaded. | |
9 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 25 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
10 base::android::InitVM(vm); | 26 std::vector<base::android::RegisterCallback> register_callbacks; |
11 JNIEnv* env = base::android::AttachCurrentThread(); | 27 register_callbacks.push_back(base::Bind(&RegisterJNI)); |
12 | 28 |
13 if (!base::android::RegisterJni(env)) | 29 std::vector<base::android::InitCallback> init_callbacks; |
30 init_callbacks.push_back(base::Bind(&Init)); | |
31 | |
32 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || | |
33 !base::android::OnJNIOnLoadInit(init_callbacks)) { | |
14 return -1; | 34 return -1; |
35 } | |
15 | 36 |
16 if (!net::android::RegisterJni(env)) | 37 // There cannot be two AtExitManagers at the same time. Remove the one from |
17 return -1; | 38 // LibraryLoader as ApplicationRunnerChromium also uses one. |
39 base::android::LibraryLoaderExitHook(); | |
michaelbai
2015/03/04 17:25:52
Why can't you use the AtExitManager created in bas
qsr
2015/03/04 17:28:59
We use the one in base, but we create it later on
| |
18 | 40 |
19 return JNI_VERSION_1_4; | 41 return JNI_VERSION_1_4; |
20 } | 42 } |
21 | 43 |
22 extern "C" JNI_EXPORT void InitApplicationContext( | 44 extern "C" JNI_EXPORT void InitApplicationContext( |
23 const base::android::JavaRef<jobject>& context) { | 45 const base::android::JavaRef<jobject>& context) { |
24 JNIEnv* env = base::android::AttachCurrentThread(); | 46 JNIEnv* env = base::android::AttachCurrentThread(); |
25 base::android::InitApplicationContext(env, context); | 47 base::android::InitApplicationContext(env, context); |
26 } | 48 } |
OLD | NEW |