Bug 742815 - Don't launch migration twice when status is probed. r=lucasr

This commit is contained in:
Gian-Carlo Pascutto 2012-04-12 19:28:50 +02:00
parent e398ecb85a
commit 427a30db60
3 changed files with 44 additions and 36 deletions

View File

@ -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 {

View File

@ -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.

View File

@ -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;
}