Commit 81079fc1 authored by mef@chromium.org's avatar mef@chromium.org

Refactor Cronet library loader.

Move java LibraryLoader into cronet.jar.

BUG=354143

Review URL: https://codereview.chromium.org/250683002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266357 0039d316-1c4b-4281-b951-d872f2087c98
parent c6d5bfcb
......@@ -60,11 +60,13 @@
'../net/net.gyp:net',
],
'sources': [
'cronet/android/cronet_jni.cc',
'cronet/android/org_chromium_net_UrlRequest.cc',
'cronet/android/org_chromium_net_UrlRequest.h',
'cronet/android/org_chromium_net_UrlRequest_error_list.h',
'cronet/android/org_chromium_net_UrlRequest_priority_list.h',
'cronet/android/org_chromium_net_UrlRequestContext.cc',
'cronet/android/org_chromium_net_UrlRequestContext.h',
'cronet/android/url_request_context_peer.cc',
'cronet/android/url_request_context_peer.h',
'cronet/android/url_request_peer.cc',
......
// 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 "base/android/base_jni_registrar.h"
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "components/cronet/android/org_chromium_net_UrlRequest.h"
#include "components/cronet/android/org_chromium_net_UrlRequestContext.h"
#include "net/android/net_jni_registrar.h"
namespace {
const base::android::RegistrationMethod kCronetRegisteredMethods[] = {
{"BaseAndroid", base::android::RegisterJni},
{"NetAndroid", net::android::RegisterJni},
{"UrlRequest", cronet::UrlRequestRegisterJni},
{"UrlRequestContext", cronet::UrlRequestContextRegisterJni},
};
base::AtExitManager* g_at_exit_manager = NULL;
} // namespace
// 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;
}
base::android::InitVM(vm);
if (!base::android::RegisterNativeMethods(
env, kCronetRegisteredMethods, arraysize(kCronetRegisteredMethods))) {
return -1;
}
g_at_exit_manager = new base::AtExitManager();
base::i18n::InitializeICU();
return JNI_VERSION_1_6;
}
extern "C" void JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM* jvm, void* reserved) {
if (g_at_exit_manager) {
delete g_at_exit_manager;
g_at_exit_manager = NULL;
}
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.cronet_sample_apk;
package org.chromium.net;
import android.util.Log;
......
......@@ -2,18 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/base_jni_registrar.h"
#include "components/cronet/android/org_chromium_net_UrlRequestContext.h"
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "base/android/jni_string.h"
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "base/metrics/statistics_recorder.h"
#include "components/cronet/android/org_chromium_net_UrlRequest.h"
#include "components/cronet/android/url_request_context_peer.h"
#include "components/cronet/android/url_request_peer.h"
#include "jni/UrlRequestContext_jni.h"
#include "net/android/net_jni_registrar.h"
// Version of this build of Chromium NET.
#define CHROMIUM_NET_VERSION "1"
......@@ -22,15 +19,6 @@ namespace {
const char kVersion[] = CHROMIUM_VERSION "/" CHROMIUM_NET_VERSION;
const base::android::RegistrationMethod kCronetRegisteredMethods[] = {
{"BaseAndroid", base::android::RegisterJni},
{"NetAndroid", net::android::RegisterJni},
{"UrlRequest", cronet::UrlRequestRegisterJni},
{"UrlRequestContext", cronet::RegisterNativesImpl},
};
base::AtExitManager* g_at_exit_manager = NULL;
// Delegate of URLRequestContextPeer that delivers callbacks to the Java layer.
class JniURLRequestContextPeerDelegate
: public cronet::URLRequestContextPeer::URLRequestContextPeerDelegate {
......@@ -59,36 +47,13 @@ class JniURLRequestContextPeerDelegate
} // namespace
// 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;
}
base::android::InitVM(vm);
if (!base::android::RegisterNativeMethods(
env, kCronetRegisteredMethods, arraysize(kCronetRegisteredMethods))) {
return -1;
}
g_at_exit_manager = new base::AtExitManager();
base::i18n::InitializeICU();
return JNI_VERSION_1_6;
}
namespace cronet {
extern "C" void JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM* jvm, void* reserved) {
if (g_at_exit_manager) {
delete g_at_exit_manager;
g_at_exit_manager = NULL;
}
// Explicitly register static JNI functions.
bool UrlRequestContextRegisterJni(JNIEnv* env) {
return RegisterNativesImpl(env);
}
namespace cronet {
static jstring GetVersion(JNIEnv* env, jclass unused) {
return env->NewStringUTF(kVersion);
}
......
// 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.
#ifndef COMPONENTS_CRONET_ANDROID_URLREQUEST_CONTEXT_H_
#define COMPONENTS_CRONET_ANDROID_URLREQUEST_CONTEXT_H_
#include <jni.h>
namespace cronet {
bool UrlRequestContextRegisterJni(JNIEnv* env);
} // namespace cronet
#endif // COMPONENTS_CRONET_ANDROID_URLREQUEST_CONTEXT_H_
......@@ -16,6 +16,7 @@ import android.widget.Toast;
import org.chromium.net.HttpUrlRequest;
import org.chromium.net.HttpUrlRequestFactory;
import org.chromium.net.HttpUrlRequestListener;
import org.chromium.net.LibraryLoader;
import org.chromium.net.UrlRequest;
import org.chromium.net.UrlRequestContext;
import org.chromium.net.UrlRequestPriority;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment