webengine/osswebengine/MemoryManager/Src/MemoryPool.cpp
changeset 26 cb62a4f66ebe
parent 10 a359256acfc6
child 28 d39add9822e2
--- a/webengine/osswebengine/MemoryManager/Src/MemoryPool.cpp	Thu Dec 17 09:20:16 2009 +0200
+++ b/webengine/osswebengine/MemoryManager/Src/MemoryPool.cpp	Thu Jan 07 13:31:38 2010 +0200
@@ -28,6 +28,10 @@
 #include "SymbianDlHeap.h"
 #include <OOMMonitorSession.h>
 #include <hal.h>
+#include <avkon.hrh>
+#include <avkon.rsg>
+#include <StringLoader.h>
+#include <WebKit.rsg>
 
 // CONSTANTS
 
@@ -461,7 +465,10 @@
 //-----------------------------------------------------------------------------
 TAny* CNewSymbianHeapPool::DoAlloc( TUint aSize )
     {
-    return iAlloc->Alloc( aSize );
+    TAny *p = iAlloc->Alloc( aSize );
+    if (!p)
+        ShowOOMDialog();
+    return p;
     }
 
 //-----------------------------------------------------------------------------
@@ -477,6 +484,7 @@
     // check memory manager status
     if( !p || iMemStatus & ERescueOOM )
         {
+        ShowOOMDialog();
         if( !iIsCollecting )
             {
             CollectMemory();
@@ -551,7 +559,8 @@
 	if(req > 0)
 		return ETrue;
 	
-	// We haven't got the required amount free yet, try the browser heap.
+    // We haven't got the required amount free yet, pop an OOM dialog and then try the browser heap.
+    ShowOOMDialog();
 	CollectMemory(aTotalSize);
 	// ask the system how much is free now...
 	HAL::Get(HALData::EMemoryRAMFree, systemFreeMemory);
@@ -610,6 +619,9 @@
 
 CNewSymbianHeapPool::CNewSymbianHeapPool() : CMemoryPool()
 	{
+    isInitted = EFalse;
+    iOOMErrorDialog = 0;
+    iOOMMessage = 0;
 	}
 
 CNewSymbianHeapPool::~CNewSymbianHeapPool()
@@ -663,6 +675,55 @@
 	return CMemoryPool::Create();
 	}
 
+/*
+ * Initialize the OOM dialog and localized message resource
+ * This should be called as soon in the startup process as possible
+ * (unfortunately it can't be called until resources are already loaded)
+ * Note: apps are responsible for showing their own oom dialog; there
+ * is no system one AFAIK; at least we can re-use the oom localized
+ * resource message from elsewhere
+ */
+void CNewSymbianHeapPool::InitOOMDialog()
+    {
+    if (!isInitted)
+        {
+        isInitted = ETrue;
+        iOOMErrorDialog = CAknGlobalNote::NewL();
+        iOOMErrorDialog->SetSoftkeys(R_AVKON_SOFTKEYS_OK_EMPTY);
+        iOOMMessage = StringLoader::LoadL(R_QTN_BROWSER_DIALOG_OOM);
+        iOOMDisplayed = EFalse;
+        }
+    }
+
+void CNewSymbianHeapPool::ShowOOMDialog()
+    {
+    // Don't show it if we did once already
+    if (iOOMDisplayed)
+        return;
+
+    // If we got OOM, show a dialog (if the dialog was initted properly to begin with)
+    if (iOOMErrorDialog)
+        {
+        // If we couldn't load the message resource when we first initted, 
+        // try again now; this shouldn't ever happen
+        if (!iOOMMessage)
+            {
+            iOOMMessage = StringLoader::LoadL(R_QTN_BROWSER_DIALOG_OOM);
+            }
+        // If we have no dialog or message we unfortunately cannot display it!
+        if (iOOMMessage) 
+            {
+            iOOMErrorDialog->ShowNoteL(EAknGlobalWarningNote,iOOMMessage->Des());
+            iOOMDisplayed = ETrue;
+            }
+        }
+    }
+
+void CNewSymbianHeapPool::ResetOOMDialogDisplayed()
+    {
+    iOOMDisplayed = EFalse;
+    }
+
 #ifdef OOM_LOGGING   
 void CNewSymbianHeapPool::DumpHeapLogs()
     {