Bug 800166 - Fire a low-memory notification when a B2G process is backgrounded. r=gwagner,bent
authorJustin Lebar <justin.lebar@gmail.com>
Mon, 22 Oct 2012 15:40:19 -0400
changeset 111206 56a682c947c43dbbd1bbf4f255da94fcf3af3866
parent 111205 3d3039772d4aa1377407afcbc91da1c0e87421aa
child 111207 04b94f89672f6982e936395c83a7ade1b0e0b554
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersgwagner, bent
bugs800166
milestone19.0a1
Bug 800166 - Fire a low-memory notification when a B2G process is backgrounded. r=gwagner,bent
dom/ipc/ProcessPriorityManager.cpp
xpcom/base/nsIMemoryReporter.idl
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -293,16 +293,23 @@ ProcessPriorityManager::OnGracePeriodTim
 
   // mProcessPriority should already be BACKGROUND: We set it in
   // SetPriority(BACKGROUND), and we canceled this timer if there was an
   // intervening SetPriority(FOREGROUND) call.
   MOZ_ASSERT(mProcessPriority == PROCESS_PRIORITY_BACKGROUND);
 
   mGracePeriodTimer = nullptr;
   hal::SetProcessPriority(getpid(), PROCESS_PRIORITY_BACKGROUND);
+
+  // We're in the background; dump as much memory as we can.
+  nsCOMPtr<nsIMemoryReporterManager> mgr =
+    do_GetService("@mozilla.org/memory-reporter-manager;1");
+  if (mgr) {
+    mgr->MinimizeMemoryUsage(/* callback = */ nullptr);
+  }
 }
 
 } // anonymous namespace
 
 void
 InitProcessPriorityManager()
 {
   if (sInitialized) {
--- a/xpcom/base/nsIMemoryReporter.idl
+++ b/xpcom/base/nsIMemoryReporter.idl
@@ -290,17 +290,18 @@ interface nsIMemoryReporterManager : nsI
 
   /*
    * This attribute indicates if moz_malloc_usable_size() works.
    */
   [infallible] readonly attribute boolean hasMozMallocUsableSize;
 
   /*
    * Run a series of GC/CC's in an attempt to minimize the application's memory
-   * usage.  When we're finished, we invoke the given runnable.
+   * usage.  When we're finished, we invoke the given runnable if it's not
+   * null.
    */
   void minimizeMemoryUsage(in nsIRunnable callback);
 };
 
 %{C++
 
 /*
  * Note that this defaults 'process' to "", which is usually what's desired.