mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
make imagelib listen to the memory-pressure observer. bug #94454. patch from nivedita@netscape.com. r=pavlov sr=brendan
This commit is contained in:
parent
be398efa70
commit
dd685b2503
@ -57,10 +57,18 @@ static nsModuleComponentInfo components[] =
|
||||
imgRequestProxyConstructor, },
|
||||
};
|
||||
|
||||
PR_STATIC_CALLBACK(nsresult)
|
||||
imgCache_Initialize(nsIModule* aSelf)
|
||||
{
|
||||
imgCache::Init();
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
ImageModuleDestructor(nsIModule *self)
|
||||
imgCache_Shutdown(nsIModule* aSelf)
|
||||
{
|
||||
imgCache::Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_NSGETMODULE_WITH_DTOR(nsImageLib2Module, components, ImageModuleDestructor)
|
||||
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsImageLib2Module, components, imgCache_Initialize, imgCache_Shutdown)
|
||||
|
||||
|
@ -30,13 +30,15 @@
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIMemory.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
||||
#include "nsICache.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsICacheSession.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(imgCache, imgICache)
|
||||
NS_IMPL_ISUPPORTS3(imgCache, imgICache, nsIObserver, nsISupportsWeakReference)
|
||||
|
||||
imgCache::imgCache()
|
||||
{
|
||||
@ -49,6 +51,18 @@ imgCache::~imgCache()
|
||||
/* destructor code */
|
||||
}
|
||||
|
||||
nsresult imgCache::Init()
|
||||
{
|
||||
imgCache* cache = new imgCache();
|
||||
if(!cache) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1", &rv);
|
||||
if (NS_SUCCEEDED(rv) && os)
|
||||
rv = os->AddObserver(cache, "memory-pressure", PR_TRUE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* void clearCache (in boolean chrome); */
|
||||
NS_IMETHODIMP imgCache::ClearCache(PRBool chrome)
|
||||
{
|
||||
@ -255,3 +269,12 @@ PRBool imgCache::Remove(nsIURI *aKey)
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
imgCache::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData)
|
||||
{
|
||||
if (strcmp(aTopic, "memory-pressure") == 0)
|
||||
ClearCache(PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
*/
|
||||
|
||||
#include "imgICache.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
@ -37,15 +39,20 @@ class nsICacheEntryDescriptor;
|
||||
{0x83, 0x91, 0xe1, 0x42, 0x42, 0xc5, 0x9a, 0x41} \
|
||||
}
|
||||
|
||||
class imgCache : public imgICache
|
||||
class imgCache : public imgICache,
|
||||
public nsIObserver,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGICACHE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
imgCache();
|
||||
virtual ~imgCache();
|
||||
|
||||
static nsresult Init();
|
||||
|
||||
static void Shutdown(); // for use by the factory
|
||||
|
||||
/* additional members */
|
||||
|
Loading…
x
Reference in New Issue
Block a user