Chromium Code Reviews| Index: blimp/client/android/blimp_library_loader.cc |
| diff --git a/blimp/client/android/blimp_library_loader.cc b/blimp/client/android/blimp_library_loader.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f558e025bb4487efd997fa10b919098f18501c19 |
| --- /dev/null |
| +++ b/blimp/client/android/blimp_library_loader.cc |
| @@ -0,0 +1,88 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "blimp/client/android/blimp_library_loader.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/android/base_jni_onload.h" |
| +#include "base/android/jni_android.h" |
| +#include "base/android/library_loader/library_loader_hooks.h" |
| +#include "base/bind.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/logging.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "blimp/client/android/blimp_jni_registrar.h" |
| +#include "jni/BlimpLibraryLoader_jni.h" |
| +#include "ui/gl/gl_surface.h" |
| + |
| +namespace { |
| + |
| +base::LazyInstance<scoped_ptr<base::MessageLoopForUI>> g_main_message_loop = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +bool LibraryLoaded(JNIEnv* env, jclass clazz) { |
|
Wez
2015/08/27 02:01:50
nit: OnLibrariesLoaded (to fit the description of
David Trainor- moved to gerrit
2015/08/28 01:23:45
Done.
|
| + logging::LoggingSettings settings; |
| + settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| + logging::InitLogging(settings); |
| + // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
|
Wez
2015/08/27 02:01:50
nit: Prefer to have a blank line before comments,
David Trainor- moved to gerrit
2015/08/28 01:23:45
Done.
|
| + logging::SetLogItems(false, // Process ID |
| + false, // Thread ID |
| + false, // Timestamp |
| + false); // Tick count |
| + VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() |
|
Wez
2015/08/27 02:01:50
nit: is "chromium" useful info here? is logging th
David Trainor- moved to gerrit
2015/08/28 01:23:45
I want to try to stay consistent with the rest of
Wez
2015/09/03 00:49:26
Acknowledged.
|
| + << ", default verbosity = " << logging::GetVlogVerbosity(); |
| + |
| + return true; |
| +} |
| + |
| +bool InitBlimp() { |
|
Wez
2015/08/27 02:01:50
Can we name this something more helpful, e.g. OnJn
David Trainor- moved to gerrit
2015/08/28 01:23:45
Yeah that sounds cleaner. Changed.
|
| + base::android::SetLibraryLoadedHook(&LibraryLoaded); |
| + return true; |
| +} |
| + |
| +} // namespace |
| + |
| +namespace blimp { |
| + |
| +static jboolean InitializeBlimp(JNIEnv* env, jclass clazz, jobject jcontext) { |
|
Wez
2015/08/27 02:01:50
Let's not have InitBlimp _and_ InitializeBlimp her
David Trainor- moved to gerrit
2015/08/28 01:23:45
This is called from java (notice the JNIEnv*, and
Wez
2015/09/03 00:49:26
Acknowledged.
|
| + base::android::ScopedJavaLocalRef<jobject> scoped_jcontext(env, jcontext); |
| + base::android::InitApplicationContext(env, scoped_jcontext); |
| + |
| + // TODO(dtrainor): Start the runner? |
| + return true; |
| +} |
| + |
| +static jboolean StartBlimp(JNIEnv* env, jclass clazz) { |
|
Wez
2015/08/27 02:01:50
This doesn't seem to be called from anywhere, nor
David Trainor- moved to gerrit
2015/08/28 01:23:45
See Java comment above.
|
| + // TODO(dtrainor): Initialize ICU? |
| + |
| + if (!gfx::GLSurface::InitializeOneOff()) |
| + return false; |
| + |
| + g_main_message_loop.Get().reset(new base::MessageLoopForUI); |
| + base::MessageLoopForUI::current()->Start(); |
| + |
| + return true; |
| +} |
| + |
| +bool RegisterBlimpLibraryLoaderJni(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +} // namespace blimp |
| + |
| +JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
| + std::vector<base::android::RegisterCallback> register_callbacks; |
| + register_callbacks.push_back(base::Bind(&blimp::RegisterBlimpJni)); |
| + |
| + std::vector<base::android::InitCallback> init_callbacks; |
| + init_callbacks.push_back(base::Bind(&InitBlimp)); |
| + |
| + if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || |
| + !base::android::OnJNIOnLoadInit(init_callbacks)) { |
|
Wez
2015/08/27 02:01:50
This OnJNIOnLoadInit() stuff is strangely obfuscat
David Trainor- moved to gerrit
2015/08/28 01:23:45
I'd rather not bypass the basic work flow (althoug
Wez
2015/09/03 00:49:26
Acknowledged, but perhaps include a comment to cla
David Trainor- moved to gerrit
2015/09/03 06:33:21
Done.
|
| + return -1; |
| + } |
| + |
| + return JNI_VERSION_1_4; |
| +} |