Bug 1531047 - Part 1: Some code cleanup. r=petru
authorVlad Baicu <vlad.baicu@softvision.ro>
Fri, 15 Mar 2019 11:21:02 +0000
changeset 522029 069dea6b6bc5b0b4bc43d00e3b6e55c7b25ae245
parent 522028 e0fb5aa748b0a6d617c25bc104e3d271151c45c9
child 522030 36132f5347e8b31f4fe5b28d0bd182f6fe606237
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru
bugs1531047
milestone67.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 1531047 - Part 1: Some code cleanup. r=petru Differential Revision: https://phabricator.services.mozilla.com/D23528
mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueueService.java
--- a/mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueueService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabqueue/TabQueueService.java
@@ -99,20 +99,20 @@ public class TabQueueService extends Ser
 
         windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
 
         LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
         toastLayout = layoutInflater.inflate(R.layout.tab_queue_toast, null);
 
         final Resources resources = getResources();
 
-        TextView messageView = (TextView) toastLayout.findViewById(R.id.toast_message);
+        TextView messageView = toastLayout.findViewById(R.id.toast_message);
         messageView.setText(resources.getText(R.string.tab_queue_toast_message));
 
-        openNowButton = (Button) toastLayout.findViewById(R.id.toast_button);
+        openNowButton = toastLayout.findViewById(R.id.toast_button);
         openNowButton.setText(resources.getText(R.string.tab_queue_toast_action));
 
         toastLayoutParams = new WindowManager.LayoutParams(
                 WindowManager.LayoutParams.MATCH_PARENT,
                 WindowManager.LayoutParams.WRAP_CONTENT,
                 AppConstants.Versions.preO ?
                         WindowManager.LayoutParams.TYPE_PHONE :
                         WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
@@ -137,36 +137,33 @@ public class TabQueueService extends Ser
             final SafeIntent safeIntent = new SafeIntent(intent);
             final String intentUrl = safeIntent.getDataString();
 
             final long lastRunTime = sharedPreferences.getLong(GeckoPreferences.PREFS_TAB_QUEUE_LAST_TIME, 0);
             final boolean isWithinDoubleTapTimeLimit = System.currentTimeMillis() - lastRunTime < TOAST_DOUBLE_TAP_TIMEOUT_MILLIS;
 
             if (!TextUtils.isEmpty(lastUrl) && lastUrl.equals(intentUrl) && isWithinDoubleTapTimeLimit) {
                 // Background thread because we could do some file IO if we have to remove a url from the list.
-                tabQueueHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        // If there is a runnable around, that means that the previous process hasn't yet completed, so
-                        // we will need to prevent it from running and remove the view from the window manager.
-                        // If there is no runnable around then the url has already been added to the list, so we'll
-                        // need to remove it before proceeding or that url will open multiple times.
-                        if (stopServiceRunnable != null) {
-                            tabQueueHandler.removeCallbacks(stopServiceRunnable);
-                            stopSelfResult(stopServiceRunnable.getStartId());
-                            stopServiceRunnable = null;
-                            removeView();
-                        } else {
-                            TabQueueHelper.removeURLFromFile(applicationContext, intentUrl, TabQueueHelper.FILE_NAME);
-                        }
-                        openNow(safeIntent.getUnsafe());
+                tabQueueHandler.post(() -> {
+                    // If there is a runnable around, that means that the previous process hasn't yet completed, so
+                    // we will need to prevent it from running and remove the view from the window manager.
+                    // If there is no runnable around then the url has already been added to the list, so we'll
+                    // need to remove it before proceeding or that url will open multiple times.
+                    if (stopServiceRunnable != null) {
+                        tabQueueHandler.removeCallbacks(stopServiceRunnable);
+                        stopSelfResult(stopServiceRunnable.getStartId());
+                        stopServiceRunnable = null;
+                        removeView();
+                    } else {
+                        TabQueueHelper.removeURLFromFile(applicationContext, intentUrl, TabQueueHelper.FILE_NAME);
+                    }
+                    openNow(safeIntent.getUnsafe());
 
-                        Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "tabqueue-doubletap");
-                        stopSelfResult(startId);
-                    }
+                    Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "tabqueue-doubletap");
+                    stopSelfResult(startId);
                 });
 
                 return START_REDELIVER_INTENT;
             }
 
             sharedPreferences.edit().putString(GeckoPreferences.PREFS_TAB_QUEUE_LAST_SITE, intentUrl)
                                     .putLong(GeckoPreferences.PREFS_TAB_QUEUE_LAST_TIME, System.currentTimeMillis())
                                     .apply();
@@ -189,27 +186,24 @@ public class TabQueueService extends Ser
         stopServiceRunnable = new StopServiceRunnable(startId) {
             @Override
             public void onRun() {
                 addURLToTabQueue(intent, TabQueueHelper.FILE_NAME);
                 stopServiceRunnable = null;
             }
         };
 
