Bug 1046709 - If visits are missing from sync hist record, insert a fake one r=nalexander
MozReview-Commit-ID: FGoRmjy7Nja
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/android/AndroidBrowserHistoryDataAccessor.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/android/AndroidBrowserHistoryDataAccessor.java
@@ -128,15 +128,26 @@ public class AndroidBrowserHistoryDataAc
Logger.debug(LOG_TAG, "Inserted " + inserted + " records, as expected.");
} else {
Logger.debug(LOG_TAG, "Inserted " +
inserted + " records but expected " +
size + " records; continuing to update visits.");
}
for (Record record : records) {
- VisitsHelper.bulkInsertRemoteVisits(
- context.getContentResolver(), record.guid, ((HistoryRecord) record).visits, true);
+ HistoryRecord rec = (HistoryRecord) record;
+
+ // Default history "visits" count is 1 (ensured on insertion), so in case visits array is empty/missing,
+ // we need to insert a fake visit to keep our counter and list of visits in sync.
+ if (rec.visits == null || rec.visits.size() == 0) {
+ ContentValues fakeVisit = new ContentValues();
+ fakeVisit.put(BrowserContract.Visits.HISTORY_GUID, rec.guid);
+ fakeVisit.put(BrowserContract.Visits.DATE_VISITED, rec.lastModified);
+ context.getContentResolver().insert(BrowserContract.Visits.CONTENT_URI, fakeVisit);
+ } else {
+ VisitsHelper.bulkInsertRemoteVisits(
+ context.getContentResolver(), rec.guid, rec.visits, true);
+ }
}
return inserted;
}
}