Bug 975434 - Remove the ability to cancel memory minimizations. r=njn
authorGabriele Svelto <gsvelto@mozilla.com>
Tue, 25 Feb 2014 16:37:30 +0100
changeset 170912 a21fc292b2eac11ef03e18675d98c8ceb17adf52
parent 170911 dd0f72140555e291f05dc29e9de7d40d99f649ad
child 170913 058d484e50349fe461d44a1501f96ce76b93ddf9
child 170969 626d99c084cb8aa80bc58df9949d798edea510e3
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersnjn
bugs975434
milestone30.0a1
Bug 975434 - Remove the ability to cancel memory minimizations. r=njn
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/PContent.ipdl
xpcom/base/nsIMemoryReporter.idl
xpcom/base/nsMemoryInfoDumper.cpp
xpcom/base/nsMemoryReporterManager.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -1556,41 +1556,17 @@ ContentChild::RecvMinimizeMemoryUsage()
         // GC thread could be frozen.
         return true;
     }
 #endif
     nsCOMPtr<nsIMemoryReporterManager> mgr =
         do_GetService("@mozilla.org/memory-reporter-manager;1");
     NS_ENSURE_TRUE(mgr, true);
 
-    nsCOMPtr<nsICancelableRunnable> runnable =
-        do_QueryReferent(mMemoryMinimizerRunnable);
-
-    // Cancel the previous task if it's still pending.
-    if (runnable) {
-        runnable->Cancel();
-        runnable = nullptr;
-    }
-
-    mgr->MinimizeMemoryUsage(/* callback = */ nullptr,
-                             getter_AddRefs(runnable));
-    mMemoryMinimizerRunnable = do_GetWeakReference(runnable);
-    return true;
-}
-
-bool
-ContentChild::RecvCancelMinimizeMemoryUsage()
-{
-    nsCOMPtr<nsICancelableRunnable> runnable =
-        do_QueryReferent(mMemoryMinimizerRunnable);
-    if (runnable) {
-        runnable->Cancel();
-        mMemoryMinimizerRunnable = nullptr;
-    }
-
+    mgr->MinimizeMemoryUsage(/* callback = */ nullptr);
     return true;
 }
 
 bool
 ContentChild::RecvNotifyPhoneStateChange(const nsString& aState)
 {
   nsCOMPtr<nsIObserverService> os = services::GetObserverService();
   if (os) {
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -237,17 +237,16 @@ public:
                                       const bool& aIsSharing,
                                       const bool& aIsFormatting) MOZ_OVERRIDE;
 
     virtual bool RecvNuwaFork() MOZ_OVERRIDE;
 
     virtual bool
     RecvNotifyProcessPriorityChanged(const hal::ProcessPriority& aPriority) MOZ_OVERRIDE;
     virtual bool RecvMinimizeMemoryUsage() MOZ_OVERRIDE;
-    virtual bool RecvCancelMinimizeMemoryUsage() MOZ_OVERRIDE;
 
     virtual bool RecvLoadAndRegisterSheet(const URIParams& aURI,
                                           const uint32_t& aType) MOZ_OVERRIDE;
     virtual bool RecvUnregisterSheet(const URIParams& aURI, const uint32_t& aType) MOZ_OVERRIDE;
 
     virtual bool RecvNotifyPhoneStateChange(const nsString& state) MOZ_OVERRIDE;
 
     void AddIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS);
@@ -302,17 +301,16 @@ private:
 
 #ifdef ANDROID
     gfxIntSize mScreenSize;
 #endif
 
     bool mIsForApp;
     bool mIsForBrowser;
     nsString mProcessName;
-    nsWeakPtr mMemoryMinimizerRunnable;
 
     static ContentChild* sSingleton;
 
     DISALLOW_EVIL_CONSTRUCTORS(ContentChild);
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -329,17 +329,16 @@ child:
                      int32_t mountGeneration, bool isMediaPresent,
                      bool isSharing, bool isFormatting);
 
     // Ask the Nuwa process to create a new child process.
     NuwaFork();
 
     NotifyProcessPriorityChanged(ProcessPriority priority);
     MinimizeMemoryUsage();
-    CancelMinimizeMemoryUsage();
 
     /**
      * Used to manage nsIStyleSheetService across processes.
      */
     async LoadAndRegisterSheet(URIParams uri, uint32_t type);
     async UnregisterSheet(URIParams uri, uint32_t type);
 
     NotifyPhoneStateChange(nsString newState);
--- a/xpcom/base/nsIMemoryReporter.idl
+++ b/xpcom/base/nsIMemoryReporter.idl
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
-interface nsICancelableRunnable;
 interface nsIDOMWindow;
 interface nsIRunnable;
 interface nsISimpleEnumerator;
 
 /*
  * Memory reporters measure Firefox's memory usage.  They are primarily used to
  * generate the about:memory page.  You should read
  * https://wiki.mozilla.org/Memory_Reporting before writing a memory
@@ -174,17 +173,17 @@ interface nsIMemoryReporter : nsISupport
 };
 
 [scriptable, function, uuid(548b3909-c04d-4ca6-8466-b8bee3837457)]
 interface nsIFinishReportingCallback : nsISupports
 {
   void callback(in nsISupports data);
 };
 
-[scriptable, builtinclass, uuid(e4e4ca56-13e0-46f1-b3c5-62d2c09fc98e)]
+[scriptable, builtinclass, uuid(12e08b1b-6590-4f78-996b-d9062c17e856)]
 interface nsIMemoryReporterManager : nsISupports
 {
   /*
    * Initialize.
    */
   void init();
 
   /*
@@ -345,19 +344,19 @@ 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 if it's not
-   * null.  Returns a reference to the runnable used for carrying out the task.
+   * null.
    */
