Bug 744961 - Safer handling of Context in MemoryMonitor. r=wesj
authorRichard Newman <rnewman@mozilla.com>
Sun, 21 Oct 2012 09:32:39 -0700
changeset 111180 d7e67c8d00e36f7c5d3e3264920dd973f0ddbfa1
parent 111179 0b6a823a8cfeba5f2184d8d53d21297fa064c7c9
child 111181 4b3247d6507b5452b5ef3c4953cfa37477f6cf0e
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerswesj
bugs744961
milestone19.0a1
Bug 744961 - Safer handling of Context in MemoryMonitor. r=wesj
mobile/android/base/MemoryMonitor.java
--- a/mobile/android/base/MemoryMonitor.java
+++ b/mobile/android/base/MemoryMonitor.java
@@ -49,26 +49,24 @@ class MemoryMonitor extends BroadcastRec
 
     static MemoryMonitor getInstance() {
         return sInstance;
     }
 
     private final PressureDecrementer mPressureDecrementer;
     private int mMemoryPressure;
     private boolean mStoragePressure;
-    private Context mContext;
 
     private MemoryMonitor() {
         mPressureDecrementer = new PressureDecrementer();
         mMemoryPressure = MEMORY_PRESSURE_NONE;
         mStoragePressure = false;
     }
 
     public void init(Context context) {
-        mContext = context;
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
         filter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
         filter.addAction(ACTION_MEMORY_DUMP);
         filter.addAction(ACTION_FORCE_PRESSURE);
         context.getApplicationContext().registerReceiver(this, filter);
     }
 
@@ -106,17 +104,17 @@ class MemoryMonitor extends BroadcastRec
         }
     }
 
     @Override
     public void onReceive(Context context, Intent intent) {
         if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(intent.getAction())) {
             Log.d(LOGTAG, "Device storage is low");
             mStoragePressure = true;
-            GeckoAppShell.getHandler().post(new StorageReducer());
+            GeckoAppShell.getHandler().post(new StorageReducer(context));
         } else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(intent.getAction())) {
             Log.d(LOGTAG, "Device storage is ok");
             mStoragePressure = false;
         } else if (ACTION_MEMORY_DUMP.equals(intent.getAction())) {
             String label = intent.getStringExtra("label");
             if (label == null) {
                 label = "default";
             }
@@ -202,16 +200,21 @@ class MemoryMonitor extends BroadcastRec
             }
 
             // need to keep decrementing
             GeckoAppShell.getHandler().postDelayed(this, DECREMENT_DELAY);
         }
     }
 
     class StorageReducer implements Runnable {
+        private final Context mContext;
+        public StorageReducer(final Context context) {
+            this.mContext = context;
+        }
+
         @Override
         public void run() {
             // this might get run right on startup, if so wait 10 seconds and try again
             if (!GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) {
                 GeckoAppShell.getHandler().postDelayed(this, 10000);
                 return;
             }