Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1610)

Unified Diff: blimp/client/android/blimp_library_loader.cc

Issue 1295243003: Initial commit of the blimp/ folder and target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address more nits Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c32a096367c2909cd98737ab4646bef8f2ac2ac9
--- /dev/null
+++ b/blimp/client/android/blimp_library_loader.cc
@@ -0,0 +1,104 @@
+// 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/base_jni_registrar.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 OnLibrariesLoaded(JNIEnv* env, jclass clazz) {
+ logging::LoggingSettings settings;
+ settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+ logging::InitLogging(settings);
+
+ // Disable process info prefixes on log lines. These can be obtained via "adb
+ // logcat -v threadtime".
+ logging::SetLogItems(false, // Process ID
+ false, // Thread ID
+ false, // Timestamp
+ false); // Tick count
+ VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel()
+ << ", default verbosity = " << logging::GetVlogVerbosity();
+
+ return true;
+}
+
+bool OnJniInitializationComplete() {
+ base::android::SetLibraryLoadedHook(&OnLibrariesLoaded);
+ return true;
+}
+
+bool RegisterJni(JNIEnv* env) {
+ if (!base::android::RegisterJni(env))
+ return false;
+
+ if (!blimp::RegisterBlimpJni(env))
+ return false;
+
+ return true;
+}
+
+} // namespace
+
+namespace blimp {
+
+static jboolean InitializeBlimp(JNIEnv* env, jclass clazz, jobject jcontext) {
+ 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) {
+ // 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(&RegisterJni));
+
+ std::vector<base::android::InitCallback> init_callbacks;
+ init_callbacks.push_back(base::Bind(&OnJniInitializationComplete));
+
+ // This is a little over-engineered here. Only base/ and blimp/ need to
+ // register JNI calls. But this follows the Chrome for Android pattern and
+ // calling these methods makes us future-proof for underlying JNI refactors.
Wez 2015/09/03 18:26:11 nit: I think: "Although we only need to register
David Trainor- moved to gerrit 2015/09/03 19:06:00 Done.
+ if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) ||
+ !base::android::OnJNIOnLoadInit(init_callbacks)) {
+ return -1;
+ }
+
+ return JNI_VERSION_1_4;
+}

Powered by Google App Engine
This is Rietveld 408576698