Bug 1287623, part 2 - Use StaticRefPtr for nsDirectoryService::gService. r=froydnj
authorAndrew McCreight <continuation@gmail.com>
Thu, 21 Jul 2016 09:54:16 -0700
changeset 346214 cef4132ee60b6e498751c8fabcb153535b5c4cec
parent 346213 872848c3a71663e8fcd27182864eefce162346ab
child 346215 aafe24d898d25a20b838a459456d0a1d13e79f9d
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1287623
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1287623, part 2 - Use StaticRefPtr for nsDirectoryService::gService. r=froydnj
xpcom/build/XPCOMInit.cpp
xpcom/io/nsDirectoryService.cpp
xpcom/io/nsDirectoryService.h
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -930,17 +930,17 @@ ShutdownXPCOM(nsIServiceManager* aServMg
   NS_IF_RELEASE(aServMgr);
 
   // Shutdown global servicemanager
   if (nsComponentManagerImpl::gComponentManager) {
     nsComponentManagerImpl::gComponentManager->FreeServices();
   }
 
   // Release the directory service
-  NS_IF_RELEASE(nsDirectoryService::gService);
+  nsDirectoryService::gService = nullptr;
 
   free(gGREBinPath);
   gGREBinPath = nullptr;
 
   if (moduleLoaders) {
     bool more;
     nsCOMPtr<nsISupports> el;
     while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) && more) {
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -187,17 +187,17 @@ nsDirectoryService::GetCurrentProcessDir
   }
 
 #endif
 
   NS_ERROR("unable to get current process directory");
   return NS_ERROR_FAILURE;
 } // GetCurrentProcessDirectory()
 
-nsDirectoryService* nsDirectoryService::gService = nullptr;
+StaticRefPtr<nsDirectoryService> nsDirectoryService::gService;
 
 nsDirectoryService::nsDirectoryService()
   : mHashtable(128)
 {
 }
 
 nsresult
 nsDirectoryService::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
@@ -238,25 +238,23 @@ nsDirectoryService::Init()
 }
 
 void
 nsDirectoryService::RealInit()
 {
   NS_ASSERTION(!gService,
                "nsDirectoryService::RealInit Mustn't initialize twice!");
 
-  RefPtr<nsDirectoryService> self = new nsDirectoryService();
+  gService = new nsDirectoryService();
 
   NS_RegisterStaticAtoms(directory_atoms);
 
   // Let the list hold the only reference to the provider.
   nsAppFileLocationProvider* defaultProvider = new nsAppFileLocationProvider;
-  self->mProviders.AppendElement(defaultProvider);
-
-  self.swap(gService);
+  gService->mProviders.AppendElement(defaultProvider);
 }
 
 nsDirectoryService::~nsDirectoryService()
 {
 }
 
 NS_IMPL_ISUPPORTS(nsDirectoryService,
                   nsIProperties,
--- a/xpcom/io/nsDirectoryService.h
+++ b/xpcom/io/nsDirectoryService.h
@@ -8,16 +8,17 @@
 #define nsDirectoryService_h___
 
 #include "nsIDirectoryService.h"
 #include "nsInterfaceHashtable.h"
 #include "nsIFile.h"
 #include "nsIAtom.h"
 #include "nsTArray.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/StaticPtr.h"
 
 #define NS_XPCOM_INIT_CURRENT_PROCESS_DIR       "MozBinD"   // Can be used to set NS_XPCOM_CURRENT_PROCESS_DIR
                                                             // CANNOT be used to GET a location
 #define NS_DIRECTORY_SERVICE_CID  {0xf00152d0,0xb40b,0x11d3,{0x8c, 0x9c, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
 
 class nsDirectoryService final
   : public nsIDirectoryService
   , public nsIProperties
@@ -37,17 +38,17 @@ public:
   nsDirectoryService();
 
   static void RealInit();
   void RegisterCategoryProviders();
 
   static nsresult
   Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
-  static nsDirectoryService* gService;
+  static mozilla::StaticRefPtr<nsDirectoryService> gService;
 
 private:
   ~nsDirectoryService();
 
   nsresult GetCurrentProcessDirectory(nsIFile** aFile);
 
   nsInterfaceHashtable<nsCStringHashKey, nsIFile> mHashtable;
   nsTArray<nsCOMPtr<nsIDirectoryServiceProvider>> mProviders;