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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java

Issue 2855123008: VR: Make work done during onResume in VrShellDelegate asynchronous. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java
index 0d1ef6389e475d33ce782cf23150cd5bee8b007f..4a878a239961df69fd796bfde5917d58f903e814 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java
@@ -14,6 +14,8 @@ import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Build;
import android.os.Handler;
import android.os.StrictMode;
import android.os.SystemClock;
@@ -245,15 +247,38 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
* If VR Shell is enabled, and the activity is supported, register with the Daydream
* platform that this app would like to be launched in VR when the device enters VR.
*/
- public static void maybeRegisterVrEntryHook(ChromeActivity activity) {
+ public static void maybeRegisterVrEntryHook(final ChromeActivity activity) {
+ // Daydream is not supported on pre-N devices.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
if (sInstance != null) return; // Will be handled in onResume.
if (!activitySupportsVrBrowsing(activity)) return;
- VrClassesWrapper wrapper = getVrClassesWrapper();
- if (wrapper == null) return;
- VrDaydreamApi api = wrapper.createVrDaydreamApi(activity);
- if (api == null) return;
- int vrSupportLevel = getVrSupportLevel(api, wrapper.createVrCoreVersionChecker(), null);
- if (isVrShellEnabled(vrSupportLevel)) registerDaydreamIntent(api, activity);
+
+ // Reading VR support level and version can be slow, so do it asynchronously.
+ new AsyncTask<Void, Void, VrDaydreamApi>() {
+ @Override
+ protected VrDaydreamApi doInBackground(Void... params) {
+ VrClassesWrapper wrapper = getVrClassesWrapper();
+ if (wrapper == null) return null;
+ VrDaydreamApi api = wrapper.createVrDaydreamApi(activity);
+ if (api == null) return null;
+ int vrSupportLevel =
+ getVrSupportLevel(api, wrapper.createVrCoreVersionChecker(), null);
+ if (!isVrShellEnabled(vrSupportLevel)) return null;
+ return api;
+ }
+
+ @Override
+ protected void onPostExecute(VrDaydreamApi api) {
+ // Registering the daydream intent has to be done on the UI thread. Note that this
+ // call is slow (~10ms at time of writing).
+ if (api != null
+ && ApplicationStatus.getStateForActivity(activity)
+ == ActivityState.RESUMED) {
+ registerDaydreamIntent(api, activity);
+ }
+ }
+ }
+ .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
/**
@@ -261,6 +286,8 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
* from being launched from the background when the device enters VR.
*/
public static void maybeUnregisterVrEntryHook(ChromeActivity activity) {
+ // Daydream is not supported on pre-N devices.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
if (sInstance != null) return; // Will be handled in onPause.
if (!activitySupportsVrBrowsing(activity)) return;
VrClassesWrapper wrapper = getVrClassesWrapper();
@@ -335,10 +362,10 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
private static void registerDaydreamIntent(
final VrDaydreamApi daydreamApi, final ChromeActivity activity) {
if (sVrBroadcastReceiver != null) sVrBroadcastReceiver.unregister();
+ if (!daydreamApi.registerDaydreamIntent(getEnterVrPendingIntent(activity))) return;
IntentFilter filter = new IntentFilter(VR_ENTRY_RESULT_ACTION);
sVrBroadcastReceiver = new VrBroadcastReceiver(activity);
activity.registerReceiver(sVrBroadcastReceiver, filter);
- daydreamApi.registerDaydreamIntent(getEnterVrPendingIntent(activity));
}
/**
@@ -614,9 +641,14 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
}
if (mVrSupportLevel != VR_DAYDREAM) return;
- if (mListeningForWebVrActivateBeforePause
- || (isVrShellEnabled(mVrSupportLevel) && activitySupportsVrBrowsing(mActivity))) {
- registerDaydreamIntent(mVrDaydreamApi, mActivity);
+ if (isVrShellEnabled(mVrSupportLevel) && activitySupportsVrBrowsing(mActivity)) {
+ // registerDaydreamIntent is slow, so run it after resuming.
+ new Handler().post(new Runnable() {
+ @Override
+ public void run() {
+ if (!mPaused) registerDaydreamIntent(mVrDaydreamApi, mActivity);
+ }
+ });
}
if (mVrDaydreamApi.isDaydreamCurrentViewer()
@@ -704,7 +736,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
// mListeningForWebVrActivate for them.
if (mVrSupportLevel != VR_DAYDREAM) return;
mListeningForWebVrActivate = listening;
- if (listening) {
+ if (listening && !mPaused) {
registerDaydreamIntent(mVrDaydreamApi, mActivity);
} else {
unregisterDaydreamIntent(mVrDaydreamApi);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698