Bug 1280409 - Guard against cursor failures while migrating data from HistoryExtensionsDB r=sebastian
MozReview-Commit-ID: 138SK46rgfi
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
@@ -756,16 +756,19 @@ public final class BrowserDatabaseHelper
}
}
/**
* We used to have a separate history extensions database which was used by Sync to store arrays
* of visits for individual History GUIDs. It was only used by Sync.
* This function migrates contents of that database over to the Visits table.
*
+ * Warning to callers: this method might throw IllegalStateException if we fail to allocate a
+ * cursor to read HistoryExtensionsDB data for whatever reason. See Bug 1280409.
+ *
* @param historyExtensionDb Source History Extensions database
* @param db Destination database
*/
private void copyHistoryExtensionDataToVisitsTable(final SQLiteDatabase historyExtensionDb, final SQLiteDatabase db) {
final String historyExtensionTable = "HistoryExtension";
final String columnGuid = "guid";
final String columnVisits = "visits";
@@ -1767,24 +1770,30 @@ public final class BrowserDatabaseHelper
// Otherwise, we risk overwhelming their Top Sites with remote history, just as we did before this migration.
try {
// If FxAccount exists (Sync is enabled) then port data over to the Visits table.
if (FirefoxAccounts.firefoxAccountsExist(mContext)) {
try {
historyExtensionDb = SQLiteDatabase.openDatabase(historyExtensionsDatabase.getPath(), null,
SQLiteDatabase.OPEN_READONLY);
+ if (historyExtensionDb != null) {
+ copyHistoryExtensionDataToVisitsTable(historyExtensionDb, db);
+ }
+
// If we fail to open HistoryExtensionDatabase, then synthesize visits marking them as remote
} catch (SQLiteException e) {
Log.w(LOGTAG, "Couldn't open history extension database; synthesizing visits instead", e);
synthesizeAndInsertVisits(db, false);
- }
- if (historyExtensionDb != null) {
- copyHistoryExtensionDataToVisitsTable(historyExtensionDb, db);
+ // It's possible that we might fail to copy over visit data from the HistoryExtensionsDB,
+ // so let's synthesize visits marking them as remote. See Bug 1280409.
+ } catch (IllegalStateException e) {
+ Log.w(LOGTAG, "Couldn't copy over history extension data; synthesizing visits instead", e);
+ synthesizeAndInsertVisits(db, false);
}
// FxAccount doesn't exist, but there's evidence Sync was enabled at some point.
// Synthesize visits from History table marking them all as remote.
} else if (historyExtensionsDatabase.exists()) {
synthesizeAndInsertVisits(db, false);
// FxAccount doesn't exist and there's no evidence sync was ever enabled.