-        openNowButton.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(final View view) {
-                tabQueueHandler.removeCallbacks(stopServiceRunnable);
-                stopServiceRunnable = null;
-                removeView();
-                openNow(intent);
+        openNowButton.setOnClickListener(view -> {
+            tabQueueHandler.removeCallbacks(stopServiceRunnable);
+            stopServiceRunnable = null;
+            removeView();
+            openNow(intent);
 
-                Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "tabqueue-now");
-                stopSelfResult(startId);
-            }
+            Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "tabqueue-now");
+            stopSelfResult(startId);
         });
 
         tabQueueHandler.postDelayed(stopServiceRunnable, TOAST_TIMEOUT);
 
         return START_REDELIVER_INTENT;
     }
 
     private void openNow(Intent intent) {
@@ -219,22 +213,19 @@ public class TabQueueService extends Ser
         startActivity(forwardIntent);
 
         TabQueueHelper.removeNotification(getApplicationContext());
 
         GeckoSharedPrefs.forApp(getApplicationContext()).edit().remove(GeckoPreferences.PREFS_TAB_QUEUE_LAST_SITE)
                                                                .remove(GeckoPreferences.PREFS_TAB_QUEUE_LAST_TIME)
                                                                .apply();
 
-        executorService.submit(new Runnable() {
-            @Override
-            public void run() {
-                int queuedTabCount = TabQueueHelper.getTabQueueLength(TabQueueService.this);
-                Telemetry.addToHistogram("FENNEC_TABQUEUE_QUEUESIZE", queuedTabCount);
-            }
+        executorService.submit(() -> {
+            int queuedTabCount = TabQueueHelper.getTabQueueLength(TabQueueService.this);
+            Telemetry.addToHistogram("FENNEC_TABQUEUE_QUEUESIZE", queuedTabCount);
         });
 
     }
 
     @SuppressLint("NewApi")
     @TargetApi(Build.VERSION_CODES.M)
     private void showSettingsNotification() {
         if (AppConstants.Versions.preMarshmallow) {
@@ -285,33 +276,30 @@ public class TabQueueService extends Ser
             // This should never happen, but let's return silently instead of crashing if it does.
             Log.w(LOGTAG, "Error adding URL to tab queue - invalid intent passed in.");
             return;
         }
         final SafeIntent safeIntent = new SafeIntent(intent);
         final String intentData = safeIntent.getDataString();
 
         // As we're doing disk IO, let's run this stuff in a separate thread.
-        executorService.submit(new Runnable() {
-            @Override
-            public void run() {
-                Context applicationContext = getApplicationContext();
-                final GeckoProfile profile = GeckoProfile.get(applicationContext);
-                int tabsQueued = TabQueueHelper.queueURL(profile, intentData, filename);
-                List<String> urls = TabQueueHelper.getLastURLs(applicationContext, filename);
+        executorService.submit(() -> {
+            Context applicationContext = getApplicationContext();
+            final GeckoProfile profile = GeckoProfile.get(applicationContext);
+            int tabsQueued = TabQueueHelper.queueURL(profile, intentData, filename);
+            List<String> urls = TabQueueHelper.getLastURLs(applicationContext, filename);
 
-                TabQueueHelper.showNotification(applicationContext, tabsQueued, urls);
+            TabQueueHelper.showNotification(applicationContext, tabsQueued, urls);
 
-                // Store the number of URLs queued so that we don't have to read and process the file to see if we have
-                // any urls to open.
-                // TODO: Use profile shared prefs when bug 1147925 gets fixed.
-                final SharedPreferences prefs = GeckoSharedPrefs.forApp(applicationContext);
+            // Store the number of URLs queued so that we don't have to read and process the file to see if we have
+            // any urls to open.
+            // TODO: Use profile shared prefs when bug 1147925 gets fixed.
+            final SharedPreferences prefs = GeckoSharedPrefs.forApp(applicationContext);
 
-                prefs.edit().putInt(TabQueueHelper.PREF_TAB_QUEUE_COUNT, tabsQueued).apply();
-            }
+            prefs.edit().putInt(TabQueueHelper.PREF_TAB_QUEUE_COUNT, tabsQueued).apply();
         });
     }
 
     @Override
     public void onDestroy() {
         super.onDestroy();
         handlerThread.quit();
     }
@@ -319,17 +307,17 @@ public class TabQueueService extends Ser
     /**
      * A modified Runnable which additionally removes the view from the window view hierarchy and stops the service
      * when run, unless explicitly instructed not to.
      */
     private abstract class StopServiceRunnable implements Runnable {
 
         private final int startId;
 
-        public StopServiceRunnable(final int startId) {
+        /*package*/ StopServiceRunnable(final int startId) {
             this.startId = startId;
         }
 
         public void run() {
             run(true);
         }
 
         public void run(final boolean shouldRemoveView) {
@@ -337,15 +325,15 @@ public class TabQueueService extends Ser
 
             if (shouldRemoveView) {
                 removeView();
             }
 
             stopSelfResult(startId);
         }
 
-        public int getStartId() {
+        /*package*/ int getStartId() {
             return startId;
         }
 
         public abstract void onRun();
     }
 }
\ No newline at end of file