Freeze nsIMemory interface bug 99151 r=rpotts@netscape.com, sr=brendan@netscape.com
This commit is contained in:
@@ -904,7 +904,7 @@ nsXBLService::AttachGlobalDragHandler(nsIDOMEventReceiver* aReceiver)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXBLService::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData)
|
nsXBLService::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData)
|
||||||
{
|
{
|
||||||
if (nsCRT::strcmp(aTopic, NS_MEMORY_PRESSURE_TOPIC) == 0)
|
if (nsCRT::strcmp(aTopic, "memory-pressure") == 0)
|
||||||
FlushMemory();
|
FlushMemory();
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@@ -1506,7 +1506,7 @@ NS_NewXBLService(nsIXBLService** aResult)
|
|||||||
// so it can flush the LRU list in low-memory situations.
|
// so it can flush the LRU list in low-memory situations.
|
||||||
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
||||||
if (os)
|
if (os)
|
||||||
os->AddObserver(result, NS_MEMORY_PRESSURE_TOPIC, PR_TRUE);
|
os->AddObserver(result, "memory-pressure", PR_TRUE);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -797,7 +797,7 @@ nsStringBundleService::Init()
|
|||||||
{
|
{
|
||||||
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
||||||
if (os)
|
if (os)
|
||||||
os->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC, PR_TRUE);
|
os->AddObserver(this, "memory-pressure", PR_TRUE);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
@@ -807,7 +807,7 @@ nsStringBundleService::Observe(nsISupports* aSubject,
|
|||||||
const char* aTopic,
|
const char* aTopic,
|
||||||
const PRUnichar* aSomeData)
|
const PRUnichar* aSomeData)
|
||||||
{
|
{
|
||||||
if (nsCRT::strcmp(NS_MEMORY_PRESSURE_TOPIC, aTopic) == 0)
|
if (nsCRT::strcmp("memory-pressure", aTopic) == 0)
|
||||||
flushBundleCache();
|
flushBundleCache();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1146,7 +1146,7 @@ nsZipReaderCache::Init(PRUint32 cacheSize)
|
|||||||
do_GetService("@mozilla.org/observer-service;1", &rv);
|
do_GetService("@mozilla.org/observer-service;1", &rv);
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
rv = os->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC, PR_TRUE);
|
rv = os->AddObserver(this, "memory-pressure", PR_TRUE);
|
||||||
}
|
}
|
||||||
// ignore failure of the observer registration.
|
// ignore failure of the observer registration.
|
||||||
|
|
||||||
@@ -1359,7 +1359,7 @@ nsZipReaderCache::Observe(nsISupports *aSubject,
|
|||||||
const char *aTopic,
|
const char *aTopic,
|
||||||
const PRUnichar *aSomeData)
|
const PRUnichar *aSomeData)
|
||||||
{
|
{
|
||||||
if (nsCRT::strcmp(aTopic, NS_MEMORY_PRESSURE_TOPIC) == 0) {
|
if (nsCRT::strcmp(aTopic, "memory-pressure") == 0) {
|
||||||
nsAutoLock lock(mLock);
|
nsAutoLock lock(mLock);
|
||||||
while (PR_TRUE) {
|
while (PR_TRUE) {
|
||||||
nsHashKey* flushable = nsnull;
|
nsHashKey* flushable = nsnull;
|
||||||
|
|||||||
@@ -35,31 +35,38 @@
|
|||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
/**
|
|
||||||
* <font color="#FF0000"><b> W A R N I N G
|
|
||||||
* <p>This API is currently under review in preparation for making it an
|
|
||||||
* officially supported part of the mozilla platform. Please submit comments
|
|
||||||
* to porkjockeys@mozilla.org before 6/15/00. Until that time, it is not
|
|
||||||
* advised to base commercial products on this API because it is subject to
|
|
||||||
* change. Use at your own risk!
|
|
||||||
* </b></font>
|
|
||||||
*
|
|
||||||
* @status UNDER_REVIEW
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* nsIMemory: interface to allocate and deallocate memory. Also provides
|
* nsIMemory: interface to allocate and deallocate memory. Also provides
|
||||||
* for notifications in low-memory situations.
|
* for notifications in low-memory situations.
|
||||||
*
|
*
|
||||||
* A client that wishes to be notified of low memory situations (for
|
* A client that wishes to be notified of low memory situations (for
|
||||||
* example, because the client maintains a large memory cache that
|
* example, because the client maintains a large memory cache that
|
||||||
* could be released when memory is tight) may register with the
|
* could be released when memory is tight) should register with the
|
||||||
* observer service (see nsIObserverService) using the
|
* observer service (see nsIObserverService) using the topic
|
||||||
* NS_MEMORY_PRESSURE_TOPIC ("memory-pressure") as the topic for
|
* "memory-pressure". There are three specific types of notications
|
||||||
* observation.
|
* that can occur. These types will be passed as the |aData|
|
||||||
|
* parameter of the of the "memory-pressure" notification:
|
||||||
|
*
|
||||||
|
* "low-memory"
|
||||||
|
* This will be passed as the extra data when the pressure
|
||||||
|
* observer is being asked to flush for low-memory conditions.
|
||||||
|
*
|
||||||
|
* "heap-minimize"
|
||||||
|
* This will be passed as the extra data when the pressure
|
||||||
|
* observer is being asked to flush because of a heap minimize
|
||||||
|
* call.
|
||||||
|
*
|
||||||
|
* "alloc-failure"
|
||||||
|
* This will be passed as the extra data when the pressure
|
||||||
|
* observer has been asked to flush because a malloc() or
|
||||||
|
* realloc() has failed.
|
||||||
|
*
|
||||||
|
* @status FROZEN
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[scriptable, uuid(59e7e77a-38e4-11d4-8cf5-0060b0fc14a3)]
|
[scriptable, uuid(59e7e77a-38e4-11d4-8cf5-0060b0fc14a3)]
|
||||||
interface nsIMemory : nsISupports
|
interface nsIMemory : nsISupports
|
||||||
{
|
{
|
||||||
@@ -112,41 +119,8 @@ interface nsIMemory : nsISupports
|
|||||||
/**
|
/**
|
||||||
* This predicate can be used to determine if we're in a low-memory
|
* This predicate can be used to determine if we're in a low-memory
|
||||||
* situation (what constitutes low-memory is platform dependent). This
|
* situation (what constitutes low-memory is platform dependent). This
|
||||||
* can be used to trigger the memory flushers.
|
* can be used to trigger the memory pressure observers.
|
||||||
*/
|
*/
|
||||||
boolean isLowMemory();
|
boolean isLowMemory();
|
||||||
};
|
};
|
||||||
|
|
||||||
%{C++
|
|
||||||
/**
|
|
||||||
* This is the topic that a memory pressure observer
|
|
||||||
* should use with the observer service.
|
|
||||||
*/
|
|
||||||
#define NS_MEMORY_PRESSURE_TOPIC "memory-pressure"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will be passed as the extra data when the flusher
|
|
||||||
* is being asked to flush for low-memory conditions.
|
|
||||||
*/
|
|
||||||
#define NS_MEMORY_PRESSURE_LOW_MEMORY "low-memory"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will be passed as the extra data when the flusher
|
|
||||||
* is being asked to flush because of a heap minimize call.
|
|
||||||
*/
|
|
||||||
#define NS_MEMORY_PRESSURE_HEAP_MINIMIZE "heap-minimize"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will be passed as the extra data when the flusher
|
|
||||||
* has been asked to flush because a malloc() or realloc()
|
|
||||||
* has failed.
|
|
||||||
*/
|
|
||||||
#define NS_MEMORY_PRESSURE_ALLOC_FAILURE "alloc-failure"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%{C++
|
|
||||||
/**
|
|
||||||
* ContractID for the global memory service:
|
|
||||||
*/
|
|
||||||
#define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
|
|
||||||
%}
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ MemoryFlusher::Run()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (isLowMemory) {
|
if (isLowMemory) {
|
||||||
mMemoryImpl->FlushMemory(NS_LITERAL_STRING(NS_MEMORY_PRESSURE_LOW_MEMORY).get(), PR_FALSE);
|
mMemoryImpl->FlushMemory(NS_LITERAL_STRING("low-memory").get(), PR_FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ nsMemoryImpl::Alloc(PRSize size)
|
|||||||
void* result = MALLOC1(size);
|
void* result = MALLOC1(size);
|
||||||
if (! result) {
|
if (! result) {
|
||||||
// Request an asynchronous flush
|
// Request an asynchronous flush
|
||||||
FlushMemory(NS_LITERAL_STRING(NS_MEMORY_PRESSURE_ALLOC_FAILURE).get(), PR_FALSE);
|
FlushMemory(NS_LITERAL_STRING("alloc-failure").get(), PR_FALSE);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ nsMemoryImpl::Realloc(void * ptr, PRSize size)
|
|||||||
void* result = REALLOC1(ptr, size);
|
void* result = REALLOC1(ptr, size);
|
||||||
if (! result) {
|
if (! result) {
|
||||||
// Request an asynchronous flush
|
// Request an asynchronous flush
|
||||||
FlushMemory(NS_LITERAL_STRING(NS_MEMORY_PRESSURE_ALLOC_FAILURE).get(), PR_FALSE);
|
FlushMemory(NS_LITERAL_STRING("alloc-failure").get(), PR_FALSE);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -345,7 +345,7 @@ nsMemoryImpl::Free(void * ptr)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMemoryImpl::HeapMinimize(PRBool aImmediate)
|
nsMemoryImpl::HeapMinimize(PRBool aImmediate)
|
||||||
{
|
{
|
||||||
return FlushMemory(NS_LITERAL_STRING(NS_MEMORY_PRESSURE_HEAP_MINIMIZE).get(), aImmediate);
|
return FlushMemory(NS_LITERAL_STRING("heap-minimize").get(), aImmediate);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@@ -457,7 +457,7 @@ nsMemoryImpl::RunFlushers(nsMemoryImpl* aSelf, const PRUnichar* aReason)
|
|||||||
{
|
{
|
||||||
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
||||||
if (os) {
|
if (os) {
|
||||||
os->NotifyObservers(aSelf, NS_MEMORY_PRESSURE_TOPIC, aReason);
|
os->NotifyObservers(aSelf, "memory-pressure", aReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,6 +45,8 @@
|
|||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "plevent.h"
|
#include "plevent.h"
|
||||||
|
|
||||||
|
#define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
|
||||||
|
|
||||||
struct PRLock;
|
struct PRLock;
|
||||||
class MemoryFlusher;
|
class MemoryFlusher;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user