Bug 869225 - Move decision whether to restore session or not onto background thread. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 11 May 2017 22:19:18 +0200
changeset 583901 09dd736355aa488909fdf2a6b4045f3b7fea893e
parent 583157 52cbcfe7515e7579b656734ab8e60849818e06bd
child 630245 52500761aff6d4652696b61c1933b5c75d997ce2
push id60593
push usermozilla@buttercookie.de
push dateWed, 24 May 2017 19:39:16 +0000
reviewerssebastian
bugs869225
milestone55.0a1
Bug 869225 - Move decision whether to restore session or not onto background thread. r?sebastian This involves accessing the file system to check whether our last session crashed or not (as well as reading some shared preferences), so moving this onto the background thread as well avoids some strict mode warnings. With the exception of loadStartupTab(), mShouldRestore and mLastSessionCrashed are always accessed from the background thread. loadStartupTab() can potentially run on the main thread, however this is okay, because as far as I can see it is only called after the main and background thread have synchronised with each other during initialize(). mPrivateBrowsingSession in turn is now initially only accessed from the background thread for storing the data from the savedInstanceState and the passing it on to session restore. Afterwards, we pass through the synchronisation in initialize() and then all further accesses - receiving private tab data from Gecko and saving it during onSaveInstanceState - happen only on the main thread. Additionally, all data updates from Gecko will completely overwrite the previous state, so the initial value set during onCreate() will soon become irrelevant, anyway. MozReview-Commit-ID: L5hMFCXLcIf
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -1428,35 +1428,37 @@ public abstract class GeckoApp extends G
 
         if (Versions.preMarshmallow) {
             mTextSelection = new ActionBarTextSelection(this, getTextSelectPresenter());
         } else {
             mTextSelection = new FloatingToolbarTextSelection(this, mLayerView);
         }
         mTextSelection.create();
 
-        // Determine whether we should restore tabs.
-        mLastSessionCrashed = updateCrashedState();
-        mShouldRestore = getSessionRestoreState(savedInstanceState);
-        if (mShouldRestore && savedInstanceState != null) {
-            boolean wasInBackground =
-                savedInstanceState.getBoolean(SAVED_STATE_IN_BACKGROUND, false);
-
-            // Don't log OOM-kills if only one activity was destroyed. (For example
-            // from "Don't keep activities" on ICS)
-            if (!wasInBackground && !mIsRestoringActivity) {
-                Telemetry.addToHistogram("FENNEC_WAS_KILLED", 1);
-            }
-
-            mPrivateBrowsingSession = savedInstanceState.getString(SAVED_STATE_PRIVATE_SESSION);
-        }
-
+        final Bundle finalSavedInstanceState = savedInstanceState;
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
+                // Determine whether we should restore tabs.
+                mLastSessionCrashed = updateCrashedState();
+                mShouldRestore = getSessionRestoreState(finalSavedInstanceState);
+                if (mShouldRestore && finalSavedInstanceState != null) {
+                    boolean wasInBackground =
+                            finalSavedInstanceState.getBoolean(SAVED_STATE_IN_BACKGROUND, false);
+
+                    // Don't log OOM-kills if only one activity was destroyed. (For example
+                    // from "Don't keep activities" on ICS)
+                    if (!wasInBackground && !mIsRestoringActivity) {
+                        Telemetry.addToHistogram("FENNEC_WAS_KILLED", 1);
+                    }
+
+                    mPrivateBrowsingSession =
+                            finalSavedInstanceState.getString(SAVED_STATE_PRIVATE_SESSION);
+                }
+
                 // If we are doing a restore, read the session data so we can send it to Gecko later.
                 GeckoBundle restoreMessage = null;
                 if (!mIsRestoringActivity && mShouldRestore) {
                     final boolean isExternalURL = invokedWithExternalURL(getIntentURI(new SafeIntent(getIntent())));
                     try {
                         // restoreSessionTabs() will create simple tab stubs with the
                         // URL and title for each page, but we also need to restore
                         // session history. restoreSessionTabs() will inject the IDs