Commit 3994cb32 authored by michaelbai's avatar michaelbai Committed by Commit bot

Refactoring chrome JNI registration.

Move the JNI registration to OnJNIOnLoadRegisterJNI.
Remove ChromeMainDelegateAndroid::RegisterApplicationNativeMethods()

TBR=jochen

BUG=447393

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

Cr-Commit-Position: refs/heads/master@{#319129}
parent fcfde7d9
......@@ -671,6 +671,7 @@ if (is_android) {
"app/android/chrome_android_initializer.cc",
"app/android/chrome_android_initializer.h",
"app/android/chrome_jni_onload.cc",
"app/android/chrome_jni_onload.h",
"app/android/chrome_main_delegate_android.cc",
"app/android/chrome_main_delegate_android.h",
"app/chrome_main_delegate.cc",
......
......@@ -179,6 +179,7 @@ shared_library("chrome_shell") {
sources = [
"shell/chrome_main_delegate_chrome_shell_android.cc",
"shell/chrome_main_delegate_chrome_shell_android.h",
"shell/chrome_shell_entry_point.cc",
]
deps = [
":chrome_shell_base",
......@@ -197,6 +198,7 @@ shared_library("chrome_shell") {
shared_library("chrome_sync_shell") {
testonly = true
sources = [
#"shell/chrome_shell_entry_point.cc",
#"sync_shell/chrome_main_delegate_chrome_sync_shell_android.cc",
#"sync_shell/chrome_main_delegate_chrome_sync_shell_android.h",
]
......
// Copyright 2015 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/jni_android.h"
#include "base/bind.h"
#include "chrome/app/android/chrome_jni_onload.h"
namespace {
bool RegisterJNI(JNIEnv* env) {
return true;
}
bool Init() {
return true;
}
} // namespace
// This is called by the VM when the shared library is first loaded,
// and used by chrome_shell and chrome_sync_shell.
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
if (!chrome::android::OnJNIOnLoadRegisterJNI(vm, base::Bind(&RegisterJNI)) ||
!chrome::android::OnJNIOnLoadInit(base::Bind(&Init))) {
return -1;
}
return JNI_VERSION_1_4;
}
......@@ -20,15 +20,20 @@ ChromeMainDelegateChromeSyncShellAndroid::
~ChromeMainDelegateChromeSyncShellAndroid() {
}
bool
ChromeMainDelegateChromeSyncShellAndroid::RegisterApplicationNativeMethods(
JNIEnv* env) {
return ChromeMainDelegateAndroid::RegisterApplicationNativeMethods(env) &&
FakeServerHelperAndroid::Register(env);
}
bool ChromeMainDelegateChromeSyncShellAndroid::BasicStartupComplete(
int* exit_code) {
return ChromeMainDelegateAndroid::BasicStartupComplete(exit_code);
}
int ChromeMainDelegateChromeSyncShellAndroid::RunProcess(
const std::string& process_type,
const content::MainFunctionParams& main_function_params) {
if (process_type.empty()) {
// This JNI registration can not be moved to JNI_OnLoad because
// FakeServerHelper seems not known by class loader when shared library
// is loaded.
FakeServerHelperAndroid::Register(base::android::AttachCurrentThread());
}
return ChromeMainDelegateAndroid::RunProcess(process_type,
main_function_params);
}
......@@ -13,9 +13,10 @@ class ChromeMainDelegateChromeSyncShellAndroid
ChromeMainDelegateChromeSyncShellAndroid();
~ChromeMainDelegateChromeSyncShellAndroid() override;
bool RegisterApplicationNativeMethods(JNIEnv* env) override;
bool BasicStartupComplete(int* exit_code) override;
int RunProcess(
const std::string& process_type,
const content::MainFunctionParams& main_function_params) override;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeMainDelegateChromeSyncShellAndroid);
......
......@@ -2,35 +2,48 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/jni_android.h"
#include "chrome/app/android/chrome_jni_onload.h"
#include "base/android/library_loader/library_loader_hooks.h"
#include "base/bind.h"
#include "chrome/app/android/chrome_android_initializer.h"
#include "chrome/browser/android/chrome_jni_registrar.h"
#include "content/public/app/content_jni_onload.h"
namespace chrome {
namespace android {
namespace {
bool RegisterJNI(JNIEnv* env) {
if (base::android::GetLibraryProcessType(env) ==
base::android::PROCESS_BROWSER) {
return RegisterBrowserJNI(env);
}
return true;
}
bool Init() {
// TODO(michaelbai): Move the JNI registration from RunChrome() to
// RegisterJNI().
return RunChrome();
}
} // namespace
// This is called by the VM when the shared library is first loaded.
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
bool OnJNIOnLoadRegisterJNI(
JavaVM* vm,
base::android::RegisterCallback callback) {
std::vector<base::android::RegisterCallback> register_callbacks;
register_callbacks.push_back(callback);
register_callbacks.push_back(base::Bind(&RegisterJNI));
return content::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks);
}
bool OnJNIOnLoadInit(base::android::InitCallback callback) {
std::vector<base::android::InitCallback> init_callbacks;
init_callbacks.push_back(callback);
init_callbacks.push_back(base::Bind(&Init));
if (!content::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) ||
!content::android::OnJNIOnLoadInit(init_callbacks)) {
return -1;
}
return JNI_VERSION_1_4;
return content::android::OnJNIOnLoadInit(init_callbacks);
}
} // namespace android
} // namespace chrome
// Copyright 2015 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 CHROME_APP_ANDROID_CHROME_JNI_ONLOAD_H_
#define CHROME_APP_ANDROID_CHROME_JNI_ONLOAD_H_
#include "base/android/base_jni_onload.h"
namespace chrome {
namespace android {
bool OnJNIOnLoadRegisterJNI(
JavaVM* vm,
base::android::RegisterCallback callback);
bool OnJNIOnLoadInit(base::android::InitCallback callback);
} // namespace android
} // namespace chrome
#endif // CHROME_APP_ANDROID_CHROME_JNI_ONLOAD_H_
......@@ -6,7 +6,6 @@
#include "base/android/jni_android.h"
#include "base/trace_event/trace_event.h"
#include "chrome/browser/android/chrome_jni_registrar.h"
#include "chrome/browser/android/chrome_startup_flags.h"
#include "chrome/browser/android/metrics/uma_utils.h"
#include "components/startup_metric_utils/startup_metric_utils.h"
......@@ -31,9 +30,6 @@ int ChromeMainDelegateAndroid::RunProcess(
const content::MainFunctionParams& main_function_params) {
TRACE_EVENT0("startup", "ChromeMainDelegateAndroid::RunProcess")
if (process_type.empty()) {
JNIEnv* env = base::android::AttachCurrentThread();
RegisterApplicationNativeMethods(env);
// Because the browser process can be started asynchronously as a series of
// UI thread tasks a second request to start it can come in while the
// first request is still being processed. Chrome must keep the same
......@@ -55,7 +51,3 @@ bool ChromeMainDelegateAndroid::BasicStartupComplete(int* exit_code) {
SetChromeSpecificCommandLineFlags();
return ChromeMainDelegate::BasicStartupComplete(exit_code);
}
bool ChromeMainDelegateAndroid::RegisterApplicationNativeMethods(JNIEnv* env) {
return chrome::android::RegisterJni(env);
}
......@@ -13,10 +13,6 @@ class ChromeMainDelegateAndroid : public ChromeMainDelegate {
public:
static ChromeMainDelegateAndroid* Create();
// Set up the JNI bindings. Tie the Java methods with their native
// counterparts. Override to add more JNI bindings.
virtual bool RegisterApplicationNativeMethods(JNIEnv* env);
protected:
ChromeMainDelegateAndroid();
~ChromeMainDelegateAndroid() override;
......
......@@ -243,7 +243,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
#endif
};
bool RegisterJni(JNIEnv* env) {
bool RegisterBrowserJNI(JNIEnv* env) {
TRACE_EVENT0("startup", "chrome_android::RegisterJni");
return RegisterNativeMethods(env, kChromeRegisteredMethods,
arraysize(kChromeRegisteredMethods));
......
......@@ -10,8 +10,8 @@
namespace chrome {
namespace android {
// Register all JNI bindings necessary for chrome.
bool RegisterJni(JNIEnv* env);
// Register all JNI bindings necessary for chrome browser process.
bool RegisterBrowserJNI(JNIEnv* env);
} // namespace android
} // namespace chrome
......
......@@ -42,6 +42,7 @@
'app/android/chrome_android_initializer.cc',
'app/android/chrome_android_initializer.h',
'app/android/chrome_jni_onload.cc',
'app/android/chrome_jni_onload.h',
'app/android/chrome_main_delegate_android.cc',
'app/android/chrome_main_delegate_android.h',
'app/chrome_main_delegate.cc',
......
......@@ -48,6 +48,7 @@
'target_name': 'libchromeshell',
'type': 'shared_library',
'sources': [
'android/shell/chrome_shell_entry_point.cc',
'android/shell/chrome_main_delegate_chrome_shell_android.cc',
'android/shell/chrome_main_delegate_chrome_shell_android.h',
],
......@@ -65,6 +66,7 @@
'target_name': 'libchromesyncshell',
'type': 'shared_library',
'sources': [
'android/shell/chrome_shell_entry_point.cc',
'android/sync_shell/chrome_main_delegate_chrome_sync_shell_android.cc',
'android/sync_shell/chrome_main_delegate_chrome_sync_shell_android.h',
],
......
......@@ -22,15 +22,6 @@
#include "extensions/common/constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_ANDROID)
#include "base/android/jni_android.h"
#include "chrome/browser/android/chrome_jni_registrar.h"
#include "net/android/net_jni_registrar.h"
#include "ui/base/android/ui_base_jni_registrar.h"
#include "ui/gfx/android/gfx_jni_registrar.h"
#include "ui/gl/android/gl_jni_registrar.h"
#endif
#if defined(OS_CHROMEOS)
#include "base/process/process_metrics.h"
#include "chromeos/chromeos_paths.h"
......@@ -81,15 +72,6 @@ void ChromeTestSuite::Initialize() {
#endif // !defined(OS_IOS)
#endif
#if defined(OS_ANDROID)
// Register JNI bindings for android.
gfx::android::RegisterJni(base::android::AttachCurrentThread());
net::android::RegisterJni(base::android::AttachCurrentThread());
ui::android::RegisterJni(base::android::AttachCurrentThread());
ui::gl::android::RegisterJni(base::android::AttachCurrentThread());
chrome::android::RegisterJni(base::android::AttachCurrentThread());
#endif
if (!browser_dir_.empty()) {
PathService::Override(base::DIR_EXE, browser_dir_);
PathService::Override(base::DIR_MODULE, browser_dir_);
......
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