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

Unified Diff: components/cronet/android/test/cronet_tests_jni.cc

Issue 560153002: Add Cronet Test App that uses libcronet_tests.so with net test utilities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 6 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: components/cronet/android/test/cronet_tests_jni.cc
diff --git a/components/cronet/android/test/cronet_tests_jni.cc b/components/cronet/android/test/cronet_tests_jni.cc
new file mode 100644
index 0000000000000000000000000000000000000000..354ef9ab85e49e8a28bc29f12991e2f58ee32cd4
--- /dev/null
+++ b/components/cronet/android/test/cronet_tests_jni.cc
@@ -0,0 +1,44 @@
+// Copyright 2014 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 <jni.h>
+
+#include "base/android/base_jni_registrar.h"
+#include "base/android/jni_android.h"
+#include "base/android/jni_registrar.h"
+#include "components/cronet/android/cronet_loader.h"
+
+namespace {
+
+const base::android::RegistrationMethod kCronetTestsRegisteredMethods[] = {
+ {"BaseAndroid", base::android::RegisterJni},
+};
+
+} // namespace
+
+// This is called by the VM when the shared library is first loaded.
+// Checks the available version of JNI. Also, caches Java reflection artifacts.
+extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ JNIEnv* env;
+ if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
+ return -1;
+ }
+
+ jint cronet_onload = cronet::CronetOnLoad(vm, reserved);
+ if (cronet_onload == -1)
+ return cronet_onload;
+
+ if (!base::android::RegisterNativeMethods(
+ env,
+ kCronetTestsRegisteredMethods,
+ arraysize(kCronetTestsRegisteredMethods))) {
+ return -1;
+ }
+ return cronet_onload;
+}
+
+extern "C" void JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM* vm, void* reserved) {
xunjieli 2014/09/11 22:36:22 I think JNIEXPORT and JNICALL are not defined in c
xunjieli 2014/09/12 13:46:19 I still have one question about JNIEXPORT and JNI_
mef 2014/09/12 13:54:30 I think you are right and JNIEXPORT JNICALL are n
mef 2014/09/12 13:59:22 Done.
+ cronet::CronetOnUnLoad(vm, reserved);
+}
+
« no previous file with comments | « components/cronet/android/test/AndroidManifest.xml ('k') | components/cronet/android/test/javatests/AndroidManifest.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698