Bug 697988 - Use weak references to observers in nsDOMStorage.cpp. r=honzab.moz.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Wed, 30 Nov 2011 19:08:54 -0500
changeset 81848 414534199a74fed43d66adba67806fd04a6ee415
parent 81847 ab37c20227f8b146fd6a4c986a32ec98a143210e
child 81849 b03e24707280134abd5ba965e37c8c64d0cbdbdb
push idunknown
push userunknown
push dateunknown
reviewershonzab.moz
bugs697988
milestone11.0a1
Bug 697988 - Use weak references to observers in nsDOMStorage.cpp. r=honzab.moz.
dom/src/storage/nsDOMStorage.cpp
dom/src/storage/nsDOMStorage.h
--- a/dom/src/storage/nsDOMStorage.cpp
+++ b/dom/src/storage/nsDOMStorage.cpp
@@ -254,19 +254,20 @@ nsSessionStorageEntry::~nsSessionStorage
 
 nsDOMStorageManager* nsDOMStorageManager::gStorageManager;
 
 nsDOMStorageManager::nsDOMStorageManager()
   : mInPrivateBrowsing(false)
 {
 }
 
-NS_IMPL_ISUPPORTS2(nsDOMStorageManager,
+NS_IMPL_ISUPPORTS3(nsDOMStorageManager,
                    nsIDOMStorageManager,
-                   nsIObserver)
+                   nsIObserver,
+                   nsISupportsWeakReference)
 
 //static
 nsresult
 nsDOMStorageManager::Initialize()
 {
   gStorageManager = new nsDOMStorageManager();
   if (!gStorageManager)
     return NS_ERROR_OUT_OF_MEMORY;
@@ -283,35 +284,34 @@ nsDOMStorageManager::Initialize()
   if (XRE_GetProcessType() != GeckoProcessType_Default)
     return NS_OK;
 
   nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (!os)
     return NS_OK;
 
   nsresult rv;
-  rv = os->AddObserver(gStorageManager, "cookie-changed", false);
+  rv = os->AddObserver(gStorageManager, "cookie-changed", true);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = os->AddObserver(gStorageManager, "offline-app-removed", false);
+  rv = os->AddObserver(gStorageManager, "offline-app-removed", true);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = os->AddObserver(gStorageManager, NS_PRIVATE_BROWSING_SWITCH_TOPIC, true);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = os->AddObserver(gStorageManager, NS_PRIVATE_BROWSING_SWITCH_TOPIC,
-                       false);
+  rv = os->AddObserver(gStorageManager, "profile-after-change", true);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = os->AddObserver(gStorageManager, "profile-after-change", false);
+  rv = os->AddObserver(gStorageManager, "perm-changed", true);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = os->AddObserver(gStorageManager, "perm-changed", false);
-  NS_ENSURE_SUCCESS(rv, rv);
-  rv = os->AddObserver(gStorageManager, "browser:purge-domain-data", false);
+  rv = os->AddObserver(gStorageManager, "browser:purge-domain-data", true);
   NS_ENSURE_SUCCESS(rv, rv);
   // Used for temporary table flushing
-  rv = os->AddObserver(gStorageManager, "profile-before-change", false);
+  rv = os->AddObserver(gStorageManager, "profile-before-change", true);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = os->AddObserver(gStorageManager, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
+  rv = os->AddObserver(gStorageManager, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = os->AddObserver(gStorageManager, NS_DOMSTORAGE_FLUSH_TIMER_TOPIC, false);
+  rv = os->AddObserver(gStorageManager, NS_DOMSTORAGE_FLUSH_TIMER_TOPIC, true);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 //static
 nsDOMStorageManager*
 nsDOMStorageManager::GetInstance()
--- a/dom/src/storage/nsDOMStorage.h
+++ b/dom/src/storage/nsDOMStorage.h
@@ -100,16 +100,17 @@ public:
   nsSessionStorageEntry(const nsSessionStorageEntry& aToCopy);
   ~nsSessionStorageEntry();
 
   nsRefPtr<nsDOMStorageItem> mItem;
 };
 
 class nsDOMStorageManager : public nsIDOMStorageManager
                           , public nsIObserver
+                          , public nsSupportsWeakReference
 {
 public:
   // nsISupports
   NS_DECL_ISUPPORTS
 
   // nsIDOMStorageManager
   NS_DECL_NSIDOMSTORAGEMANAGER