diff options
author | michaelbai <michaelbai@chromium.org> | 2015-01-28 13:40:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-28 21:41:51 +0000 |
commit | 842c972d5011ed671d2486deee78ae7640b0cca6 (patch) | |
tree | b868874a770f6c69579c5bd520b2f7cf225c8d73 /testing/android/native_test_jni_onload.cc | |
parent | 005229b167c1a9e415fc814520bf1d650adebb22 (diff) | |
download | chromium_src-842c972d5011ed671d2486deee78ae7640b0cca6.zip chromium_src-842c972d5011ed671d2486deee78ae7640b0cca6.tar.gz chromium_src-842c972d5011ed671d2486deee78ae7640b0cca6.tar.bz2 |
This is the first patch to separate JNI registration with initialization, currently, we have JNI_OnLoad defined multiple places which has a lot of
duplicated code and JNI registration and initialization are mixed;
This patch
- Added JNIOnLoadDelegate class for each component specific initialization.
- Added base::android::OnJNIOnLoad() to call a list of delegates
- Migrate testing, content_shell, chrome_shell.
BUG=447393
TBR=thakis
Review URL: https://codereview.chromium.org/864563002
Cr-Commit-Position: refs/heads/master@{#313592}
Diffstat (limited to 'testing/android/native_test_jni_onload.cc')
-rw-r--r-- | testing/android/native_test_jni_onload.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/testing/android/native_test_jni_onload.cc b/testing/android/native_test_jni_onload.cc new file mode 100644 index 0000000..bfab3c9 --- /dev/null +++ b/testing/android/native_test_jni_onload.cc @@ -0,0 +1,40 @@ +// 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 "testing/android/native_test_launcher.h" + +namespace { + +class NativeTestJNIOnLoadDelegate : public base::android::JNIOnLoadDelegate { + public: + bool RegisterJNI(JNIEnv* env) override; + bool Init() override; +}; + +bool NativeTestJNIOnLoadDelegate::RegisterJNI(JNIEnv* env) { + return RegisterNativeTestJNI(env); +} + +bool NativeTestJNIOnLoadDelegate::Init() { + InstallHandlers(); + return true; +} + +} // namespace + + +// This is called by the VM when the shared library is first loaded. +JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + NativeTestJNIOnLoadDelegate delegate; + std::vector<base::android::JNIOnLoadDelegate*> delegates; + delegates.push_back(&delegate); + + if (!base::android::OnJNIOnLoad(vm, &delegates)) + return -1; + + return JNI_VERSION_1_4; +} |