зеркало из https://github.com/mozilla/pjs.git
Freeze nsIMemory interface bug 99151 r=rpotts@netscape.com, sr=brendan@netscape.com
This commit is contained in:
Родитель
3028af33af
Коммит
abb5f8b703
|
@ -904,7 +904,7 @@ nsXBLService::AttachGlobalDragHandler(nsIDOMEventReceiver* aReceiver)
|
|||
NS_IMETHODIMP
|
||||
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();
|
||||
|
||||
return NS_OK;
|
||||
|
@ -1506,7 +1506,7 @@ NS_NewXBLService(nsIXBLService** aResult)
|
|||
// so it can flush the LRU list in low-memory situations.
|
||||
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (os)
|
||||
os->AddObserver(result, NS_MEMORY_PRESSURE_TOPIC, PR_TRUE);
|
||||
os->AddObserver(result, "memory-pressure", PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -797,7 +797,7 @@ nsStringBundleService::Init()
|
|||
{
|
||||
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (os)
|
||||
os->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC, PR_TRUE);
|
||||
os->AddObserver(this, "memory-pressure", PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -807,7 +807,7 @@ nsStringBundleService::Observe(nsISupports* aSubject,
|
|||
const char* aTopic,
|
||||
const PRUnichar* aSomeData)
|
||||
{
|
||||
if (nsCRT::strcmp(NS_MEMORY_PRESSURE_TOPIC, aTopic) == 0)
|
||||
if (nsCRT::strcmp("memory-pressure", aTopic) == 0)
|
||||
flushBundleCache();
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -1146,7 +1146,7 @@ nsZipReaderCache::Init(PRUint32 cacheSize)
|
|||
do_GetService("@mozilla.org/observer-service;1", &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.
|
||||
|
||||
|
@ -1359,7 +1359,7 @@ nsZipReaderCache::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) {
|
||||
nsAutoLock lock(mLock);
|
||||
while (PR_TRUE) {
|
||||
nsHashKey* flushable = nsnull;
|
||||
|
|
|
@ -35,31 +35,38 @@
|
|||
*
|
||||
* ***** 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"
|
||||
|
||||
/**
|
||||
*
|
||||
* nsIMemory: interface to allocate and deallocate memory. Also provides
|
||||
* for notifications in low-memory situations.
|
||||
*
|
||||
* A client that wishes to be notified of low memory situations (for
|
||||
* example, because the client maintains a large memory cache that
|
||||
* could be released when memory is tight) may register with the
|
||||
* observer service (see nsIObserverService) using the
|
||||
* NS_MEMORY_PRESSURE_TOPIC ("memory-pressure") as the topic for
|
||||
* observation.
|
||||
* could be released when memory is tight) should register with the
|
||||
* observer service (see nsIObserverService) using the topic
|
||||
* "memory-pressure". There are three specific types of notications
|
||||
* 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)]
|
||||
interface nsIMemory : nsISupports
|
||||
{
|
||||
|
@ -112,41 +119,8 @@ interface nsIMemory : nsISupports
|
|||
/**
|
||||
* This predicate can be used to determine if we're in a low-memory
|
||||
* 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();
|
||||
};
|
||||
|
||||
%{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
|
||||
|
||||
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);
|
||||
if (! result) {
|
||||
// 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;
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ nsMemoryImpl::Realloc(void * ptr, PRSize size)
|
|||
void* result = REALLOC1(ptr, size);
|
||||
if (! result) {
|
||||
// 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;
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ nsMemoryImpl::Free(void * ptr)
|
|||
NS_IMETHODIMP
|
||||
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
|
||||
|
@ -457,7 +457,7 @@ nsMemoryImpl::RunFlushers(nsMemoryImpl* aSelf, const PRUnichar* aReason)
|
|||
{
|
||||
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (os) {
|
||||
os->NotifyObservers(aSelf, NS_MEMORY_PRESSURE_TOPIC, aReason);
|
||||
os->NotifyObservers(aSelf, "memory-pressure", aReason);
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "plevent.h"
|
||||
|
||||
#define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
|
||||
|
||||
struct PRLock;
|
||||
class MemoryFlusher;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче