Bug 739515 - Defensive coding for Fennec history entries. r=emtwo,nalexander
authorRichard Newman <rnewman@mozilla.com>
Tue, 27 Mar 2012 10:47:26 -0700
changeset 90430 a856b9136fd1351e7fb4272cbe21517ff0fab967
parent 90429 c8e6770642a0b5adcc3644c1665c2b548651a88e
child 90431 56789e683c23ecb10aaba419d05e4568e173574c
push id22358
push userkhuey@mozilla.com
push dateWed, 28 Mar 2012 14:41:10 +0000
treeherdermozilla-central@c3fd0768d46a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemtwo, nalexander
bugs739515
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 739515 - Defensive coding for Fennec history entries. r=emtwo,nalexander
mobile/android/base/sync/repositories/android/AndroidBrowserHistoryDataExtender.java
mobile/android/base/sync/repositories/android/AndroidBrowserHistoryRepositorySession.java
mobile/android/base/sync/repositories/android/AndroidBrowserRepositoryDataAccessor.java
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserHistoryDataExtender.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserHistoryDataExtender.java
@@ -133,16 +133,21 @@ public class AndroidBrowserHistoryDataEx
     SQLiteDatabase db = this.getCachedReadableDatabase();
     Cursor cur = queryHelper.safeQuery(db, ".fetch", TBL_HISTORY_EXT,
         TBL_COLUMNS,
         where, args);
     return cur;
   }
 
   public JSONArray visitsForGUID(String guid) throws NullCursorException {
+    if (guid == null) {
+      Logger.warn(LOG_TAG, "Asked for visits for null GUID.");
+      return new JSONArray();
+    }
+
     Logger.debug(LOG_TAG, "Fetching visits for GUID " + guid);
     Cursor visits = fetch(guid);
     try {
       if (!visits.moveToFirst()) {
         // Cursor is empty.
         return new JSONArray();
       } else {
         return RepoUtils.getJSONArrayFromCursor(visits, COL_VISITS);
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserHistoryRepositorySession.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserHistoryRepositorySession.java
@@ -1,19 +1,22 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.sync.repositories.android;
 
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
+import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.sync.repositories.InactiveSessionException;
+import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException;
 import org.mozilla.gecko.sync.repositories.NullCursorException;
 import org.mozilla.gecko.sync.repositories.Repository;
+import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate;
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
 import org.mozilla.gecko.sync.repositories.domain.HistoryRecord;
 import org.mozilla.gecko.sync.repositories.domain.Record;
 
 import android.content.Context;
 import android.database.Cursor;
 import android.util.Log;
 
@@ -24,16 +27,28 @@ public class AndroidBrowserHistoryReposi
   public static final long DEFAULT_VISIT_TYPE = 1;
 
   public AndroidBrowserHistoryRepositorySession(Repository repository, Context context) {
     super(repository);
     dbHelper = new AndroidBrowserHistoryDataAccessor(context);
   }
 
   @Override
+  public void begin(RepositorySessionBeginDelegate delegate) throws InvalidSessionTransitionException {
+    // HACK: Fennec creates history records without a GUID. Mercilessly drop
+    // them on the floor. See Bug 739514.
+    try {
+      dbHelper.delete(BrowserContract.History.GUID + " IS NULL", null);
+    } catch (Exception e) {
+      // Ignore.
+    }
+    super.begin(delegate);
+  }
+
+  @Override
   protected Record retrieveDuringStore(Cursor cur) {
     return RepoUtils.historyFromMirrorCursor(cur);
   }
 
   @Override
   protected Record retrieveDuringFetch(Cursor cur) {
     return RepoUtils.historyFromMirrorCursor(cur);
   }
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserRepositoryDataAccessor.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserRepositoryDataAccessor.java
@@ -87,20 +87,24 @@ public abstract class AndroidBrowserRepo
       }
     }
   }
 
   public String dateModifiedWhere(long timestamp) {
     return BrowserContract.SyncColumns.DATE_MODIFIED + " >= " + Long.toString(timestamp);
   }
 
-  public void wipe() {
+  public void delete(String where, String[] args) {
     Uri uri = getUri();
-    Logger.debug(LOG_TAG, "Wiping: " + uri);
-    context.getContentResolver().delete(uri, null, null);
+    context.getContentResolver().delete(uri, where, args);
+  }
+
+  public void wipe() {
+    Logger.debug(LOG_TAG, "Wiping.");
+    delete(null, null);
   }
 
   public void purgeDeleted() throws NullCursorException {
     String where = BrowserContract.SyncColumns.IS_DELETED + "= 1";
     Uri uri = getUri();
     Logger.info(LOG_TAG, "Purging deleted from: " + uri);
     context.getContentResolver().delete(uri, where, null);
   }