Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6127)

Unified Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2727873002: Implement lazy initialization for VrShellDelegate (Closed)
Patch Set: Address comments + Fix shutdown crash Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/vr_shell_delegate.cc
diff --git a/chrome/browser/android/vr_shell/vr_shell_delegate.cc b/chrome/browser/android/vr_shell/vr_shell_delegate.cc
index a25b6a513e19f90feaf80bb77c62485cb3b9d239..d7bf7dbbe33a4feb02a969ed7813579e035051e2 100644
--- a/chrome/browser/android/vr_shell/vr_shell_delegate.cc
+++ b/chrome/browser/android/vr_shell/vr_shell_delegate.cc
@@ -21,16 +21,23 @@ namespace vr_shell {
VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
: weak_ptr_factory_(this) {
j_vr_shell_delegate_.Reset(env, obj);
- GvrDelegateProvider::SetInstance(this);
}
VrShellDelegate::~VrShellDelegate() {
- GvrDelegateProvider::SetInstance(nullptr);
if (device_provider_) {
device_provider_->Device()->OnDelegateChanged();
}
}
+device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() {
+ JNIEnv* env = AttachCurrentThread();
+ base::android::ScopedJavaLocalRef<jobject> jdelegate =
+ Java_VrShellDelegate_getInstance(env);
+ if (!jdelegate.is_null())
+ return GetNativeVrShellDelegate(env, jdelegate.obj());
+ return nullptr;
+}
+
VrShellDelegate* VrShellDelegate::GetNativeVrShellDelegate(JNIEnv* env,
jobject jdelegate) {
return reinterpret_cast<VrShellDelegate*>(
@@ -115,6 +122,10 @@ void VrShellDelegate::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
}
}
+void VrShellDelegate::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
+ delete this;
+}
+
void VrShellDelegate::ShowTab(int id) {
JNIEnv* env = AttachCurrentThread();
Java_VrShellDelegate_showTab(env, j_vr_shell_delegate_.obj(), id);
@@ -134,7 +145,6 @@ void VrShellDelegate::ClearDeviceProvider() {
JNIEnv* env = AttachCurrentThread();
Java_VrShellDelegate_shutdownNonPresentingNativeContext(
env, j_vr_shell_delegate_.obj());
- device_provider_->Device()->OnDelegateChanged();
device_provider_ = nullptr;
}
@@ -208,4 +218,9 @@ jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
}
+static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
+ device::GvrDelegateProvider::SetInstance(
+ base::Bind(&VrShellDelegate::CreateVrShellDelegate));
+}
+
} // namespace vr_shell

Powered by Google App Engine
This is Rietveld 408576698