Bug 784040 - Add an intent to simulate an increase in memory pressure. r=mfinkle
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 27 Sep 2012 12:29:47 -0400
changeset 108423 8921d8bc93a29bd855a5d2b279f2997f629b1fb3
parent 108422 db369c141f937a4cdb5bc0ce559b6609453519d0
child 108424 e6fd6841e7f3bbf2a113da7c24a8ae7f3c9fcb14
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersmfinkle
bugs784040
milestone18.0a1
Bug 784040 - Add an intent to simulate an increase in memory pressure. r=mfinkle
mobile/android/base/MemoryMonitor.java
--- a/mobile/android/base/MemoryMonitor.java
+++ b/mobile/android/base/MemoryMonitor.java
@@ -29,16 +29,17 @@ import android.util.Log;
   * Synchronization note: MemoryMonitor contains an inner class PressureDecrementer. Both
   * of these classes may be accessed from various threads, and have both been designed to
   * be thread-safe. In terms of lock ordering, code holding the PressureDecrementer lock
   * is allowed to pick up the MemoryMonitor lock, but not vice-versa.
   */
 class MemoryMonitor extends BroadcastReceiver {
     private static final String LOGTAG = "GeckoMemoryMonitor";
     private static final String ACTION_MEMORY_DUMP = "org.mozilla.gecko.MEMORY_DUMP";
+    private static final String ACTION_FORCE_PRESSURE = "org.mozilla.gecko.FORCE_MEMORY_PRESSURE";
 
     private static final int MEMORY_PRESSURE_NONE = 0;
     private static final int MEMORY_PRESSURE_CLEANUP = 1;
     private static final int MEMORY_PRESSURE_LOW = 2;
     private static final int MEMORY_PRESSURE_MEDIUM = 3;
     private static final int MEMORY_PRESSURE_HIGH = 4;
 
     private static MemoryMonitor sInstance = new MemoryMonitor();
@@ -57,16 +58,17 @@ class MemoryMonitor extends BroadcastRec
         mStoragePressure = false;
     }
 
     public void init(Context 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);
     }
 
     public void onLowMemory() {
         Log.d(LOGTAG, "onLowMemory() notification received");
         increaseMemoryPressure(MEMORY_PRESSURE_HIGH);
     }
 
@@ -110,16 +112,18 @@ class MemoryMonitor extends BroadcastRec
             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";
             }
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Memory:Dump", label));
+        } else if (ACTION_FORCE_PRESSURE.equals(intent.getAction())) {
+            increaseMemoryPressure(MEMORY_PRESSURE_HIGH);
         }
     }
 
     private void increaseMemoryPressure(int level) {
         int oldLevel;
         synchronized (this) {
             // bump up our level if we're not already higher
             if (mMemoryPressure > level) {