Bug 749857 - Don't upload history records without URI or visits. r=liuche, a=android-only
authorRichard Newman <rnewman@mozilla.com>
Mon, 30 Apr 2012 13:40:34 -0700
changeset 94999 74108dd3201df330bb7f93d8064932c2b251503f
parent 94998 0d06d9f8e4f65ea1f1524b75943a296645e3c111
child 95000 a53189537295eabffb760bb38a411d119a48c543
child 109736 395864a65f2bdf96970145ac758041d741bdf94b
push idunknown
push userunknown
push dateunknown
reviewersliuche, android-only
bugs749857
milestone15.0a1
Bug 749857 - Don't upload history records without URI or visits. r=liuche, a=android-only
mobile/android/base/sync/repositories/android/RepoUtils.java
--- a/mobile/android/base/sync/repositories/android/RepoUtils.java
+++ b/mobile/android/base/sync/repositories/android/RepoUtils.java
@@ -114,30 +114,52 @@ public class RepoUtils {
     try {
       return (JSONArray) new JSONParser().parse(getStringFromCursor(cur, colId));
     } catch (ParseException e) {
       Logger.error(LOG_TAG, "JSON parsing error for " + colId, e);
       return null;
     }
   }
 
-  //Create a HistoryRecord object from a cursor on a row with a Moz History record in it
+  /**
+   * Create a HistoryRecord object from a cursor row.
+   *
+   * @return a HistoryRecord, or null if this row would produce
+   *         an invalid record (e.g., with a null URI or no visits).
+   */
   public static HistoryRecord historyFromMirrorCursor(Cursor cur) {
+    final String guid = getStringFromCursor(cur, BrowserContract.SyncColumns.GUID);
+    if (guid == null) {
+      Logger.debug(LOG_TAG, "Skipping history record with null GUID.");
+      return null;
+    }
 
-    String guid = getStringFromCursor(cur, BrowserContract.SyncColumns.GUID);
-    String collection = "history";
-    long lastModified = getLongFromCursor(cur, BrowserContract.SyncColumns.DATE_MODIFIED);
-    boolean deleted = getLongFromCursor(cur, BrowserContract.SyncColumns.IS_DELETED) == 1 ? true : false;
-    HistoryRecord rec = new HistoryRecord(guid, collection, lastModified, deleted);
+    final String historyURI = getStringFromCursor(cur, BrowserContract.History.URL);
+    if (historyURI == null || (historyURI.length() == 0)) {
+      Logger.debug(LOG_TAG, "Skipping history record " + guid + " with null or empty URI.");
+      return null;
+    }
+
+    final long visitCount = getLongFromCursor(cur, BrowserContract.History.VISITS);
+    if (visitCount <= 0) {
+      Logger.debug(LOG_TAG, "Skipping history record " + guid + " with <= 0 visit count.");
+      return null;
+    }
 
-    rec.title = getStringFromCursor(cur, BrowserContract.History.TITLE);
-    rec.histURI = getStringFromCursor(cur, BrowserContract.History.URL);
-    rec.androidID = getLongFromCursor(cur, BrowserContract.History._ID);
+    final String collection = "history";
+    final long lastModified = getLongFromCursor(cur, BrowserContract.SyncColumns.DATE_MODIFIED);
+    final boolean deleted = getLongFromCursor(cur, BrowserContract.SyncColumns.IS_DELETED) == 1 ? true : false;
+
+    final HistoryRecord rec = new HistoryRecord(guid, collection, lastModified, deleted);
+
+    rec.androidID         = getLongFromCursor(cur, BrowserContract.History._ID);
     rec.fennecDateVisited = getLongFromCursor(cur, BrowserContract.History.DATE_LAST_VISITED);
-    rec.fennecVisitCount = getLongFromCursor(cur, BrowserContract.History.VISITS);
+    rec.fennecVisitCount  = visitCount;
+    rec.histURI           = historyURI;
+    rec.title             = getStringFromCursor(cur, BrowserContract.History.TITLE);
 
     return logHistory(rec);
   }
 
   private static HistoryRecord logHistory(HistoryRecord rec) {
     try {
       Logger.debug(LOG_TAG, "Returning history record " + rec.guid + " (" + rec.androidID + ")");
       Logger.debug(LOG_TAG, "> Visited:          " + rec.fennecDateVisited);