From 2983d0a348c9399753255640eebb583749cf7d65 Mon Sep 17 00:00:00 2001 From: Gian-Carlo Pascutto Date: Thu, 19 Apr 2012 22:07:39 +0200 Subject: [PATCH] Bug 746630 - Trigger the "setting up" screen via callbacks instead of timers. r=blassey a=blocking-fennec --- mobile/android/base/GeckoApp.java | 26 ++++++++++++++++++++--- mobile/android/base/ProfileMigrator.java | 27 +++++++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 9f94c114e3b..45046825f0e 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -2298,13 +2298,33 @@ abstract public class GeckoApp // 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"); diff --git a/mobile/android/base/ProfileMigrator.java b/mobile/android/base/ProfileMigrator.java index 12f1c7f187b..fd1ba8ad057 100644 --- a/mobile/android/base/ProfileMigrator.java +++ b/mobile/android/base/ProfileMigrator.java @@ -98,6 +98,9 @@ public class 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; @@ -260,6 +263,17 @@ public class ProfileMigrator { 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() { @@ -276,6 +290,7 @@ public class ProfileMigrator { } public void launchPlaces(int maxEntries) { + mLongOperationStartRun = false; // Places migration is heavy on the phone, allow it to block // other processing. new PlacesRunnable(maxEntries).run(); @@ -1171,6 +1186,11 @@ public class ProfileMigrator { setMigratedHistory(); } else { // Compatible schema. Let's go. + if (mLongOperationStartCallback != null) { + mLongOperationStartCallback.run(); + mLongOperationStartRun = true; + } + calculateReroot(db); if (!areBookmarksMigrated()) { @@ -1205,7 +1225,12 @@ public class ProfileMigrator { db.close(); } Log.e(LOGTAG, "Error on places database:", e); - return; + } finally { + if (mLongOperationStopCallback != null) { + if (mLongOperationStartRun) { + mLongOperationStopCallback.run(); + } + } } }