Bug 635552 - Avoid leaking nsAlertsIconObserver objects by using a weak reference. r=karlt

This commit is contained in:
Josh Matthews 2011-02-21 01:50:57 -05:00
Родитель 5aaa1dc7d8
Коммит d6e1aafc64
2 изменённых файлов: 10 добавлений и 18 удалений

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

@ -75,32 +75,19 @@ static void notify_closed_marshal(GClosure* closure,
NS_RELEASE(alert);
}
NS_IMPL_ISUPPORTS3(nsAlertsIconListener, imgIContainerObserver, imgIDecoderObserver, nsIObserver)
NS_IMPL_ISUPPORTS4(nsAlertsIconListener, imgIContainerObserver,
imgIDecoderObserver, nsIObserver, nsISupportsWeakReference)
nsAlertsIconListener::nsAlertsIconListener()
: mLoadedFrame(PR_FALSE),
mHasQuit(PR_FALSE),
mNotification(NULL)
{
MOZ_COUNT_CTOR(nsAlertsIconListener);
nsCOMPtr<nsIObserverService> obsServ =
do_GetService("@mozilla.org/observer-service;1");
obsServ->AddObserver(this, "quit-application", PR_FALSE);
}
nsAlertsIconListener::~nsAlertsIconListener()
{
MOZ_COUNT_DTOR(nsAlertsIconListener);
if (mIconRequest)
mIconRequest->CancelAndForgetObserver(NS_BINDING_ABORTED);
if (!mHasQuit) {
nsCOMPtr<nsIObserverService> obsServ =
do_GetService("@mozilla.org/observer-service;1");
obsServ->RemoveObserver(this, "quit-application");
}
}
NS_IMETHODIMP
@ -307,7 +294,6 @@ nsAlertsIconListener::Observe(nsISupports *aSubject, const char *aTopic,
g_signal_handler_disconnect(mNotification, mClosureHandler);
g_object_unref(mNotification);
mNotification = NULL;
mHasQuit = PR_TRUE;
Release(); // equivalent to NS_RELEASE(this)
}
return NS_OK;
@ -364,6 +350,11 @@ nsAlertsIconListener::InitAlertAsync(const nsAString & aImageUrl,
if (!gHasActions && aAlertTextClickable)
return NS_ERROR_FAILURE; // No good, fallback to XUL
nsCOMPtr<nsIObserverService> obsServ =
do_GetService("@mozilla.org/observer-service;1");
if (obsServ)
obsServ->AddObserver(this, "quit-application", PR_TRUE);
// Workaround for a libnotify bug - blank titles aren't dealt with
// properly so we use a space
if (aAlertTitle.IsEmpty()) {

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

@ -42,6 +42,7 @@
#include "imgIDecoderObserver.h"
#include "nsStringAPI.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libnotify/notify.h>
@ -49,7 +50,8 @@
class imgIRequest;
class nsAlertsIconListener : public imgIDecoderObserver,
public nsIObserver
public nsIObserver,
public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
@ -80,7 +82,6 @@ protected:
PRPackedBool mLoadedFrame;
PRPackedBool mAlertHasAction;
PRPackedBool mHasQuit;
NotifyNotification* mNotification;
gulong mClosureHandler;