Bug 399096 - nsDOMCacheUpdateService leaks. r=dcamp, sr=biesi, a=blocker

This commit is contained in:
jwalden@mit.edu 2007-11-08 21:12:59 -08:00
Родитель 5a746e48f3
Коммит f426e03c0a
2 изменённых файлов: 29 добавлений и 9 удалений

Просмотреть файл

@ -419,9 +419,10 @@ nsOfflineCacheUpdate::Init(PRBool aPartialUpdate,
nsresult rv; nsresult rv;
// Make sure the service has been initialized // Make sure the service has been initialized
if (!nsOfflineCacheUpdateService::GetInstance()) { nsOfflineCacheUpdateService* service =
nsOfflineCacheUpdateService::EnsureService();
if (!service)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
}
LOG(("nsOfflineCacheUpdate::Init [%p]", this)); LOG(("nsOfflineCacheUpdate::Init [%p]", this));
@ -649,8 +650,8 @@ nsOfflineCacheUpdate::Finish()
mState = STATE_FINISHED; mState = STATE_FINISHED;
nsOfflineCacheUpdateService *service = nsOfflineCacheUpdateService* service =
nsOfflineCacheUpdateService::GetInstance(); nsOfflineCacheUpdateService::EnsureService();
if (!mPartialUpdate) { if (!mPartialUpdate) {
if (mSucceeded) { if (mSucceeded) {
@ -822,8 +823,8 @@ nsOfflineCacheUpdate::Schedule()
{ {
LOG(("nsOfflineCacheUpdate::Schedule [%p]", this)); LOG(("nsOfflineCacheUpdate::Schedule [%p]", this));
nsOfflineCacheUpdateService *service = nsOfflineCacheUpdateService* service =
nsOfflineCacheUpdateService::GetInstance(); nsOfflineCacheUpdateService::EnsureService();
if (!service) { if (!service) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -837,8 +838,8 @@ nsOfflineCacheUpdate::ScheduleOnDocumentStop(nsIDOMDocument *aDocument)
{ {
LOG(("nsOfflineCacheUpdate::ScheduleOnDocumentStop [%p]", this)); LOG(("nsOfflineCacheUpdate::ScheduleOnDocumentStop [%p]", this));
nsOfflineCacheUpdateService *service = nsOfflineCacheUpdateService* service =
nsOfflineCacheUpdateService::GetInstance(); nsOfflineCacheUpdateService::EnsureService();
if (!service) { if (!service) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -930,6 +931,18 @@ nsOfflineCacheUpdateService::GetInstance()
return gOfflineCacheUpdateService; return gOfflineCacheUpdateService;
} }
nsOfflineCacheUpdateService *
nsOfflineCacheUpdateService::EnsureService()
{
if (!gOfflineCacheUpdateService) {
// Make the service manager hold a long-lived reference to the service
nsCOMPtr<nsIOfflineCacheUpdateService> service =
do_GetService(NS_OFFLINECACHEUPDATESERVICE_CONTRACTID);
}
return gOfflineCacheUpdateService;
}
nsresult nsresult
nsOfflineCacheUpdateService::Schedule(nsOfflineCacheUpdate *aUpdate) nsOfflineCacheUpdateService::Schedule(nsOfflineCacheUpdate *aUpdate)
{ {

Просмотреть файл

@ -177,6 +177,13 @@ public:
nsIDOMDocument *aDocument); nsIDOMDocument *aDocument);
nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate); nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate);
/**
* Returns the singleton nsOfflineCacheUpdateService without an addref, or
* nsnull if the service couldn't be created.
*/
static nsOfflineCacheUpdateService *EnsureService();
/** Addrefs and returns the singleton nsOfflineCacheUpdateService. */
static nsOfflineCacheUpdateService *GetInstance(); static nsOfflineCacheUpdateService *GetInstance();
private: private: