Bug 749857 - Don't upload history records without URI or visits. r=liuche, a=android-only
--- 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);