From 6aac93c689af41f02db7e17e461f07f9f46faddb Mon Sep 17 00:00:00 2001 From: Panagiotis Koutsourakis Date: Fri, 10 Feb 2012 16:06:37 +0100 Subject: [PATCH] Bug 716661 - Convert observers in nsDownloadManager to weak observers. r=mak Make nsDownloadManager inherit from nsSupportsWeakReference, expose the new interface, and change the last argument of the addObserver calls to true to signify that we are adding a weak observer. --- .../downloads/nsDownloadManager.cpp | 29 +++++++++---------- .../components/downloads/nsDownloadManager.h | 4 ++- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/toolkit/components/downloads/nsDownloadManager.cpp b/toolkit/components/downloads/nsDownloadManager.cpp index 17c9dcb3999..cb1f1f6099f 100644 --- a/toolkit/components/downloads/nsDownloadManager.cpp +++ b/toolkit/components/downloads/nsDownloadManager.cpp @@ -111,11 +111,12 @@ static const PRInt64 gUpdateInterval = 400 * PR_USEC_PER_MSEC; //////////////////////////////////////////////////////////////////////////////// //// nsDownloadManager -NS_IMPL_ISUPPORTS3( +NS_IMPL_ISUPPORTS4( nsDownloadManager , nsIDownloadManager , nsINavHistoryObserver , nsIObserver +, nsISupportsWeakReference ) nsDownloadManager *nsDownloadManager::gDownloadManagerService = nsnull; @@ -886,23 +887,19 @@ nsDownloadManager::Init() // completely initialized), but the observerservice would still keep a reference // to us and notify us about shutdown, which may cause crashes. // failure to add an observer is not critical - // - // These observers will be cleaned up automatically at app shutdown. We do - // not bother explicitly breaking the observers because we are a singleton - // that lives for the duration of the app. - (void)mObserverService->AddObserver(this, "quit-application", false); - (void)mObserverService->AddObserver(this, "quit-application-requested", false); - (void)mObserverService->AddObserver(this, "offline-requested", false); - (void)mObserverService->AddObserver(this, "sleep_notification", false); - (void)mObserverService->AddObserver(this, "wake_notification", false); - (void)mObserverService->AddObserver(this, "profile-before-change", false); - (void)mObserverService->AddObserver(this, NS_IOSERVICE_GOING_OFFLINE_TOPIC, false); - (void)mObserverService->AddObserver(this, NS_IOSERVICE_OFFLINE_STATUS_TOPIC, false); - (void)mObserverService->AddObserver(this, NS_PRIVATE_BROWSING_REQUEST_TOPIC, false); - (void)mObserverService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, false); + (void)mObserverService->AddObserver(this, "quit-application", true); + (void)mObserverService->AddObserver(this, "quit-application-requested", true); + (void)mObserverService->AddObserver(this, "offline-requested", true); + (void)mObserverService->AddObserver(this, "sleep_notification", true); + (void)mObserverService->AddObserver(this, "wake_notification", true); + (void)mObserverService->AddObserver(this, "profile-before-change", true); + (void)mObserverService->AddObserver(this, NS_IOSERVICE_GOING_OFFLINE_TOPIC, true); + (void)mObserverService->AddObserver(this, NS_IOSERVICE_OFFLINE_STATUS_TOPIC, true); + (void)mObserverService->AddObserver(this, NS_PRIVATE_BROWSING_REQUEST_TOPIC, true); + (void)mObserverService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, true); if (history) - (void)history->AddObserver(this, false); + (void)history->AddObserver(this, true); return NS_OK; } diff --git a/toolkit/components/downloads/nsDownloadManager.h b/toolkit/components/downloads/nsDownloadManager.h index 54312e40049..2750db9fd34 100644 --- a/toolkit/components/downloads/nsDownloadManager.h +++ b/toolkit/components/downloads/nsDownloadManager.h @@ -58,6 +58,7 @@ #include "nsIObserverService.h" #include "nsIStringBundle.h" #include "nsISupportsPrimitives.h" +#include "nsWeakReference.h" #include "nsITimer.h" #include "nsString.h" @@ -76,7 +77,8 @@ class nsDownload; class nsDownloadManager : public nsIDownloadManager, public nsINavHistoryObserver, - public nsIObserver + public nsIObserver, + public nsSupportsWeakReference { public: NS_DECL_ISUPPORTS