Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / cronet / android / cronet_jni.cc
blob890649a183a7496a9673f8c2ed3471d4de543d10
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.
5 #include "base/android/base_jni_registrar.h"
6 #include "base/android/jni_android.h"
7 #include "base/android/jni_registrar.h"
8 #include "base/at_exit.h"
9 #include "components/cronet/android/chromium_url_request.h"
10 #include "components/cronet/android/chromium_url_request_context.h"
11 #include "net/android/net_jni_registrar.h"
12 #include "url/android/url_jni_registrar.h"
14 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID)
15 #include "base/i18n/icu_util.h"
16 #endif
18 namespace {
20 const base::android::RegistrationMethod kCronetRegisteredMethods[] = {
21 {"BaseAndroid", base::android::RegisterJni},
22 {"ChromiumUrlRequest", cronet::ChromiumUrlRequestRegisterJni},
23 {"ChromiumUrlRequestContext", cronet::ChromiumUrlRequestContextRegisterJni},
24 {"NetAndroid", net::android::RegisterJni},
25 {"UrlAndroid", url::android::RegisterJni},
28 base::AtExitManager* g_at_exit_manager = NULL;
30 } // namespace
32 // Checks the available version of JNI. Also, caches Java reflection artifacts.
33 extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) {
34 JNIEnv* env;
35 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
36 return -1;
39 base::android::InitVM(vm);
41 if (!base::android::RegisterNativeMethods(
42 env, kCronetRegisteredMethods, arraysize(kCronetRegisteredMethods))) {
43 return -1;
46 g_at_exit_manager = new base::AtExitManager();
48 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID)
49 base::i18n::InitializeICU();
50 #endif
52 return JNI_VERSION_1_6;
55 extern "C" void JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM* jvm, void* reserved) {
56 if (g_at_exit_manager) {
57 delete g_at_exit_manager;
58 g_at_exit_manager = NULL;