[not part of build] Use nsIObserverService to shut down cache before XPCOM is shut down. r=gordon

This commit is contained in:
beard%netscape.com 2001-03-13 01:59:43 +00:00
Родитель 27feb04903
Коммит 2c47dd3f64
2 изменённых файлов: 18 добавлений и 2 удалений

16
netwerk/cache/src/nsCacheService.cpp поставляемый
Просмотреть файл

@ -35,13 +35,14 @@
#include "nsIEventQueue.h"
#include "nsProxiedService.h"
#include "nsICacheVisitor.h"
#include "nsIObserverService.h"
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
nsCacheService * nsCacheService::gService = nsnull;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheService, nsICacheService)
NS_IMPL_THREADSAFE_ISUPPORTS2(nsCacheService, nsICacheService, nsIObserver)
nsCacheService::nsCacheService()
: mCacheServiceLock(nsnull),
@ -103,6 +104,14 @@ nsCacheService::Init()
rv = mDiskDevice->Init();
if (NS_FAILED(rv)) goto error;
// observer XPCOM shutdown.
{
nsCOMPtr<nsIObserverService> observerService = do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
observerService->AddObserver(this, NS_LITERAL_STRING(NS_XPCOM_SHUTDOWN_OBSERVER_ID).get());
}
}
return NS_OK;
error:
@ -680,6 +689,11 @@ nsCacheService::ProcessPendingRequests(nsCacheEntry * entry)
return NS_OK;
}
NS_IMETHODIMP nsCacheService::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
return Shutdown();
}
/**
* Cache Service Utility Functions

4
netwerk/cache/src/nsCacheService.h поставляемый
Просмотреть файл

@ -32,6 +32,7 @@
#include "nsCacheSession.h"
#include "nsCacheDevice.h"
#include "nsCacheEntry.h"
#include "nsIObserver.h"
class nsCacheRequest;
@ -40,11 +41,12 @@ class nsCacheRequest;
* nsCacheService
*/
class nsCacheService : public nsICacheService
class nsCacheService : public nsICacheService, public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICACHESERVICE
NS_DECL_NSIOBSERVER
nsCacheService();
virtual ~nsCacheService();