Bug 1316021 - Remove unnecessary static fields; r?sebastian draft
authorShan <11812r@gmail.com>
Sat, 26 Nov 2016 11:07:08 +0530
changeset 444088 224ae339045710da145452cc0cdc12f69433594b
parent 443898 e18a36f02a39a629305eb04535a7374e337b6427
child 444089 f8a80586a08a5b476d57cb2ba00c02c4fa624783
push id37195
push userbmo:11812r@gmail.com
push dateSat, 26 Nov 2016 05:38:39 +0000
reviewerssebastian
bugs1316021
milestone53.0a1
Bug 1316021 - Remove unnecessary static fields; r?sebastian MozReview-Commit-ID: 5Z2SNqIRkRq
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/widget/GeckoActionProvider.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -1465,17 +1465,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
@@ -762,17 +762,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();
                 return;
 
             } else if (event.equals("Accessibility:Event")) {
                 GeckoAccessibility.sendAccessibilityEvent(message);
@@ -2285,24 +2285,26 @@ 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(Context context) {
+        GeckoApplication app = (GeckoApplication)context;
+        if (app != null)
+            app.getExternalFilesDir("temp");
+        return null;
     }
 
     // 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/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(",");