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_onload.h" | 5 #include "base/android/base_jni_onload.h" |
6 #include "base/android/base_jni_registrar.h" | 6 #include "base/android/base_jni_registrar.h" |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_registrar.h" | 8 #include "base/android/jni_registrar.h" |
| 9 #include "base/android/library_loader/library_loader_hooks.h" |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "mojo/android/javatests/mojo_test_case.h" | 11 #include "mojo/android/javatests/mojo_test_case.h" |
11 #include "mojo/android/javatests/validation_test_util.h" | 12 #include "mojo/android/javatests/validation_test_util.h" |
12 #include "mojo/android/system/core_impl.h" | 13 #include "mojo/android/system/core_impl.h" |
13 #include "mojo/android/system/watcher_impl.h" | 14 #include "mojo/android/system/watcher_impl.h" |
14 #include "mojo/edk/embedder/embedder.h" | 15 #include "mojo/edk/embedder/embedder.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 base::android::RegistrationMethod kMojoRegisteredMethods[] = { | 19 base::android::RegistrationMethod kMojoRegisteredMethods[] = { |
19 {"CoreImpl", mojo::android::RegisterCoreImpl}, | 20 {"CoreImpl", mojo::android::RegisterCoreImpl}, |
20 {"MojoTestCase", mojo::android::RegisterMojoTestCase}, | 21 {"MojoTestCase", mojo::android::RegisterMojoTestCase}, |
21 {"ValidationTestUtil", mojo::android::RegisterValidationTestUtil}, | 22 {"ValidationTestUtil", mojo::android::RegisterValidationTestUtil}, |
22 {"WatcherImpl", mojo::android::RegisterWatcherImpl}, | 23 {"WatcherImpl", mojo::android::RegisterWatcherImpl}, |
23 }; | 24 }; |
24 | 25 |
25 bool RegisterJNI(JNIEnv* env) { | 26 bool RegisterJNI() { |
| 27 JNIEnv* env = base::android::AttachCurrentThread(); |
26 return base::android::RegisterJni(env) && | 28 return base::android::RegisterJni(env) && |
27 RegisterNativeMethods(env, kMojoRegisteredMethods, | 29 RegisterNativeMethods(env, kMojoRegisteredMethods, |
28 arraysize(kMojoRegisteredMethods)); | 30 arraysize(kMojoRegisteredMethods)); |
29 } | 31 } |
30 | 32 |
31 bool Init() { | 33 bool NativeInit() { |
| 34 if (!base::android::OnJNIOnLoadInit()) |
| 35 return false; |
| 36 |
32 mojo::edk::Init(); | 37 mojo::edk::Init(); |
33 return true; | 38 return true; |
34 } | 39 } |
35 | 40 |
36 } // namespace | 41 } // namespace |
37 | 42 |
38 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 43 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
39 std::vector<base::android::RegisterCallback> register_callbacks; | 44 if (!base::android::OnJNIOnLoadRegisterJNI(vm) || !RegisterJNI() || |
40 register_callbacks.push_back(base::Bind(&RegisterJNI)); | 45 !NativeInit()) { |
41 std::vector<base::android::InitCallback> init_callbacks; | |
42 init_callbacks.push_back(base::Bind(&Init)); | |
43 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || | |
44 !base::android::OnJNIOnLoadInit(init_callbacks)) | |
45 return -1; | 46 return -1; |
46 | 47 } |
47 return JNI_VERSION_1_4; | 48 return JNI_VERSION_1_4; |
48 } | 49 } |
OLD | NEW |