Bug 1213490 - review: Move BrowserApp.getOtherSyncClientCount -> TabsAccessor.getRemoteClientCount. r=me
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 27 Oct 2015 17:08:28 -0700
changeset 304997 81f5d579fb2bbef17eeb2a9a80c16d05fc9e399d
parent 304996 e0fc8e81cc7013751be22a27b538ddf1ffabcbc3
child 304998 ac1ec5e7fb8a3709ac8e5d9e5f29458e4f33747f
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1213490
milestone44.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 1213490 - review: Move BrowserApp.getOtherSyncClientCount -> TabsAccessor.getRemoteClientCount. r=me
mobile/android/base/BrowserApp.java
mobile/android/base/db/LocalTabsAccessor.java
mobile/android/base/db/StubBrowserDB.java
mobile/android/base/db/TabsAccessor.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -3386,17 +3386,20 @@ public class BrowserApp extends GeckoApp
         if (account == null) {
             // TODO (bug 1217164): Go back to previous tab on back press
             final Intent intent = new Intent(FxAccountConstants.ACTION_FXA_GET_STARTED);
             intent.putExtra(FxAccountWebFlowActivity.EXTRA_ENDPOINT, FxAccountConstants.ENDPOINT_PREFERENCES);
             startActivity(intent);
             return;
         }
 
-        if (getOtherSyncClientCount() == 0) {
+        final BrowserDB browserDB = GeckoProfile.get(this).getDB();
+        final TabsAccessor tabsAccessor = browserDB.getTabsAccessor();
+        final int remoteClientCount = tabsAccessor.getRemoteClientCount(this);
+        if (remoteClientCount == 0) {
             final Toast toast = Toast.makeText(this, R.string.menu_no_synced_devices, Toast.LENGTH_LONG);
             toast.show();
 
         } else {
             String url = selectedTab.getURL();
             if (url != null) {
                 if (AboutPages.isAboutReader(url)) {
                     url = ReaderModeUtils.getUrlFromAboutReader(url);
@@ -3404,31 +3407,16 @@ public class BrowserApp extends GeckoApp
                 final Intent sendToDeviceIntent = GeckoAppShell.getShareIntent(getContext(), url,
                         "text/plain", selectedTab.getDisplayTitle());
                 sendToDeviceIntent.setClass(getContext(), ShareDialog.class);
                 startActivity(sendToDeviceIntent);
             }
         }
     }
 
-    private int getOtherSyncClientCount() {
-        final BrowserDB browserDB = GeckoProfile.get(this).getDB();
-        final TabsAccessor tabsAccessor = browserDB.getTabsAccessor();
-        final Cursor remoteClientsCursor = tabsAccessor.getRemoteClientsByRecencyCursor(this);
-        if (remoteClientsCursor == null) {
-            return 0;
-        }
-
-        try {
-            return remoteClientsCursor.getCount();
-        } finally {
-            remoteClientsCursor.close();
-        }
-    }
-
     @Override
     public boolean onMenuItemLongClick(MenuItem item) {
         if (item.getItemId() == R.id.reload) {
             Tab tab = Tabs.getInstance().getSelectedTab();
             if (tab != null) {
                 tab.doReload(true);
 
                 Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "reload_force");
--- a/mobile/android/base/db/LocalTabsAccessor.java
+++ b/mobile/android/base/db/LocalTabsAccessor.java
@@ -67,16 +67,30 @@ public class LocalTabsAccessor implement
     private final Uri clientsUriWithProfile;
 
     public LocalTabsAccessor(String profileName) {
         tabsUriWithProfile = DBUtils.appendProfileWithDefault(profileName, BrowserContract.Tabs.CONTENT_URI);
         clientsUriWithProfile = DBUtils.appendProfileWithDefault(profileName, BrowserContract.Clients.CONTENT_URI);
         clientsRecencyUriWithProfile = DBUtils.appendProfileWithDefault(profileName, BrowserContract.Clients.CONTENT_RECENCY_URI);
     }
 
+    @Override
+    public int getRemoteClientCount(final Context context) {
+        final Cursor remoteClientsCursor = getRemoteClientsByRecencyCursor(context);
+        if (remoteClientsCursor == null) {
+            return 0;
+        }
+
+        try {
+            return remoteClientsCursor.getCount();
+        } finally {
+            remoteClientsCursor.close();
+        }
+    }
+
     /**
      * Extracts a List of just RemoteClients from a cursor.
      * The supplied cursor should be grouped by guid and sorted by most recently used.
      */
     @Override
     public List<RemoteClient> getClientsWithoutTabsByRecencyFromCursor(Cursor cursor) {
         final ArrayList<RemoteClient> clients = new ArrayList<>(cursor.getCount());
 
--- a/mobile/android/base/db/StubBrowserDB.java
+++ b/mobile/android/base/db/StubBrowserDB.java
@@ -113,16 +113,21 @@ class StubURLMetadata implements URLMeta
     }
 }
 
 class StubTabsAccessor implements TabsAccessor {
     public StubTabsAccessor() {
     }
 
     @Override
+    public int getRemoteClientCount(Context context) {
+        return 0;
+    }
+
+    @Override
     public List<RemoteClient> getClientsWithoutTabsByRecencyFromCursor(Cursor cursor) {
         return new ArrayList<>();
     }
 
     @Override
     public List<RemoteClient> getClientsFromCursor(final Cursor cursor) {
         return new ArrayList<RemoteClient>();
     }
--- a/mobile/android/base/db/TabsAccessor.java
+++ b/mobile/android/base/db/TabsAccessor.java
@@ -12,16 +12,17 @@ import org.mozilla.gecko.Tab;
 
 import java.util.List;
 
 public interface TabsAccessor {
     public interface OnQueryTabsCompleteListener {
         public void onQueryTabsComplete(List<RemoteClient> clients);
     }
 
+    public int getRemoteClientCount(Context context);
     public Cursor getRemoteClientsByRecencyCursor(Context context);
     public Cursor getRemoteTabsCursor(Context context);
     public Cursor getRemoteTabsCursor(Context context, int limit);
     public List<RemoteClient> getClientsWithoutTabsByRecencyFromCursor(final Cursor cursor);
     public List<RemoteClient> getClientsFromCursor(final Cursor cursor);
     public void getTabs(final Context context, final OnQueryTabsCompleteListener listener);
     public void getTabs(final Context context, final int limit, final OnQueryTabsCompleteListener listener);
     public void persistLocalTabs(final ContentResolver cr, final Iterable<Tab> tabs);