• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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/org_chromium_net_UrlRequest.h"
10 #include "components/cronet/android/org_chromium_net_UrlRequestContext.h"
11 #include "net/android/net_jni_registrar.h"
12 #include "url/android/url_jni_registrar.h"
13 
14 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID)
15 #include "base/i18n/icu_util.h"
16 #endif
17 
18 namespace {
19 
20 const base::android::RegistrationMethod kCronetRegisteredMethods[] = {
21   {"BaseAndroid", base::android::RegisterJni},
22   {"NetAndroid", net::android::RegisterJni},
23   {"UrlAndroid", url::android::RegisterJni},
24   {"UrlRequest", cronet::UrlRequestRegisterJni},
25   {"UrlRequestContext", cronet::UrlRequestContextRegisterJni},
26 };
27 
28 base::AtExitManager* g_at_exit_manager = NULL;
29 
30 }  // namespace
31 
32 // Checks the available version of JNI. Also, caches Java reflection artifacts.
JNI_OnLoad(JavaVM * vm,void * reserved)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;
37   }
38 
39   base::android::InitVM(vm);
40 
41   if (!base::android::RegisterNativeMethods(
42           env, kCronetRegisteredMethods, arraysize(kCronetRegisteredMethods))) {
43     return -1;
44   }
45 
46   g_at_exit_manager = new base::AtExitManager();
47 
48 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID)
49   base::i18n::InitializeICU();
50 #endif
51 
52   return JNI_VERSION_1_6;
53 }
54 
JNI_OnUnLoad(JavaVM * jvm,void * reserved)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;
59   }
60 }
61 
62