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.
5 #include "blimp/client/android/blimp_library_loader.h"
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"
23 base::LazyInstance
<scoped_ptr
<base::MessageLoopForUI
>> g_main_message_loop
=
24 LAZY_INSTANCE_INITIALIZER
;
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
);
31 // Disable process info prefixes on log lines. These can be obtained via "adb
32 // logcat -v threadtime".
33 logging::SetLogItems(false, // Process ID
37 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel()
38 << ", default verbosity = " << logging::GetVlogVerbosity();
43 bool OnJniInitializationComplete() {
44 base::android::SetLibraryLoadedHook(&OnLibrariesLoaded
);
48 bool RegisterJni(JNIEnv
* env
) {
49 if (!base::android::RegisterJni(env
))
52 if (!blimp::RegisterBlimpJni(env
))
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
);
66 // TODO(dtrainor): Start the runner?
70 static jboolean
StartBlimp(JNIEnv
* env
, jclass clazz
) {
71 // TODO(dtrainor): Initialize ICU?
73 if (!gfx::GLSurface::InitializeOneOff())
76 g_main_message_loop
.Get().reset(new base::MessageLoopForUI
);
77 base::MessageLoopForUI::current()->Start();
82 bool RegisterBlimpLibraryLoaderJni(JNIEnv
* env
) {
83 return RegisterNativesImpl(env
);
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
));
92 std::vector
<base::android::InitCallback
> init_callbacks
;
93 init_callbacks
.push_back(base::Bind(&OnJniInitializationComplete
));
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
98 if (!base::android::OnJNIOnLoadRegisterJNI(vm
, register_callbacks
) ||
99 !base::android::OnJNIOnLoadInit(init_callbacks
)) {
103 return JNI_VERSION_1_4
;