Commit 5d4a4c5f authored by michaelbai's avatar michaelbai Committed by Commit bot

Migrate cast to use JNIOnLoadDelegate

BUG=447393

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

Cr-Commit-Position: refs/heads/master@{#316351}
parent de0ab472
...@@ -3,34 +3,42 @@ ...@@ -3,34 +3,42 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_registrar.h" #include "base/android/jni_onload_delegate.h"
#include "base/android/library_loader/library_loader_hooks.h"
#include "base/basictypes.h"
#include "base/debug/debugger.h"
#include "base/logging.h"
#include "chromecast/android/cast_jni_registrar.h" #include "chromecast/android/cast_jni_registrar.h"
#include "chromecast/android/platform_jni_loader.h" #include "chromecast/android/platform_jni_loader.h"
#include "chromecast/app/cast_main_delegate.h" #include "chromecast/app/cast_main_delegate.h"
#include "content/public/app/android_library_loader_hooks.h" #include "content/public/app/content_jni_onload.h"
#include "content/public/app/content_main.h" #include "content/public/app/content_main.h"
#include "content/public/browser/android/compositor.h" #include "content/public/browser/android/compositor.h"
// This is called by the VM when the shared library is first loaded. namespace {
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
base::android::SetLibraryLoadedHook(&content::LibraryLoaded);
base::android::InitVM(vm);
JNIEnv* env = base::android::AttachCurrentThread();
if (!base::android::RegisterLibraryLoaderEntryHook(env)) return -1; class CastJNIOnLoadDelegate : public base::android::JNIOnLoadDelegate {
public:
bool RegisterJNI(JNIEnv* env) override {
// To be called only from the UI thread. If loading the library is done on
// a separate thread, this should be moved elsewhere.
if (!chromecast::android::RegisterJni(env))
return false;
// Allow platform-specific implementations to perform more JNI registration.
if (!chromecast::android::PlatformRegisterJni(env))
return false;
return true;
}
// To be called only from the UI thread. If loading the library is done on bool Init() override {
// a separate thread, this should be moved elsewhere. content::Compositor::Initialize();
if (!chromecast::android::RegisterJni(env)) return -1; content::SetContentMainDelegate(new chromecast::shell::CastMainDelegate);
// Allow platform-specific implementations to perform more JNI registration. return true;
if (!chromecast::android::PlatformRegisterJni(env)) return -1; }
};
content::Compositor::Initialize(); } // namespace
content::SetContentMainDelegate(new chromecast::shell::CastMainDelegate);
// This is called by the VM when the shared library is first loaded.
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
CastJNIOnLoadDelegate delegate;
if (!content::android::OnJNIOnLoad(vm, &delegate))
return -1;
return JNI_VERSION_1_4; return JNI_VERSION_1_4;
} }
...@@ -13,6 +13,7 @@ import android.util.Log; ...@@ -13,6 +13,7 @@ import android.util.Log;
import org.chromium.base.BaseSwitches; import org.chromium.base.BaseSwitches;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.content.app.ContentApplication; import org.chromium.content.app.ContentApplication;
import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.BrowserStartupController;
...@@ -62,11 +63,11 @@ public class CastBrowserHelper { ...@@ -62,11 +63,11 @@ public class CastBrowserHelper {
DeviceUtils.addDeviceSpecificUserAgentSwitch(context); DeviceUtils.addDeviceSpecificUserAgentSwitch(context);
try { try {
LibraryLoader.ensureInitialized(); LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
Log.d(TAG, "Loading BrowserStartupController..."); Log.d(TAG, "Loading BrowserStartupController...");
BrowserStartupController.get(context).startBrowserProcessesSync(false); BrowserStartupController.get(context, LibraryProcessType.PROCESS_BROWSER)
.startBrowserProcessesSync(false);
sIsBrowserInitialized = true; sIsBrowserInitialized = true;
return true; return true;
} catch (ProcessInitException e) { } catch (ProcessInitException e) {
......
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