OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/client/android/blimp_library_loader.h" | 5 #include "blimp/client/android/blimp_library_loader.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/android/base_jni_onload.h" | 9 #include "base/android/base_jni_onload.h" |
10 #include "base/android/base_jni_registrar.h" | 10 #include "base/android/base_jni_registrar.h" |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/library_loader/library_loader_hooks.h" | 12 #include "base/android/library_loader/library_loader_hooks.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "blimp/client/android/blimp_jni_registrar.h" | 15 #include "blimp/client/android/blimp_jni_registrar.h" |
16 #include "blimp/client/blimp_startup.h" | 16 #include "blimp/client/blimp_startup.h" |
17 #include "jni/BlimpLibraryLoader_jni.h" | 17 #include "jni/BlimpLibraryLoader_jni.h" |
18 #include "ui/gl/gl_surface.h" | 18 #include "ui/gl/gl_surface.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 bool OnLibrariesLoaded(JNIEnv* env, jclass clazz) { | 22 bool OnLibrariesLoaded(JNIEnv* env, jclass clazz) { |
23 blimp::InitializeLogging(); | 23 blimp::client::InitializeLogging(); |
24 return true; | 24 return true; |
25 } | 25 } |
26 | 26 |
27 bool OnJniInitializationComplete() { | 27 bool OnJniInitializationComplete() { |
28 base::android::SetLibraryLoadedHook(&OnLibrariesLoaded); | 28 base::android::SetLibraryLoadedHook(&OnLibrariesLoaded); |
29 return true; | 29 return true; |
30 } | 30 } |
31 | 31 |
32 bool RegisterJni(JNIEnv* env) { | 32 bool RegisterJni(JNIEnv* env) { |
33 if (!base::android::RegisterJni(env)) | 33 if (!base::android::RegisterJni(env)) |
34 return false; | 34 return false; |
35 | 35 |
36 if (!blimp::RegisterBlimpJni(env)) | 36 if (!blimp::client::RegisterBlimpJni(env)) |
37 return false; | 37 return false; |
38 | 38 |
39 return true; | 39 return true; |
40 } | 40 } |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 namespace blimp { | 44 namespace blimp { |
| 45 namespace client { |
45 | 46 |
46 static jboolean StartBlimp(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 47 static jboolean StartBlimp(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
47 if (!blimp::InitializeMainMessageLoop()) | 48 if (!InitializeMainMessageLoop()) |
48 return false; | 49 return false; |
49 | 50 |
50 base::MessageLoopForUI::current()->Start(); | 51 base::MessageLoopForUI::current()->Start(); |
51 | 52 |
52 return true; | 53 return true; |
53 } | 54 } |
54 | 55 |
55 bool RegisterBlimpLibraryLoaderJni(JNIEnv* env) { | 56 bool RegisterBlimpLibraryLoaderJni(JNIEnv* env) { |
56 return RegisterNativesImpl(env); | 57 return RegisterNativesImpl(env); |
57 } | 58 } |
58 | 59 |
| 60 } // namespace client |
59 } // namespace blimp | 61 } // namespace blimp |
60 | 62 |
61 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 63 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
62 std::vector<base::android::RegisterCallback> register_callbacks; | 64 std::vector<base::android::RegisterCallback> register_callbacks; |
63 register_callbacks.push_back(base::Bind(&RegisterJni)); | 65 register_callbacks.push_back(base::Bind(&RegisterJni)); |
64 | 66 |
65 std::vector<base::android::InitCallback> init_callbacks; | 67 std::vector<base::android::InitCallback> init_callbacks; |
66 init_callbacks.push_back(base::Bind(&OnJniInitializationComplete)); | 68 init_callbacks.push_back(base::Bind(&OnJniInitializationComplete)); |
67 | 69 |
68 // Although we only need to register JNI for base/ and blimp/, this follows | 70 // Although we only need to register JNI for base/ and blimp/, this follows |
69 // the general Chrome for Android pattern, to be future-proof against future | 71 // the general Chrome for Android pattern, to be future-proof against future |
70 // changes to JNI. | 72 // changes to JNI. |
71 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || | 73 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || |
72 !base::android::OnJNIOnLoadInit(init_callbacks)) { | 74 !base::android::OnJNIOnLoadInit(init_callbacks)) { |
73 return -1; | 75 return -1; |
74 } | 76 } |
75 | 77 |
76 return JNI_VERSION_1_4; | 78 return JNI_VERSION_1_4; |
77 } | 79 } |
OLD | NEW |