summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authormichaelbai <michaelbai@chromium.org>2015-02-20 17:29:40 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-21 01:30:05 +0000
commit5237cb89a8fc1a743b483bc2be5cdbe9669d9d86 (patch)
tree4aad0ee6b83360548c3e41102e25dade25207367 /base
parenta881d1ae8a3e7196d19138b677d96835ce8322ed (diff)
downloadchromium_src-5237cb89a8fc1a743b483bc2be5cdbe9669d9d86.zip
chromium_src-5237cb89a8fc1a743b483bc2be5cdbe9669d9d86.tar.gz
chromium_src-5237cb89a8fc1a743b483bc2be5cdbe9669d9d86.tar.bz2
Separate OnJNIOnLoad
Separate it into OnJNIOnLoadRegisterJNI() and OnJNIOnLoadInit(), so they could be called by embedder when needed. BUG=447393 Review URL: https://codereview.chromium.org/935413004 Cr-Commit-Position: refs/heads/master@{#317479}
Diffstat (limited to 'base')
-rw-r--r--base/BUILD.gn1
-rw-r--r--base/android/base_jni_onload.cc52
-rw-r--r--base/android/base_jni_onload.h19
-rw-r--r--base/android/jni_onload_delegate.h41
-rw-r--r--base/base.gypi1
5 files changed, 31 insertions, 83 deletions
diff --git a/base/BUILD.gn b/base/BUILD.gn
index 0148656..c63d377 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -42,7 +42,6 @@ component("base") {
"android/jni_android.h",
"android/jni_array.cc",
"android/jni_array.h",
- "android/jni_onload_delegate.h",
"android/jni_registrar.cc",
"android/jni_registrar.h",
"android/jni_string.cc",
diff --git a/base/android/base_jni_onload.cc b/base/android/base_jni_onload.cc
index 3f8fa93..c3a65d4 100644
--- a/base/android/base_jni_onload.cc
+++ b/base/android/base_jni_onload.cc
@@ -5,65 +5,51 @@
#include "base/android/base_jni_onload.h"
#include "base/android/jni_android.h"
-#include "base/android/jni_onload_delegate.h"
#include "base/android/jni_utils.h"
#include "base/android/library_loader/library_loader_hooks.h"
+#include "base/bind.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) {
+bool RegisterJNI(JNIEnv* env) {
return RegisterLibraryLoaderEntryHook(env);
}
-bool BaseJNIOnLoadDelegate::Init() {
+bool Init() {
JNIEnv* env = base::android::AttachCurrentThread();
-
base::android::InitReplacementClassLoader(env,
base::android::GetClassLoader(env));
-
return true;
}
} // namespace
-bool OnJNIOnLoad(JavaVM* vm,
- std::vector<JNIOnLoadDelegate*>* delegates) {
+bool OnJNIOnLoadRegisterJNI(JavaVM* vm,
+ std::vector<RegisterCallback> callbacks) {
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;
- }
+ callbacks.push_back(base::Bind(&RegisterJNI));
+ for (std::vector<RegisterCallback>::reverse_iterator i =
+ callbacks.rbegin(); i != callbacks.rend(); ++i) {
+ if (!i->Run(env))
+ return false;
}
+ return true;
+}
- if (ret) {
- for (std::vector<JNIOnLoadDelegate*>::reverse_iterator i =
- delegates->rbegin(); i != delegates->rend(); ++i) {
- if (!(*i)->Init()) {
- ret = false;
- break;
- }
- }
+bool OnJNIOnLoadInit(std::vector<InitCallback> callbacks) {
+ callbacks.push_back(base::Bind(&Init));
+ for (std::vector<InitCallback>::reverse_iterator i =
+ callbacks.rbegin(); i != callbacks.rend(); ++i) {
+ if (!i->Run())
+ return false;
}
- delegates->pop_back();
- return ret;
+ return true;
}
} // namespace android
diff --git a/base/android/base_jni_onload.h b/base/android/base_jni_onload.h
index f3f05fa..dcc7756 100644
--- a/base/android/base_jni_onload.h
+++ b/base/android/base_jni_onload.h
@@ -9,17 +9,22 @@
#include <vector>
#include "base/base_export.h"
+#include "base/callback.h"
namespace base {
namespace android {
-class JNIOnLoadDelegate;
-
-// Returns whether JNI registration and initialization succeeded. Caller shall
-// put the JNIOnLoadDelegate into |delegates| in reverse order. Refer
-// JNIOnLoadDelegate for more information.
-BASE_EXPORT bool OnJNIOnLoad(JavaVM* vm,
- std::vector<JNIOnLoadDelegate*>* delegates);
+// Returns whether JNI registration succeeded. Caller shall put the
+// RegisterCallback into |callbacks| in reverse order.
+typedef base::Callback<bool(JNIEnv*)> RegisterCallback;
+BASE_EXPORT bool OnJNIOnLoadRegisterJNI(
+ JavaVM* vm,
+ std::vector<RegisterCallback> callbacks);
+
+// Returns whether initialization succeeded. Caller shall put the
+// InitCallback into |callbacks| in reverse order.
+typedef base::Callback<bool(void)> InitCallback;
+BASE_EXPORT bool OnJNIOnLoadInit(std::vector<InitCallback> callbacks);
} // namespace android
} // namespace base
diff --git a/base/android/jni_onload_delegate.h b/base/android/jni_onload_delegate.h
deleted file mode 100644
index ef1b137..0000000
--- a/base/android/jni_onload_delegate.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// 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.
-
-#ifndef BASE_ANDROID_JNI_ONLOAD_DELEGATE_H_
-#define BASE_ANDROID_JNI_ONLOAD_DELEGATE_H_
-
-#include <jni.h>
-
-#include "base/base_export.h"
-
-namespace base {
-namespace android {
-
-// This delegate class is used to implement component specific JNI registration
-// and initialization. All methods are called in JNI_OnLoad().
-//
-// Both RegisterJNI() and Init() methods are called if the shared library
-// is loaded by crazy linker that can't find JNI methods without JNI
-// registration, otherwise, only Init() is invoked where dynamic lookup is
-// used to find the JNI methods.
-//
-// It is important to make sure the JNI registration code is only in
-// RegisterJNI(), so it could be stripped out when JNI registration isn't
-// needed.
-class BASE_EXPORT JNIOnLoadDelegate {
- public:
- virtual ~JNIOnLoadDelegate() {}
-
- // Returns whether the JNI registration succeeded.
- virtual bool RegisterJNI(JNIEnv* env) = 0;
-
- // Returns whether the initialization succeeded. This method is called after
- // RegisterJNI(), all JNI methods shall ready to be used.
- virtual bool Init() = 0;
-};
-
-} // namespace android
-} // namespace base
-
-#endif // BASE_ANDROID_JNI_ONLOAD_DELEGATE_H_
diff --git a/base/base.gypi b/base/base.gypi
index 05364ab8..b7c33b8 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -44,7 +44,6 @@
'android/jni_android.h',
'android/jni_array.cc',
'android/jni_array.h',
- 'android/jni_onload_delegate.h',
'android/jni_registrar.cc',
'android/jni_registrar.h',
'android/jni_string.cc',