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
,
63 const JavaParamRef
<jclass
>& clazz
,
64 const JavaParamRef
<jobject
>& jcontext
) {
65 base::android::InitApplicationContext(env
, jcontext
);
67 // TODO(dtrainor): Start the runner?
71 static jboolean
StartBlimp(JNIEnv
* env
, const JavaParamRef
<jclass
>& clazz
) {
72 // TODO(dtrainor): Initialize ICU?
74 if (!gfx::GLSurface::InitializeOneOff())
77 g_main_message_loop
.Get().reset(new base::MessageLoopForUI
);
78 base::MessageLoopForUI::current()->Start();
83 bool RegisterBlimpLibraryLoaderJni(JNIEnv
* env
) {
84 return RegisterNativesImpl(env
);
89 JNI_EXPORT jint
JNI_OnLoad(JavaVM
* vm
, void* reserved
) {
90 std::vector
<base::android::RegisterCallback
> register_callbacks
;
91 register_callbacks
.push_back(base::Bind(&RegisterJni
));
93 std::vector
<base::android::InitCallback
> init_callbacks
;
94 init_callbacks
.push_back(base::Bind(&OnJniInitializationComplete
));
96 // Although we only need to register JNI for base/ and blimp/, this follows
97 // the general Chrome for Android pattern, to be future-proof against future
99 if (!base::android::OnJNIOnLoadRegisterJNI(vm
, register_callbacks
) ||
100 !base::android::OnJNIOnLoadInit(init_callbacks
)) {
104 return JNI_VERSION_1_4
;