From 427a30db60a55291d16f6da740283ade877dc5d0 Mon Sep 17 00:00:00 2001 From: Gian-Carlo Pascutto Date: Thu, 12 Apr 2012 19:28:50 +0200 Subject: [PATCH] Bug 742815 - Don't launch migration twice when status is probed. r=lucasr --- mobile/android/base/ProfileMigrator.java | 26 ++++----- .../android/base/db/BrowserContract.java.in | 1 + .../android/base/db/BrowserProvider.java.in | 53 +++++++++++-------- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/mobile/android/base/ProfileMigrator.java b/mobile/android/base/ProfileMigrator.java index d3cb3afa5fed..d689f622ed66 100644 --- a/mobile/android/base/ProfileMigrator.java +++ b/mobile/android/base/ProfileMigrator.java @@ -205,28 +205,28 @@ public class ProfileMigrator { 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); } @@ -812,7 +812,7 @@ public class ProfileMigrator { db = new SQLiteBridge(dbPath); calculateReroot(db); - if (!isBookmarksMigrated()) { + if (!areBookmarksMigrated()) { migrateBookmarks(db); setMigratedBookmarks(); } else { diff --git a/mobile/android/base/db/BrowserContract.java.in b/mobile/android/base/db/BrowserContract.java.in index 606101211a25..148fc27e1de8 100644 --- a/mobile/android/base/db/BrowserContract.java.in +++ b/mobile/android/base/db/BrowserContract.java.in @@ -166,6 +166,7 @@ public class BrowserContract { 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. diff --git a/mobile/android/base/db/BrowserProvider.java.in b/mobile/android/base/db/BrowserProvider.java.in index 46505fef187a..536805844e20 100644 --- a/mobile/android/base/db/BrowserProvider.java.in +++ b/mobile/android/base/db/BrowserProvider.java.in @@ -1478,39 +1478,46 @@ public class BrowserProvider extends ContentProvider { 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(); - // 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."); - } + boolean needBookmarks = wantBookmarks && !migrator.areBookmarksMigrated(); + boolean needHistory = wantHistory && !migrator.isHistoryMigrated(); - row.add(bookmarksDone ? 1 : 0); + if (needBookmarks || needHistory) { + migrator.launch(); + + 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; }