Bug 913138 - Release nsLayoutStatics when the layout module is unloaded. r=bsmedberg
authorBobby Holley <bobbyholley@gmail.com>
Wed, 09 Apr 2014 09:20:15 -0700
changeset 183681 64fcbdc63ed7
parent 183671 30c45853f8cb
child 183682 6899f7b4f57c
push id3446
push usernalexander@mozilla.com
push date2014-04-09 16:21 +0000
treeherdermozilla-beta@47c8852fde22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs913138
milestone29.0
Bug 913138 - Release nsLayoutStatics when the layout module is unloaded. r=bsmedberg
layout/build/nsLayoutModule.cpp
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -347,45 +347,16 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR
 #endif
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMediaManagerService,
                                          MediaManager::GetInstance)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITelephonyProvider,
                                          TelephonyFactory::CreateTelephonyProvider)
 
 //-----------------------------------------------------------------------------
 
-// Per bug 209804, it is necessary to observe the "xpcom-shutdown" event and
-// perform shutdown of the layout modules at that time instead of waiting for
-// our module destructor to run.  If we do not do this, then we risk holding
-// references to objects in other component libraries that have already been
-// shutdown (and possibly unloaded if 60709 is ever fixed).
-
-class LayoutShutdownObserver MOZ_FINAL : public nsIObserver
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIOBSERVER
-};
-
-NS_IMPL_ISUPPORTS1(LayoutShutdownObserver, nsIObserver)
-
-NS_IMETHODIMP
-LayoutShutdownObserver::Observe(nsISupports *aSubject,
-                                const char *aTopic,
-                                const char16_t *someData)
-{
-  if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
-    Shutdown();
-    nsContentUtils::XPCOMShutdown();
-  }
-  return NS_OK;
-}
-
-//-----------------------------------------------------------------------------
-
 static bool gInitialized = false;
 
 // Perform our one-time intialization for this module
 
 // static
 nsresult
 Initialize()
 {
@@ -406,34 +377,16 @@ Initialize()
     return rv;
 
   rv = nsLayoutStatics::Initialize();
   if (NS_FAILED(rv)) {
     Shutdown();
     return rv;
   }
 
-  // Add our shutdown observer.
-  nsCOMPtr<nsIObserverService> observerService =
-    mozilla::services::GetObserverService();
-
-  if (observerService) {
-    LayoutShutdownObserver* observer = new LayoutShutdownObserver();
-
-    if (!observer) {
-      Shutdown();
-
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-
-    observerService->AddObserver(observer, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
-  } else {
-    NS_WARNING("Could not get an observer service.  We will leak on shutdown.");
-  }
-
 #ifdef DEBUG
   nsStyleContext::AssertStyleStructMaxDifferenceValid();
 #endif
 
   return NS_OK;
 }
 
 // Shutdown this module, releasing all of the module resources
@@ -1292,16 +1245,18 @@ static const mozilla::Module::CategoryEn
   { "profile-after-change", "Bluetooth Service", BLUETOOTHSERVICE_CONTRACTID },
 #endif
   { nullptr }
 };
 
 static void
 LayoutModuleDtor()
 {
+  Shutdown();
+  nsContentUtils::XPCOMShutdown();
   nsScriptSecurityManager::Shutdown();
   xpcModuleDtor();
 }
 
 static const mozilla::Module kLayoutModule = {
   mozilla::Module::kVersion,
   kLayoutCIDs,
   kLayoutContracts,