Bug 1274029 - Part 2: Update aggregates during local browsing r=sebastian
authorGrigory Kruglov <gkruglov@mozilla.com>
Fri, 27 May 2016 23:50:29 -0700
changeset 338898 ce62fcd4df4d3c7dd31c92dd7d73d736a043cb0e
parent 338897 28b948e9cad9f93cab45cdb8947784352af5b25b
child 338899 4b6a54c20fff6cc1205a7098e403b2b27bf82c2a
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1274029
milestone49.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 1274029 - Part 2: Update aggregates during local browsing r=sebastian MozReview-Commit-ID: 9Z9uFKxbRZm
mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -176,17 +176,21 @@ public class BrowserProvider extends Sha
         map = new HashMap<String, String>();
         map.put(History._ID, History._ID);
         map.put(History.TITLE, History.TITLE);
         map.put(History.URL, History.URL);
         map.put(History.FAVICON, History.FAVICON);
         map.put(History.FAVICON_ID, History.FAVICON_ID);
         map.put(History.FAVICON_URL, History.FAVICON_URL);
         map.put(History.VISITS, History.VISITS);
+        map.put(History.LOCAL_VISITS, History.LOCAL_VISITS);
+        map.put(History.REMOTE_VISITS, History.REMOTE_VISITS);
         map.put(History.DATE_LAST_VISITED, History.DATE_LAST_VISITED);
+        map.put(History.LOCAL_DATE_LAST_VISITED, History.LOCAL_DATE_LAST_VISITED);
+        map.put(History.REMOTE_DATE_LAST_VISITED, History.REMOTE_DATE_LAST_VISITED);
         map.put(History.DATE_CREATED, History.DATE_CREATED);
         map.put(History.DATE_MODIFIED, History.DATE_MODIFIED);
         map.put(History.GUID, History.GUID);
         map.put(History.IS_DELETED, History.IS_DELETED);
         HISTORY_PROJECTION_MAP = Collections.unmodifiableMap(map);
 
         // Visits
         URI_MATCHER.addURI(BrowserContract.AUTHORITY, "visits", VISITS);
@@ -1382,19 +1386,25 @@ public class BrowserProvider extends Sha
 
     private int updateOrInsertHistory(Uri uri, ContentValues values, String selection,
             String[] selectionArgs) {
         final int updated = updateHistory(uri, values, selection, selectionArgs);
         if (updated > 0) {
             return updated;
         }
 
-        // Insert a new entry if necessary
+        // Insert a new entry if necessary, setting visit and date aggregate values.
         if (!values.containsKey(History.VISITS)) {
             values.put(History.VISITS, 1);
+            values.put(History.LOCAL_VISITS, 1);
+        } else {
+            values.put(History.LOCAL_VISITS, values.getAsInteger(History.VISITS));
+        }
+        if (values.containsKey(History.DATE_LAST_VISITED)) {
+            values.put(History.LOCAL_DATE_LAST_VISITED, values.getAsLong(History.DATE_LAST_VISITED));
         }
         if (!values.containsKey(History.TITLE)) {
             values.put(History.TITLE, values.getAsString(History.URL));
         }
 
         if (0 <= insertHistory(uri, values)) {
             return 1;
         }
@@ -1415,22 +1425,27 @@ public class BrowserProvider extends Sha
         // Use the simple code path for easy updates.
         if (!shouldIncrementVisits(uri)) {
             trace("Updating history meta data only");
             return db.update(TABLE_HISTORY, values, selection, selectionArgs);
         }
 
         trace("Updating history meta data and incrementing visits");
 
+        if (values.containsKey(History.DATE_LAST_VISITED)) {
+            values.put(History.LOCAL_DATE_LAST_VISITED, values.getAsLong(History.DATE_LAST_VISITED));
+        }
+
         // Update data and increment visits by 1.
         final long incVisits = 1;
 
         // Create a separate set of values that will be updated as an expression.
         final ContentValues visits = new ContentValues();
         visits.put(History.VISITS, History.VISITS + " + " + incVisits);
+        visits.put(History.LOCAL_VISITS, History.LOCAL_VISITS + " + " + incVisits);
 
         final ContentValues[] valuesAndVisits = { values,  visits };
         final UpdateOperation[] ops = { UpdateOperation.ASSIGN, UpdateOperation.EXPRESSION };
 
         return DBUtils.updateArrays(db, TABLE_HISTORY, valuesAndVisits, ops, selection, selectionArgs);
     }
 
     private long insertVisitForHistory(Uri uri, ContentValues values, String selection, String[] selectionArgs) {