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

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

Issue 2727873002: Implement lazy initialization for VrShellDelegate (Closed)
Patch Set: Fix FindBugs errors - neat! 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
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 681f030a29c347f832a7140e76d38d70751c217a..17a7ea3f9c603694d09864451bed19822a4e59aa 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);
@@ -139,7 +150,6 @@ void VrShellDelegate::ClearDeviceProvider() {
JNIEnv* env = AttachCurrentThread();
Java_VrShellDelegate_shutdownNonPresentingNativeContext(
env, j_vr_shell_delegate_.obj());
- device_provider_->Device()->OnDelegateChanged();
device_provider_ = nullptr;
}
@@ -213,4 +223,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
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698