Bug 788021 - Part 3: Use nsMemoryReporterManager::MinimizeMemoryUsage in aboutMemory.js. r=njn
authorJustin Lebar <justin.lebar@gmail.com>
Tue, 02 Oct 2012 21:19:11 -0400
changeset 109085 a67a2a9abebb6b071b271b8086a71d40c28f5c4a
parent 109084 deb340fb0b07cd36090f245080ada96d76fee869
child 109086 9e38c551860548f77d289ac26baf1e0ee2ac0330
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersnjn
bugs788021
milestone18.0a1
Bug 788021 - Part 3: Use nsMemoryReporterManager::MinimizeMemoryUsage in aboutMemory.js. r=njn
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -137,48 +137,16 @@ function onUnload()
   // onLoadAbout{Memory,Compartments} might not fire.
   if (gChildMemoryListener) {
     let os = Cc["@mozilla.org/observer-service;1"].
         getService(Ci.nsIObserverService);
     os.removeObserver(gChildMemoryListener, "child-memory-reporter-update");
   }
 }
 
-// For maximum effect, this returns to the event loop between each
-// notification.  See bug 610166 comment 12 for an explanation.
-// Ideally a single notification would be enough.
-function minimizeMemoryUsage3x(fAfter)
-{
-  let i = 0;
-
-  function runSoon(f)
-  {
-    let tm = Cc["@mozilla.org/thread-manager;1"]
-              .getService(Ci.nsIThreadManager);
-
-    tm.mainThread.dispatch({ run: f }, Ci.nsIThread.DISPATCH_NORMAL);
-  }
-
-  function sendHeapMinNotificationsInner()
-  {
-    let os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
-    os.notifyObservers(null, "memory-pressure", "heap-minimize");
-
-    if (++i < 3) {
-      runSoon(sendHeapMinNotificationsInner);
-    } else {
-      os.notifyObservers(null, "after-minimize-memory-usage", "about:memory");
-      runSoon(fAfter);
-    }
-  }
-
-  sendHeapMinNotificationsInner();
-}
-
 //---------------------------------------------------------------------------
 
 /**
  * Iterates over each reporter and multi-reporter.
  *
  * @param aIgnoreSingle
  *        Function that indicates if we should skip a single reporter, based
  *        on its path.
@@ -540,17 +508,17 @@ function appendAboutMemoryFooter(aBody)
 
   let div1 = appendElement(aBody, "div");
 
   // The "Update" button has an id so it can be clicked in a test.
   appendButton(div1, UpDesc, updateAboutMemory, "Update", "updateButton");
   appendButton(div1, GCDesc, doGlobalGC,        "GC");
   appendButton(div1, CCDesc, doCC,              "CC");
   appendButton(div1, MPDesc,
-               function() { minimizeMemoryUsage3x(updateAboutMemory); },
+               function() { gMgr.minimizeMemoryUsage(updateAboutMemory); },
                "Minimize memory usage");
 
   // The standard file input element is ugly.  So we hide it, and add a button
   // that when clicked invokes the input element.
   let input = appendElementWithText(div1, "input", "hidden", "input text");
   input.type = "file";
   input.id = "fileInput";   // has an id so it can be invoked by a test
   input.addEventListener("change", function() {
@@ -1494,17 +1462,17 @@ function appendSectionHeader(aP, aText)
 function onLoadAboutCompartments()
 {
   // First generate the page, then minimize memory usage to collect any dead
   // compartments, then update the page.  The first generation step may sound
   // unnecessary, but it avoids a short delay in showing content when the page
   // is loaded, which makes test_aboutcompartments.xul more reliable (see bug
   // 729018 for details).
   updateAboutCompartments();
-  minimizeMemoryUsage3x(
+  gMgr.minimizeMemoryUsage(
     function() { addChildObserversAndUpdate(updateAboutCompartments); });
 }
 
 /**
  * Top-level function that does the work of generating the page.
  */
 function updateAboutCompartments()
 {