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.
This commit is contained in:
Panagiotis Koutsourakis 2012-02-10 16:06:37 +01:00
Родитель fe20bb7e39
Коммит 3ab0927d1b
2 изменённых файлов: 16 добавлений и 17 удалений

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

@ -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;
}

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

@ -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