Bug 742815 - Don't launch migration twice when status is probed. r=lucasr
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Thu, 12 Apr 2012 19:28:50 +0200
changeset 94860 aa8facffe7ffb29e261534b8e4499646a0c02747
parent 94859 1c3e7cbe44eeb5d45534d134e651cfb1e040665a
child 94861 4aa05c31b01a457ac77b9d94419b3a75c8dd73c4
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)
reviewerslucasr
bugs742815
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 742815 - Don't launch migration twice when status is probed. r=lucasr
mobile/android/base/ProfileMigrator.java
mobile/android/base/db/BrowserContract.java.in
mobile/android/base/db/BrowserProvider.java.in
--- a/mobile/android/base/ProfileMigrator.java
+++ b/mobile/android/base/ProfileMigrator.java
@@ -200,38 +200,38 @@ public class ProfileMigrator {
     public void launch() {
         launch(DEFAULT_HISTORY_MIGRATE_COUNT);
     }
 
     public void launch(int maxEntries) {
         new PlacesRunnable(maxEntries).run();
     }
 
+    public boolean areBookmarksMigrated() {
+        return getPreferences().getBoolean(PREFS_MIGRATE_BOOKMARKS_DONE, false);
+    }
+
+    public boolean isHistoryMigrated() {
+        return getPreferences().getBoolean(PREFS_MIGRATE_HISTORY_DONE, false);
+    }
+
     // Has migration run before?
-    public boolean hasMigrationRun() {
-        return isBookmarksMigrated() && (getMigratedHistoryEntries() > 0);
+    protected boolean hasMigrationRun() {
+        return areBookmarksMigrated() && (getMigratedHistoryEntries() > 0);
     }
 
     // Has migration entirely finished?
-    public boolean hasMigrationFinished() {
-        return isBookmarksMigrated() && isHistoryMigrated();
-    }
-
-    public boolean isBookmarksMigrated() {
-        return getPreferences().getBoolean(PREFS_MIGRATE_BOOKMARKS_DONE, false);
+    protected boolean hasMigrationFinished() {
+        return areBookmarksMigrated() && isHistoryMigrated();
     }
 
     protected SharedPreferences getPreferences() {
         return GeckoApp.mAppContext.getSharedPreferences(PREFS_NAME, 0);
     }
 
-    protected boolean isHistoryMigrated() {
-        return getPreferences().getBoolean(PREFS_MIGRATE_HISTORY_DONE, false);
-    }
-
     protected int getMigratedHistoryEntries() {
         return getPreferences().getInt(PREFS_MIGRATE_HISTORY_COUNT, 0);
     }
 
     protected void setMigratedHistoryEntries(int count) {
         SharedPreferences.Editor editor = getPreferences().edit();
         editor.putInt(PREFS_MIGRATE_HISTORY_COUNT, count);
         editor.commit();
@@ -807,17 +807,17 @@ public class ProfileMigrator {
             File dbFileShm = new File(dbPathShm);
 
             SQLiteBridge db = null;
             GeckoAppShell.loadSQLiteLibs(GeckoApp.mAppContext, GeckoApp.mAppContext.getApplication().getPackageResourcePath());
             try {
                 db = new SQLiteBridge(dbPath);
                 calculateReroot(db);
 
-                if (!isBookmarksMigrated()) {
+                if (!areBookmarksMigrated()) {
                     migrateBookmarks(db);
                     setMigratedBookmarks();
                 } else {
                     Log.i(LOGTAG, "Bookmarks already migrated. Skipping...");
                 }
 
                 if (!isHistoryMigrated()) {
                     migrateHistory(db);
--- a/mobile/android/base/db/BrowserContract.java.in
+++ b/mobile/android/base/db/BrowserContract.java.in
@@ -161,16 +161,17 @@ public class BrowserContract {
         public static final String VERSION = "version";
     }
 
     public static final class Control {
         private Control() {}
 
         public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "control");
 
+        // These return 1 if done/finished, 0 if not.
         // Check if history was completely migrated, do a bunch if it wasn't.
         public static final String ENSURE_HISTORY_MIGRATED = "ensure_history_migrated";
         // Check if bookmarks were completely migrated, migrate them if not.
         public static final String ENSURE_BOOKMARKS_MIGRATED = "ensure_bookmarks_migrated";
     }
 
     public static final class Passwords {
         private Passwords() {}
--- a/mobile/android/base/db/BrowserProvider.java.in
+++ b/mobile/android/base/db/BrowserProvider.java.in
@@ -1473,49 +1473,56 @@ public class BrowserProvider extends Con
             if (!TextUtils.isEmpty(profile)) {
                 profileDir = GeckoProfile.get(mContext, profile).getDir();
             }
         }
 
         MatrixCursor cursor = new MatrixCursor(projection);
         MatrixCursor.RowBuilder row = cursor.newRow();
         synchronized (this) {
+            boolean wantBookmarks = false;
+            boolean wantHistory   = false;
+
             for (String key : projection) {
+                if (key.equals(Control.ENSURE_BOOKMARKS_MIGRATED)) {
+                    wantBookmarks = true;
+                } else if (key.equals(Control.ENSURE_HISTORY_MIGRATED)) {
+                    wantHistory = true;
+                }
+            }
+
+            if (wantHistory || wantBookmarks) {
                 ProfileMigrator migrator =
                     new ProfileMigrator(mContext.getContentResolver(), profileDir);
-                if (key.equals(Control.ENSURE_BOOKMARKS_MIGRATED)) {
-                    if (migrator.isBookmarksMigrated()) {
-                        // generic Cursor has no boolean support, use ints.
-                        row.add(1);
-                    } else {
-                        // Start migration.
-                        migrator.launch();
-                        boolean bookmarksDone = migrator.isBookmarksMigrated();
+
+                boolean needBookmarks = wantBookmarks && !migrator.areBookmarksMigrated();
+                boolean needHistory = wantHistory && !migrator.isHistoryMigrated();
+
+                if (needBookmarks || needHistory) {
+                    migrator.launch();
 
-                        // We expect bookmarks to finish in one pass. Warn if
-                        // this is not the case.
-                        if (!bookmarksDone) {
-                            Log.w(LOGTAG, "Bookmarks migration did not finish.");
-                        }
-
-                        row.add(bookmarksDone ? 1 : 0);
+                    needBookmarks = wantBookmarks && !migrator.areBookmarksMigrated();
+                    needHistory = wantHistory && !migrator.isHistoryMigrated();
+                    // Bookmarks are expected to finish at the first run.
+                    if (needBookmarks) {
+                        Log.w(LOGTAG, "Bookmarks migration did not finish.");
                     }
-                } else if (key.equals(Control.ENSURE_HISTORY_MIGRATED)) {
-                    // Are we done?
-                    if (migrator.hasMigrationFinished()) {
-                        row.add(1);
-                    } else {
-                        // Migrate some more
-                        migrator.launch();
-                        // Are we done now?
-                        row.add(migrator.hasMigrationFinished() ? 1 : 0);
+                }
+
+                // Now set the results.
+                for (String key: projection) {
+                    if (key.equals(Control.ENSURE_BOOKMARKS_MIGRATED)) {
+                        row.add(needBookmarks ? 0 : 1);
+                    } else if (key.equals(Control.ENSURE_HISTORY_MIGRATED)) {
+                        row.add(needHistory   ? 0 : 1);
                     }
                 }
             }
         }
+
         return cursor;
     }
 
     @Override
     public Cursor query(Uri uri, String[] projection, String selection,
             String[] selectionArgs, String sortOrder) {
         SQLiteDatabase db = getReadableDatabase(uri);
         final int match = URI_MATCHER.match(uri);