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

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

Issue 2727873002: Implement lazy initialization for VrShellDelegate (Closed)
Patch Set: Fix support for DON flow from headset insertion. 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..b230390cb77077b00a1f2fa858cdc218fc1422f6 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());
amp 2017/03/02 18:11:54 It looks it's possible for jdelegate to be non nul
mthiesse 2017/03/02 20:01:58 Fixed. jdelegate is never null now.
+ 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);
@@ -208,4 +219,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