1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <jni.h> 6 7 #include "base/android/base_jni_registrar.h" 8 #include "base/android/jni_android.h" 9 #include "base/android/jni_registrar.h" 10 #include "components/cronet/android/cronet_loader.h" 11 #include "mock_url_request_job_test.h" 12 13 namespace { 14 15 const base::android::RegistrationMethod kCronetTestsRegisteredMethods[] = { 16 {"MockURLRequestJobTest", cronet::RegisterMockUrlRequestJobTest}, 17 }; 18 19 } // namespace 20 21 // This is called by the VM when the shared library is first loaded. 22 // Checks the available version of JNI. Also, caches Java reflection artifacts. 23 extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) { 24 JNIEnv* env; 25 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { 26 return -1; 27 } 28 29 jint cronet_onload = cronet::CronetOnLoad(vm, reserved); 30 if (cronet_onload == -1) 31 return cronet_onload; 32 33 if (!base::android::RegisterNativeMethods( 34 env, 35 kCronetTestsRegisteredMethods, 36 arraysize(kCronetTestsRegisteredMethods))) { 37 return -1; 38 } 39 return cronet_onload; 40 } 41 42 extern "C" void JNI_OnUnLoad(JavaVM* vm, void* reserved) { 43 cronet::CronetOnUnLoad(vm, reserved); 44 } 45 46