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

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

Issue 2510873003: Clean up WebVR RequestPresent and make callback asynchronous. (Closed)
Patch Set: Address comments Created 4 years, 1 month 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 ae4acc523ce7317b1e0c39f8bad9a523af61170c..cffe81ba46bd5df71cf13784615fcdd040f03d20 100644
--- a/chrome/browser/android/vr_shell/vr_shell_delegate.cc
+++ b/chrome/browser/android/vr_shell/vr_shell_delegate.cc
@@ -67,17 +67,30 @@ void VrShellDelegate::ExitWebVRIfNecessary(JNIEnv* env, jobject obj) {
device_provider_->OnGvrDelegateRemoved();
}
-bool VrShellDelegate::RequestWebVRPresent(
- base::WeakPtr<device::GvrDeviceProvider> device_provider) {
- // Only set one device provider at a time
+void VrShellDelegate::SetPresentResult(JNIEnv* env, jobject obj,
+ jboolean result) {
+ CHECK(!present_callback_.is_null());
+ present_callback_.Run(result);
+ present_callback_.Reset();
+}
+
+void VrShellDelegate::RequestWebVRPresent(
+ base::WeakPtr<device::GvrDeviceProvider> device_provider,
+ const base::Callback<void(bool)>& callback) {
+ if (!present_callback_.is_null()) {
+ // Can only handle one request at a time. This is also extremely unlikely to
+ // happen in practice.
+ callback.Run(false);
+ }
+ // Only set one device provider at a time.
DCHECK(!device_provider_);
+
device_provider_ = device_provider;
+ present_callback_ = callback;
- // If/When VRShell is ready for use it will call OnVrShellReady.
+ // If/When VRShell is ready for use it will call SetPresentResult.
JNIEnv* env = AttachCurrentThread();
- Java_VrShellDelegate_enterVRIfNecessary(env, j_vr_shell_delegate_.obj(),
- true);
- return true;
+ Java_VrShellDelegate_presentRequested(env, j_vr_shell_delegate_.obj(), true);
}
void VrShellDelegate::ExitWebVRPresent() {

Powered by Google App Engine
This is Rietveld 408576698