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