-  nsICancelableRunnable minimizeMemoryUsage(in nsIRunnable callback);
+  void minimizeMemoryUsage(in nsIRunnable callback);
 
   /*
    * Measure the memory that is known to be owned by this tab, split up into
    * several broad categories.  Note that this will be an underestimate of the
    * true number, due to imperfect memory reporter coverage (corresponding to
    * about:memory's "heap-unclassified"), and due to some memory shared between
    * tabs not being counted.
    *
--- a/xpcom/base/nsMemoryInfoDumper.cpp
+++ b/xpcom/base/nsMemoryInfoDumper.cpp
@@ -1004,18 +1004,17 @@ nsMemoryInfoDumper::DumpMemoryInfoToTemp
     nsRefPtr<DumpMemoryInfoToTempDirRunnable> callback =
       new DumpMemoryInfoToTempDirRunnable(identifier,
                                           /* minimizeMemoryUsage = */ false,
                                           /* dumpChildProcesses = */ false);
     nsCOMPtr<nsIMemoryReporterManager> mgr =
       do_GetService("@mozilla.org/memory-reporter-manager;1");
     if (NS_WARN_IF(!mgr))
       return NS_ERROR_FAILURE;
-    nsCOMPtr<nsICancelableRunnable> runnable;
-    mgr->MinimizeMemoryUsage(callback, getter_AddRefs(runnable));
+    mgr->MinimizeMemoryUsage(callback);
     return NS_OK;
   }
 
   return DumpProcessMemoryInfoToTempDir(identifier);
 }
 
 // This dumps the JSON footer and closes the file, and then calls the given
 // nsIFinishDumpingCallback.
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -1553,31 +1553,26 @@ namespace {
 /**
  * This runnable lets us implement
  * nsIMemoryReporterManager::MinimizeMemoryUsage().  We fire a heap-minimize
  * notification, spin the event loop, and repeat this process a few times.
  *
  * When this sequence finishes, we invoke the callback function passed to the
  * runnable's constructor.
  */
-class MinimizeMemoryUsageRunnable : public nsCancelableRunnable
+class MinimizeMemoryUsageRunnable : public nsRunnable
 {
 public:
   MinimizeMemoryUsageRunnable(nsIRunnable* aCallback)
     : mCallback(aCallback)
     , mRemainingIters(sNumIters)
-    , mCanceled(false)
   {}
 
   NS_IMETHOD Run()
   {
-    if (mCanceled) {
-      return NS_OK;
-    }
-
     nsCOMPtr<nsIObserverService> os = services::GetObserverService();
     if (!os) {
       return NS_ERROR_FAILURE;
     }
 
     if (mRemainingIters == 0) {
       os->NotifyObservers(nullptr, "after-minimize-memory-usage",
                           MOZ_UTF16("MinimizeMemoryUsageRunnable"));
@@ -1590,51 +1585,33 @@ public:
     os->NotifyObservers(nullptr, "memory-pressure",
                         MOZ_UTF16("heap-minimize"));
     mRemainingIters--;
     NS_DispatchToMainThread(this);
 
     return NS_OK;
   }
 
-  NS_IMETHOD Cancel()
-  {
-    if (mCanceled) {
-      return NS_ERROR_UNEXPECTED;
-    }
-
-    mCanceled = true;
-
-    return NS_OK;
-  }
-
 private:
   // Send sNumIters heap-minimize notifications, spinning the event
   // loop after each notification (see bug 610166 comment 12 for an
   // explanation), because one notification doesn't cut it.
   static const uint32_t sNumIters = 3;
 
   nsCOMPtr<nsIRunnable> mCallback;
   uint32_t mRemainingIters;
-  bool mCanceled;
 };
 
 } // anonymous namespace
 
 NS_IMETHODIMP
-nsMemoryReporterManager::MinimizeMemoryUsage(nsIRunnable* aCallback,
-                                             nsICancelableRunnable** aResult)
+nsMemoryReporterManager::MinimizeMemoryUsage(nsIRunnable* aCallback)
 {
-  if (NS_WARN_IF(!aResult)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
-  nsRefPtr<nsICancelableRunnable> runnable =
+  nsRefPtr<MinimizeMemoryUsageRunnable> runnable =
     new MinimizeMemoryUsageRunnable(aCallback);
-  NS_ADDREF(*aResult = runnable);
 
   return NS_DispatchToMainThread(runnable);
 }
 
 NS_IMETHODIMP
 nsMemoryReporterManager::SizeOfTab(nsIDOMWindow* aTopWindow,
                                    int64_t* aJSObjectsSize,
                                    int64_t* aJSStringsSize,