Bug 1316021 - Remove unnecessary static fields; r=sebastian
authorShan <11812r@gmail.com>
Mon, 19 Dec 2016 17:37:33 +0100
changeset 326519 5a74fd7f6dddecd85da653dd1fab9e546fecb2e0
parent 326518 efd1d7e036e0fe71b1f7a024eb0e31564f844905
child 326520 9098c0cb192578f74019366ef341169e6825ac74
push id31106
push userkwierso@gmail.com
push dateTue, 20 Dec 2016 19:42:03 +0000
treeherdermozilla-central@7083c0d30e75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1316021
milestone53.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 1316021 - Remove unnecessary static fields; r=sebastian
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -1472,17 +1472,17 @@ public class BrowserApp extends GeckoApp
                 nfc.setNdefPushMessageCallback(null, this);
             }
         }
 
         for (final BrowserAppDelegate delegate : delegates) {
             delegate.onDestroy(this);
         }
 
-        deleteTempFiles();
+        deleteTempFiles(getApplicationContext());
 
         if (mDoorHangerPopup != null)
             mDoorHangerPopup.destroy();
         if (mFormAssistPopup != null)
             mFormAssistPopup.destroy();
         if (mTextSelection != null)
             mTextSelection.destroy();
         NotificationHelper.destroy();
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -72,16 +72,17 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
 import android.os.Handler;
 import android.os.PowerManager;
 import android.os.Process;
 import android.os.StrictMode;
 import android.provider.ContactsContract;
 import android.provider.MediaStore.Images.Media;
+import android.support.annotation.NonNull;
 import android.support.annotation.WorkerThread;
 import android.support.design.widget.Snackbar;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.Base64;
 import android.util.Log;
 import android.util.SparseBooleanArray;
 import android.view.Gravity;
@@ -626,17 +627,17 @@ public abstract class GeckoApp
             // know that mHealthRecorder will exist. That doesn't stop us being
             // paranoid.
             // This method is cheap, so don't spawn a new runnable.
             final HealthRecorder rec = mHealthRecorder;
             if (rec != null) {
               rec.recordGeckoStartupTime(mGeckoReadyStartupTimer.getElapsed());
             }
 
-            GeckoApplication.get().onDelayedStartup();
+            ((GeckoApplication) getApplicationContext()).onDelayedStartup();
 
         } else if (event.equals("Gecko:Exited")) {
             // Gecko thread exited first; let GeckoApp die too.
             doShutdown();
 
         } else if ("Accessibility:Ready".equals(event)) {
             GeckoAccessibility.updateAccessibilitySettings(this);
 
@@ -2297,24 +2298,23 @@ public abstract class GeckoApp
     }
 
     public void showSDKVersionError() {
         final String message = getString(R.string.unsupported_sdk_version, Build.CPU_ABI, Build.VERSION.SDK_INT);
         Toast.makeText(this, message, Toast.LENGTH_LONG).show();
     }
 
     // Get a temporary directory, may return null
-    public static File getTempDirectory() {
-        File dir = GeckoApplication.get().getExternalFilesDir("temp");
-        return dir;
+    public static File getTempDirectory(@NonNull Context context) {
+        return context.getApplicationContext().getExternalFilesDir("temp");
     }
 
     // Delete any files in our temporary directory
-    public static void deleteTempFiles() {
-        File dir = getTempDirectory();
+    public static void deleteTempFiles(Context context) {
+        File dir = getTempDirectory(context);
         if (dir == null)
             return;
         File[] files = dir.listFiles();
         if (files == null)
             return;
         for (File file : files) {
             file.delete();
         }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -36,32 +36,25 @@ import org.mozilla.gecko.util.ThreadUtil
 
 import java.io.File;
 import java.lang.reflect.Method;
 
 public class GeckoApplication extends Application
     implements ContextGetter {
     private static final String LOG_TAG = "GeckoApplication";
 
-    private static volatile GeckoApplication instance;
-
     private boolean mInBackground;
     private boolean mPausedGecko;
 
     private LightweightTheme mLightweightTheme;
 
     private RefWatcher mRefWatcher;
 
     public GeckoApplication() {
         super();
-        instance = this;
-    }
-
-    public static GeckoApplication get() {
-        return instance;
     }
 
     public static RefWatcher getRefWatcher(Context context) {
         GeckoApplication app = (GeckoApplication) context.getApplicationContext();
         return app.mRefWatcher;
     }
 
     public static void watchReference(Context context, Object object) {
--- a/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
@@ -53,17 +53,17 @@ public class MediaControlService extends
     private HeadSetStateReceiver mHeadSetStateReceiver;
 
     private PrefsHelper.PrefHandler mPrefsObserver;
     private final String[] mPrefs = { MEDIA_CONTROL_PREF };
 
     private boolean mInitialize = false;
     private boolean mIsMediaControlPrefOn = true;
 
-    private static WeakReference<Tab> mTabReference = new WeakReference<>(null);
+    private WeakReference<Tab> mTabReference = new WeakReference<>(null);
 
     private int minCoverSize;
     private int coverSize;
 
     @Override
     public void onCreate() {
         initialize();
         mHeadSetStateReceiver = new HeadSetStateReceiver().registerReceiver(getApplicationContext());
--- a/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java
@@ -285,31 +285,31 @@ public class GeckoActionProvider {
     /**
      * Downloads the URI pointed to by a share intent, and alters the intent to point to the
      * locally stored file.
      *
      * @param intent share intent to alter in place.
      */
     public void downloadImageForIntent(final Intent intent) {
         final String src = IntentUtils.getStringExtraSafe(intent, Intent.EXTRA_TEXT);
-        final File dir = GeckoApp.getTempDirectory();
+        final File dir = GeckoApp.getTempDirectory(mContext);
 
         if (src == null || dir == null) {
             // We should be, but currently aren't, statically guaranteed an Activity context.
             // Try our best.
             if (mContext instanceof Activity) {
                 SnackbarBuilder.builder((Activity) mContext)
                         .message(mContext.getApplicationContext().getString(R.string.share_image_failed))
                         .duration(Snackbar.LENGTH_LONG)
                         .buildAndShow();
             }
             return;
         }
 
-        GeckoApp.deleteTempFiles();
+        GeckoApp.deleteTempFiles(mContext);
 
         String type = intent.getType();
         OutputStream os = null;
         try {
             // Create a temporary file for the image
             if (src.startsWith("data:")) {
                 final int dataStart = src.indexOf(",");