Bug 746630 - Trigger the "setting up" screen via callbacks instead of timers. r=blassey a=blocking-fennec
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Thu, 19 Apr 2012 22:07:39 +0200
changeset 95310 41aa31e62e7b0a02dbf033dc228e1ac454d3d236
parent 95309 029dae90f2ccccc1783b5da609b43a9031475e9e
child 95311 47c706c98a825fb776152b3c76fc5513e79b8bda
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey, blocking-fennec
bugs746630
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 746630 - Trigger the "setting up" screen via callbacks instead of timers. r=blassey a=blocking-fennec
mobile/android/base/GeckoApp.java
mobile/android/base/ProfileMigrator.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2293,23 +2293,43 @@ abstract public class GeckoApp
                 public void run() {
                     Log.i(LOGTAG, "Checking profile migration in: " + profileDir.getAbsolutePath());
 
                     ProfileMigrator profileMigrator =
                         new ProfileMigrator(app, profileDir);
 
                     // Do a migration run on the first start after an upgrade.
                     if (!profileMigrator.hasMigrationRun()) {
+                        // Show the "Setting up Fennec" screen if this takes
+                        // a while.
                         final SetupScreen setupScreen = new SetupScreen(app);
 
-                        // Don't show unless this take a while.
-                        setupScreen.showDelayed(mMainHandler);
-
+                        final Runnable startCallback = new Runnable() {
+                            public void run() {
+                                GeckoApp.mAppContext.runOnUiThread(new Runnable() {
+                                    public void run() {
+                                       setupScreen.show();
+                                    }
+                                });
+                            }
+                        };
+
+                        final Runnable stopCallback = new Runnable() {
+                            public void run() {
+                                GeckoApp.mAppContext.runOnUiThread(new Runnable() {
+                                    public void run() {
+                                        setupScreen.dismiss();
+                                    }
+                                });
+                            }
+                        };
+
+                        profileMigrator.setLongOperationCallbacks(startCallback,
+                                                                  stopCallback);
                         profileMigrator.launchPlaces();
-                        setupScreen.dismiss();
 
                         long timeDiff = SystemClock.uptimeMillis() - currentTime;
                         Log.i(LOGTAG, "Profile migration took " + timeDiff + " ms");
 
                         // Update about:home with the new information.
                         updateAboutHomeTopSites();
                     }
                 }}
--- a/mobile/android/base/ProfileMigrator.java
+++ b/mobile/android/base/ProfileMigrator.java
@@ -93,16 +93,19 @@ import org.json.JSONObject;
 import org.json.JSONException;
 
 public class ProfileMigrator {
     private static final String LOGTAG = "ProfileMigrator";
     private static final String PREFS_NAME = "ProfileMigrator";
     private File mProfileDir;
     private ContentResolver mCr;
     private Context mContext;
+    private Runnable mLongOperationStartCallback;
+    private boolean mLongOperationStartRun;
+    private Runnable mLongOperationStopCallback;
 
     // Default number of history entries to migrate in one run.
     private static final int DEFAULT_HISTORY_MIGRATE_COUNT = 2000;
 
     // Maximum number of history entries to fetch at once.
     // This limits the max memory use to about 10M (empirically), so we don't OOM.
     private static final int HISTORY_MAX_BATCH = 5000;
 
@@ -255,32 +258,44 @@ public class ProfileMigrator {
         "Mozilla Services Encryption Passphrase"
     };
 
 
     public ProfileMigrator(Context context, File profileDir) {
         mProfileDir = profileDir;
         mContext = context;
         mCr = mContext.getContentResolver();
+        mLongOperationStartCallback = null;
+        mLongOperationStopCallback = null;
+    }
+
+    // Define callbacks to run if the operation will take a while.
+    // Stop callback is only run if there was a start callback that was run.
+    public void setLongOperationCallbacks(Runnable start,
+                                          Runnable stop) {
+        mLongOperationStartCallback = start;
+        mLongOperationStopCallback = stop;
+        mLongOperationStartRun = false;
     }
 
     public void launchPlaces() {
         boolean timeThisRun = false;
         Telemetry.Timer timer = null;
         // First run, time things
         if (!hasMigrationRun()) {
             timeThisRun = true;
             timer = new Telemetry.Timer("BROWSERPROVIDER_XUL_IMPORT_TIME");
         }
         launchPlaces(DEFAULT_HISTORY_MIGRATE_COUNT);
         if (timeThisRun)
             timer.stop();
     }
 
     public void launchPlaces(int maxEntries) {
+        mLongOperationStartRun = false;
         // Places migration is heavy on the phone, allow it to block
         // other processing.
         new PlacesRunnable(maxEntries).run();
     }
 
     public void launchSyncPrefs() {
         // Sync settings will post a runnable, no need for a seperate thread.
         new SyncTask().run();
@@ -1166,16 +1181,21 @@ public class ProfileMigrator {
             try {
                 db = new SQLiteBridge(dbPath);
                 if (!checkPlacesSchema(db)) {
                     // Incompatible schema. Bail out.
                     setMigratedBookmarks();
                     setMigratedHistory();
                 } else {
                     // Compatible schema. Let's go.
+                    if (mLongOperationStartCallback != null) {
+                        mLongOperationStartCallback.run();
+                        mLongOperationStartRun = true;
+                    }
+
                     calculateReroot(db);
 
                     if (!areBookmarksMigrated()) {
                         migrateBookmarks(db);
                         setMigratedBookmarks();
                     } else {
                         Log.i(LOGTAG, "Bookmarks already migrated. Skipping...");
                     }
@@ -1200,17 +1220,22 @@ public class ProfileMigrator {
                 }
 
                 Log.i(LOGTAG, "Profile Migration run finished");
             } catch (SQLiteBridgeException e) {
                 if (db != null) {
                     db.close();
                 }
                 Log.e(LOGTAG, "Error on places database:", e);
-                return;
+            } finally {
+                if (mLongOperationStopCallback != null) {
+                    if (mLongOperationStartRun) {
+                        mLongOperationStopCallback.run();
+                    }
+                }
             }
         }
 
         @Override
         public void run() {
             migratePlaces(mProfileDir);
         }
     }