mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 742815 - Don't launch migration twice when status is probed. r=lucasr
This commit is contained in:
parent
8ed69c9ee3
commit
42d072812e
@ -206,26 +206,26 @@ public class ProfileMigrator {
|
||||
new PlacesRunnable(maxEntries).run();
|
||||
}
|
||||
|
||||
// Has migration run before?
|
||||
public boolean hasMigrationRun() {
|
||||
return isBookmarksMigrated() && (getMigratedHistoryEntries() > 0);
|
||||
}
|
||||
|
||||
// Has migration entirely finished?
|
||||
public boolean hasMigrationFinished() {
|
||||
return isBookmarksMigrated() && isHistoryMigrated();
|
||||
}
|
||||
|
||||
public boolean isBookmarksMigrated() {
|
||||
return getPreferences().getBoolean(PREFS_MIGRATE_BOOKMARKS_DONE, false);
|
||||
}
|
||||
|
||||
protected SharedPreferences getPreferences() {
|
||||
return GeckoApp.mAppContext.getSharedPreferences(PREFS_NAME, 0);
|
||||
public boolean isHistoryMigrated() {
|
||||
return getPreferences().getBoolean(PREFS_MIGRATE_HISTORY_DONE, false);
|
||||
}
|
||||
|
||||
protected boolean isHistoryMigrated() {
|
||||
return getPreferences().getBoolean(PREFS_MIGRATE_HISTORY_DONE, false);
|
||||
// Has migration run before?
|
||||
protected boolean hasMigrationRun() {
|
||||
return isBookmarksMigrated() && (getMigratedHistoryEntries() > 0);
|
||||
}
|
||||
|
||||
// Has migration entirely finished?
|
||||
protected boolean hasMigrationFinished() {
|
||||
return isBookmarksMigrated() && isHistoryMigrated();
|
||||
}
|
||||
|
||||
protected SharedPreferences getPreferences() {
|
||||
return GeckoApp.mAppContext.getSharedPreferences(PREFS_NAME, 0);
|
||||
}
|
||||
|
||||
protected int getMigratedHistoryEntries() {
|
||||
|
@ -1478,39 +1478,45 @@ public class BrowserProvider extends ContentProvider {
|
||||
MatrixCursor cursor = new MatrixCursor(projection);
|
||||
MatrixCursor.RowBuilder row = cursor.newRow();
|
||||
synchronized (this) {
|
||||
boolean wantBookmarks = false;
|
||||
boolean wantHistory = false;
|
||||
boolean needBookmarks = false;
|
||||
boolean needHistory = false;
|
||||
|
||||
for (String key : projection) {
|
||||
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.");
|
||||
}
|
||||
|
||||
row.add(bookmarksDone ? 1 : 0);
|
||||
}
|
||||
wantBookmarks = true;
|
||||
} 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);
|
||||
}
|
||||
wantHistory = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (wantHistory || wantBookmarks) {
|
||||
ProfileMigrator migrator =
|
||||
new ProfileMigrator(mContext.getContentResolver(), profileDir);
|
||||
|
||||
needBookmarks = wantBookmarks && !migrator.isBookmarksMigrated();
|
||||
needHistory = wantHistory && !migrator.isHistoryMigrated();
|
||||
|
||||
if (needBookmarks || needHistory) {
|
||||
migrator.launch();
|
||||
|
||||
needBookmarks = wantBookmarks && !migrator.isBookmarksMigrated();
|
||||
needHistory = wantHistory && !migrator.isHistoryMigrated();
|
||||
// Bookmarks are expected to finish at the first run.
|
||||
if (needBookmarks) {
|
||||
Log.w(LOGTAG, "Bookmarks migration did not finish.");
|
||||
}
|
||||
}
|
||||
|
||||
// Now set the results.
|
||||
if (wantBookmarks)
|
||||
row.add(needBookmarks ? 0 : 1);
|
||||
if (wantHistory)
|
||||
row.add(needHistory ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user