cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / blimp / client / android / blimp_library_loader.cc
blobd479aeb4b67b455ba64a63396decd5a0e0995569
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"
7 #include <vector>
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"
21 namespace {
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
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();
40 return true;
43 bool OnJniInitializationComplete() {
44 base::android::SetLibraryLoadedHook(&OnLibrariesLoaded);
45 return true;
48 bool RegisterJni(JNIEnv* env) {
49 if (!base::android::RegisterJni(env))
50 return false;
52 if (!blimp::RegisterBlimpJni(env))
53 return false;
55 return true;
58 } // namespace
60 namespace blimp {
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?
67 return true;
70 static jboolean StartBlimp(JNIEnv* env, jclass clazz) {
71 // TODO(dtrainor): Initialize ICU?
73 if (!gfx::GLSurface::InitializeOneOff())
74 return false;
76 g_main_message_loop.Get().reset(new base::MessageLoopForUI);
77 base::MessageLoopForUI::current()->Start();
79 return true;
82 bool RegisterBlimpLibraryLoaderJni(JNIEnv* env) {
83 return RegisterNativesImpl(env);
86 } // namespace blimp
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
97 // changes to JNI.
98 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) ||
99 !base::android::OnJNIOnLoadInit(init_callbacks)) {
100 return -1;
103 return JNI_VERSION_1_4;