Home | History | Annotate | Download | only in android
      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/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"
     13 #include "url/url_util.h"
     14 
     15 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID)
     16 #include "base/i18n/icu_util.h"
     17 #endif
     18 
     19 namespace cronet {
     20 namespace {
     21 
     22 const base::android::RegistrationMethod kCronetRegisteredMethods[] = {
     23     {"BaseAndroid", base::android::RegisterJni},
     24     {"ChromiumUrlRequest", cronet::ChromiumUrlRequestRegisterJni},
     25     {"ChromiumUrlRequestContext", cronet::ChromiumUrlRequestContextRegisterJni},
     26     {"NetAndroid", net::android::RegisterJni},
     27     {"UrlAndroid", url::android::RegisterJni},
     28 };
     29 
     30 base::AtExitManager* g_at_exit_manager = NULL;
     31 
     32 }  // namespace
     33 
     34 // Checks the available version of JNI. Also, caches Java reflection artifacts.
     35 jint CronetOnLoad(JavaVM* vm, void* reserved) {
     36   JNIEnv* env;
     37   if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
     38     return -1;
     39   }
     40 
     41   base::android::InitVM(vm);
     42 
     43   if (!base::android::RegisterNativeMethods(
     44           env, kCronetRegisteredMethods, arraysize(kCronetRegisteredMethods))) {
     45     return -1;
     46   }
     47 
     48   g_at_exit_manager = new base::AtExitManager();
     49 
     50 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID)
     51   base::i18n::InitializeICU();
     52 #endif
     53 
     54   url::Initialize();
     55 
     56   return JNI_VERSION_1_6;
     57 }
     58 
     59 void CronetOnUnLoad(JavaVM* jvm, void* reserved) {
     60   if (g_at_exit_manager) {
     61     delete g_at_exit_manager;
     62     g_at_exit_manager = NULL;
     63   }
     64 }
     65 
     66 }  // namespace cronet
     67