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

Unified Diff: base/android/base_jni_onload.cc

Issue 864563002: Separate JNI registration with initialization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments and sync Created 5 years, 11 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
« no previous file with comments | « base/android/base_jni_onload.h ('k') | base/android/jni_onload_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/base_jni_onload.cc
diff --git a/base/android/base_jni_onload.cc b/base/android/base_jni_onload.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ae64120902741e28a83f13f4f7da2e52e946bdd5
--- /dev/null
+++ b/base/android/base_jni_onload.cc
@@ -0,0 +1,64 @@
+// 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 "base/android/base_jni_onload.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_onload_delegate.h"
+#include "base/android/library_loader/library_loader_hooks.h"
+
+namespace base {
+namespace android {
+
+namespace {
+
+// The JNIOnLoadDelegate implementation in base.
+class BaseJNIOnLoadDelegate : public JNIOnLoadDelegate {
+ public:
+ bool RegisterJNI(JNIEnv* env) override;
+ bool Init() override;
+};
+
+bool BaseJNIOnLoadDelegate::RegisterJNI(JNIEnv* env) {
+ return RegisterLibraryLoaderEntryHook(env);
+}
+
+bool BaseJNIOnLoadDelegate::Init() {
+ return true;
+}
+
+} // namespace
+
+
+bool OnJNIOnLoad(JavaVM* vm,
+ std::vector<JNIOnLoadDelegate*>* delegates) {
+ base::android::InitVM(vm);
+ JNIEnv* env = base::android::AttachCurrentThread();
+
+ BaseJNIOnLoadDelegate delegate;
+ delegates->push_back(&delegate);
+ bool ret = true;
+ for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i =
+ delegates->rbegin(); i != delegates->rend(); ++i) {
+ if (!(*i)->RegisterJNI(env)) {
+ ret = false;
+ break;
+ }
+ }
+
+ if (ret) {
+ for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i =
+ delegates->rbegin(); i != delegates->rend(); ++i) {
+ if (!(*i)->Init()) {
+ ret = false;
+ break;
+ }
+ }
+ }
+ delegates->pop_back();
+ return ret;
+}
+
+} // namespace android
+} // namespace base
« no previous file with comments | « base/android/base_jni_onload.h ('k') | base/android/jni_onload_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698