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 LibraryLoaded(JNIEnv* env, jclass clazz) { |
| 27 logging::LoggingSettings settings; |
| 28 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 29 logging::InitLogging(settings); |
| 30 // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
| 31 logging::SetLogItems(false, // Process ID |
| 32 false, // Thread ID |
| 33 false, // Timestamp |
| 34 false); // Tick count |
| 35 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() |
| 36 << ", default verbosity = " << logging::GetVlogVerbosity(); |
| 37 |
| 38 return true; |
| 39 } |
| 40 |
| 41 bool InitBlimp() { |
| 42 base::android::SetLibraryLoadedHook(&LibraryLoaded); |
| 43 return true; |
| 44 } |
| 45 |
| 46 bool RegisterJni(JNIEnv* env) { |
| 47 if (!base::android::RegisterJni(env)) |
| 48 return false; |
| 49 |
| 50 if (!blimp::RegisterBlimpJni(env)) |
| 51 return false; |
| 52 |
| 53 return true; |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 |
| 58 namespace blimp { |
| 59 |
| 60 static jboolean InitializeBlimp(JNIEnv* env, jclass clazz, jobject jcontext) { |
| 61 base::android::ScopedJavaLocalRef<jobject> scoped_jcontext(env, jcontext); |
| 62 base::android::InitApplicationContext(env, scoped_jcontext); |
| 63 |
| 64 // TODO(dtrainor): Start the runner? |
| 65 return true; |
| 66 } |
| 67 |
| 68 static jboolean StartBlimp(JNIEnv* env, jclass clazz) { |
| 69 // TODO(dtrainor): Initialize ICU? |
| 70 |
| 71 if (!gfx::GLSurface::InitializeOneOff()) |
| 72 return false; |
| 73 |
| 74 g_main_message_loop.Get().reset(new base::MessageLoopForUI); |
| 75 base::MessageLoopForUI::current()->Start(); |
| 76 |
| 77 return true; |
| 78 } |
| 79 |
| 80 bool RegisterBlimpLibraryLoaderJni(JNIEnv* env) { |
| 81 return RegisterNativesImpl(env); |
| 82 } |
| 83 |
| 84 } // namespace blimp |
| 85 |
| 86 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
| 87 std::vector<base::android::RegisterCallback> register_callbacks; |
| 88 register_callbacks.push_back(base::Bind(&RegisterJni)); |
| 89 |
| 90 std::vector<base::android::InitCallback> init_callbacks; |
| 91 init_callbacks.push_back(base::Bind(&InitBlimp)); |
| 92 |
| 93 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || |
| 94 !base::android::OnJNIOnLoadInit(init_callbacks)) { |
| 95 return -1; |
| 96 } |
| 97 |
| 98 return JNI_VERSION_1_4; |
| 99 } |
OLD | NEW |