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 |