Bug 1264057 - Don't show stale clients on the History Panel r=margaret
authorGrigory Kruglov <gkruglov@mozilla.com>
Tue, 07 Jun 2016 14:48:16 -0700
changeset 325959 11880fa53889c4b79a2b6289958ee3b8031eb03f
parent 325958 5119ac972910e0f2f90c2cd90552201905526075
child 325960 c6b4171833bd9806319fd0eb97e0591d241d1808
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1264057
milestone50.0a1
Bug 1264057 - Don't show stale clients on the History Panel r=margaret Currently we might have old (aka stale) clients appear on the History panel, which could be confusing. This patch modifies underlying query to select only those clients whose LAST_MODIFIED timestamp is newer than three weeks ago. MozReview-Commit-ID: JsZJwNONDJG
mobile/android/base/java/org/mozilla/gecko/db/LocalTabsAccessor.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/LocalTabsAccessor.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalTabsAccessor.java
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.db;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UIAsyncTask;
@@ -22,16 +23,17 @@ import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
 import android.text.TextUtils;
 import android.text.format.DateUtils;
 import android.util.Log;
 
 public class LocalTabsAccessor implements TabsAccessor {
     private static final String LOGTAG = "GeckoTabsAccessor";
+    private static final long THREE_WEEKS_IN_MILLISECONDS = TimeUnit.MILLISECONDS.convert(21L, TimeUnit.DAYS);
 
     public static final String[] TABS_PROJECTION_COLUMNS = new String[] {
                                                                 BrowserContract.Tabs.TITLE,
                                                                 BrowserContract.Tabs.URL,
                                                                 BrowserContract.Clients.GUID,
                                                                 BrowserContract.Clients.NAME,
                                                                 BrowserContract.Tabs.LAST_USED,
                                                                 BrowserContract.Clients.LAST_MODIFIED,
@@ -43,16 +45,18 @@ public class LocalTabsAccessor implement
                                                                     BrowserContract.Clients.NAME,
                                                                     BrowserContract.Clients.LAST_MODIFIED,
                                                                     BrowserContract.Clients.DEVICE_TYPE
                                                             };
 
     private static final String REMOTE_CLIENTS_SELECTION = BrowserContract.Clients.GUID + " IS NOT NULL";
     private static final String LOCAL_TABS_SELECTION = BrowserContract.Tabs.CLIENT_GUID + " IS NULL";
     private static final String REMOTE_TABS_SELECTION = BrowserContract.Tabs.CLIENT_GUID + " IS NOT NULL";
+    private static final String REMOTE_TABS_SELECTION_CLIENT_RECENCY = REMOTE_TABS_SELECTION +
+            " AND " + BrowserContract.Clients.LAST_MODIFIED + " > ?";
 
     private static final String REMOTE_TABS_SORT_ORDER =
             // Most recently synced clients first.
             BrowserContract.Clients.LAST_MODIFIED + " DESC, " +
             // If two clients somehow had the same last modified time, this will
             // group them (arbitrarily).
             BrowserContract.Clients.GUID + " DESC, " +
             // Within a single client, most recently used tabs first.
@@ -182,22 +186,23 @@ public class LocalTabsAccessor implement
         Uri uri = tabsUriWithProfile;
 
         if (limit > 0) {
             uri = uri.buildUpon()
                      .appendQueryParameter(BrowserContract.PARAM_LIMIT, String.valueOf(limit))
                      .build();
         }
 
-        final Cursor cursor =  context.getContentResolver().query(uri,
+        final String threeWeeksAgoTimestampMillis = Long.valueOf(
+                System.currentTimeMillis() - THREE_WEEKS_IN_MILLISECONDS).toString();
+        return context.getContentResolver().query(uri,
                                                             TABS_PROJECTION_COLUMNS,
-                                                            REMOTE_TABS_SELECTION,
-                                                            null,
+                                                            REMOTE_TABS_SELECTION_CLIENT_RECENCY,
+                                                            new String[] {threeWeeksAgoTimestampMillis},
                                                             REMOTE_TABS_SORT_ORDER);
-        return cursor;
     }
 
     // This method returns all tabs from all remote clients,
     // ordered by most recent client first, most recent tab first
     @Override
     public void getTabs(final Context context, final OnQueryTabsCompleteListener listener) {
         getTabs(context, 0, listener);
     }