Bug 618533 - forward oom notifications to child content process. r=jdm a=blocking-fennec
authorDoug Turner <dougt@dougt.org>
Sat, 11 Dec 2010 14:36:08 -0800
changeset 59121 888d644578361acfc04c7c7e9f3a21ec3c19c6ba
parent 59120 fb5a4e4ce9994158af3c600ce86a8afe519ba719
child 59122 716d8622b175de62846e4bd93b302529e57faba6
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjdm, blocking-fennec
bugs618533
milestone2.0b8pre
Bug 618533 - forward oom notifications to child content process. r=jdm a=blocking-fennec
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/PContent.ipdl
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -581,10 +581,20 @@ ContentChild::RecvScreenSizeChanged(cons
 #ifdef ANDROID
     mScreenSize = size;
 #else
     NS_RUNTIMEABORT("Message currently only expected on android");
 #endif
   return true;
 }
 
+bool
+ContentChild::RecvFlushMemory(const nsString& reason)
+{
+    nsCOMPtr<nsIObserverService> os =
+        mozilla::services::GetObserverService();
+    if (os)
+	os->NotifyObservers(nsnull, "memory-pressure", reason.get());
+  return true;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -126,16 +126,19 @@ public:
     virtual bool RecvGeolocationUpdate(const GeoPosition& somewhere);
 
     virtual bool RecvAddPermission(const IPC::Permission& permission);
 
     virtual bool RecvAccelerationChanged(const double& x, const double& y,
                                          const double& z);
 
     virtual bool RecvScreenSizeChanged(const gfxIntSize &size);
+
+    virtual bool RecvFlushMemory(const nsString& reason);
+
 #ifdef ANDROID
     gfxIntSize GetScreenSize() { return mScreenSize; }
 #endif
 
 private:
     NS_OVERRIDE
     virtual void ActorDestroy(ActorDestroyReason why);
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -111,17 +111,19 @@ ContentParent::GetSingleton(PRBool aForc
                     gSingleton = parent;
                     nsCOMPtr<nsIPrefBranch2> prefs 
                         (do_GetService(NS_PREFSERVICE_CONTRACTID));
                     if (prefs) {  
                         prefs->AddObserver("", parent, PR_FALSE);
                     }
                 }
                 obs->AddObserver(
-                  parent, NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC, PR_FALSE); 
+                  parent, NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC, PR_FALSE);
+
+                obs->AddObserver(parent, "memory-pressure", PR_FALSE); 
             }
             nsCOMPtr<nsIThreadInternal>
                 threadInt(do_QueryInterface(NS_GetCurrentThread()));
             if (threadInt) {
                 threadInt->GetObserver(getter_AddRefs(parent->mOldObserver));
                 threadInt->SetObserver(parent);
             }
             if (obs) {
@@ -349,18 +351,22 @@ ContentParent::Observe(nsISupports* aSub
             
         Close();
         NS_ASSERTION(!mSubprocess, "Close should have nulled mSubprocess");
     }
 
     if (!mIsAlive || !mSubprocess)
         return NS_OK;
 
+    // listening for memory pressure event
+    if (!strcmp(aTopic, "memory-pressure")) {
+        SendFlushMemory(nsDependentString(aData));
+    }
     // listening for remotePrefs...
-    if (!strcmp(aTopic, "nsPref:changed")) {
+    else if (!strcmp(aTopic, "nsPref:changed")) {
         // We know prefs are ASCII here.
         NS_LossyConvertUTF16toASCII strData(aData);
 
         PrefTuple pref;
         nsCOMPtr<nsIPrefServiceInternal> prefService =
           do_GetService("@mozilla.org/preferences-service;1");
 
         prefService->MirrorPreference(strData, &pref);
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -111,16 +111,18 @@ child:
 
     // nsIPermissionManager messages
     AddPermission(Permission permission);
 
     AccelerationChanged(double x, double y, double z);
 
     ScreenSizeChanged(gfxIntSize size);
 
+    FlushMemory(nsString reason);
+
 parent:
     PNecko();
     PCrashReporter();
     
     PStorage(StorageConstructData data);
 
     PAudio(PRInt32 aNumChannels, PRInt32 aRate, PRInt32 aFormat);