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/lazy_instance.h" |
| 15 #include "base/logging.h" |
| 16 #include "base/message_loop/message_loop.h" |
| 17 #include "blimp/client/android/blimp_jni_registrar.h" |
| 18 #include "jni/BlimpLibraryLoader_jni.h" |
| 19 #include "ui/gl/gl_surface.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 base::LazyInstance<scoped_ptr<base::MessageLoopForUI>> g_main_message_loop = |
| 24 LAZY_INSTANCE_INITIALIZER; |
| 25 |
| 26 bool OnLibrariesLoaded(JNIEnv* env, jclass clazz) { |
| 27 logging::LoggingSettings settings; |
| 28 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 29 logging::InitLogging(settings); |
| 30 |
| 31 // Disable process info prefixes on log lines. These can be obtained via "adb |
| 32 // logcat -v threadtime". |
| 33 logging::SetLogItems(false, // Process ID |
| 34 false, // Thread ID |
| 35 false, // Timestamp |
| 36 false); // Tick count |
| 37 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() |
| 38 << ", default verbosity = " << logging::GetVlogVerbosity(); |
| 39 |
| 40 return true; |
| 41 } |
| 42 |
| 43 bool OnJniInitializationComplete() { |
| 44 base::android::SetLibraryLoadedHook(&OnLibrariesLoaded); |
| 45 return true; |
| 46 } |
| 47 |
| 48 bool RegisterJni(JNIEnv* env) { |
| 49 if (!base::android::RegisterJni(env)) |
| 50 return false; |
| 51 |
| 52 if (!blimp::RegisterBlimpJni(env)) |
| 53 return false; |
| 54 |
| 55 return true; |
| 56 } |
| 57 |
| 58 } // namespace |
| 59 |
| 60 namespace blimp { |
| 61 |
| 62 static jboolean InitializeBlimp(JNIEnv* env, jclass clazz, jobject jcontext) { |
| 63 base::android::ScopedJavaLocalRef<jobject> scoped_jcontext(env, jcontext); |
| 64 base::android::InitApplicationContext(env, scoped_jcontext); |
| 65 |
| 66 // TODO(dtrainor): Start the runner? |
| 67 return true; |
| 68 } |
| 69 |
| 70 static jboolean StartBlimp(JNIEnv* env, jclass clazz) { |
| 71 // TODO(dtrainor): Initialize ICU? |
| 72 |
| 73 if (!gfx::GLSurface::InitializeOneOff()) |
| 74 return false; |
| 75 |
| 76 g_main_message_loop.Get().reset(new base::MessageLoopForUI); |
| 77 base::MessageLoopForUI::current()->Start(); |
| 78 |
| 79 return true; |
| 80 } |
| 81 |
| 82 bool RegisterBlimpLibraryLoaderJni(JNIEnv* env) { |
| 83 return RegisterNativesImpl(env); |
| 84 } |
| 85 |
| 86 } // namespace blimp |
| 87 |
| 88 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
| 89 std::vector<base::android::RegisterCallback> register_callbacks; |
| 90 register_callbacks.push_back(base::Bind(&RegisterJni)); |
| 91 |
| 92 std::vector<base::android::InitCallback> init_callbacks; |
| 93 init_callbacks.push_back(base::Bind(&OnJniInitializationComplete)); |
| 94 |
| 95 // Although we only need to register JNI for base/ and blimp/, this follows |
| 96 // the general Chrome for Android pattern, to be future-proof against future |
| 97 // changes to JNI. |
| 98 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || |
| 99 !base::android::OnJNIOnLoadInit(init_callbacks)) { |
| 100 return -1; |
| 101 } |
| 102 |
| 103 return JNI_VERSION_1_4; |
| 104 } |
OLD | NEW |