Bug 1280409 - Guard against cursor failures while migrating data from HistoryExtensionsDB. r=sebastian, a=gchang
authorGrigory Kruglov <gkruglov@mozilla.com>
Thu, 23 Jun 2016 06:04:59 -0700
changeset 341885 00e9101b9ed0353afd4e7dd956a063d7ac511c91
parent 341884 a5b1d40aa344f53215c8b76c03bbe9ea6b77717d
child 341886 dd939576757577e1580b84e0820f9eb2d77dd303
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, gchang
bugs1280409
milestone49.0a2
Bug 1280409 - Guard against cursor failures while migrating data from HistoryExtensionsDB. r=sebastian, a=gchang MozReview-Commit-ID: 138SK46rgfi
mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
--- 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.