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 95600 112c34415cff56a1090b26516bba4ffb1b9c4d72
parent 95599 e910b904f86b4b85c29ab7b5c83193fd3229e007
child 95601 1a94eae3f574fb57dd2d76500eb5707fa94da97f
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, android-only
bugs749857
milestone14.0a2
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);