Bug 1403366 - Don't use nsDirectoryService::Create in nsDirectoryService::GetCurrentProcessDirectory. r=froydnj
☠☠ backed out by 8a7e10cf8824 ☠ ☠
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 28 Sep 2017 08:46:43 +0900
changeset 384308 bc7ca663b817224db4f6afd5ee6eb1a5610bfcee
parent 384307 9c05226e2248004f91a7487016612d32b39184d7
child 384309 78f4fbeaac2004bb382c12081673ed363b3ad07c
push id52581
push usermh@glandium.org
push dateTue, 03 Oct 2017 22:05:39 +0000
treeherderautoland@aa58d5c8fe1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1403366
milestone58.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 1403366 - Don't use nsDirectoryService::Create in nsDirectoryService::GetCurrentProcessDirectory. r=froydnj Back in the day, there was no global with an already initialized DirectoryService. But now there is, and, in fact, GetCurrentProcessDirectory already errors out if that global is not set by the time it's called. All calling nsDirectoryService::Create achieves is doing the check again and calling QueryInterface, which we don't need to do anyways.
xpcom/io/nsDirectoryService.cpp
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -60,34 +60,22 @@ nsDirectoryService::GetCurrentProcessDir
   }
   *aFile = nullptr;
 
   //  Set the component registry location:
   if (!gService) {
     return NS_ERROR_FAILURE;
   }
 
-  nsresult rv;
-
-  nsCOMPtr<nsIProperties> dirService;
-  rv = nsDirectoryService::Create(nullptr,
-                                  NS_GET_IID(nsIProperties),
-                                  getter_AddRefs(dirService));  // needs to be around for life of product
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  if (dirService) {
-    nsCOMPtr<nsIFile> localFile;
-    dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
-                    getter_AddRefs(localFile));
-    if (localFile) {
-      localFile.forget(aFile);
-      return NS_OK;
-    }
+  nsCOMPtr<nsIFile> file;
+  gService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
+                getter_AddRefs(file));
+  if (file) {
+    file.forget(aFile);
+    return NS_OK;
   }
 
   RefPtr<nsLocalFile> localFile = new nsLocalFile;
 
 #ifdef XP_WIN
   wchar_t buf[MAX_PATH + 1];
   SetLastError(ERROR_SUCCESS);
   if (GetModuleFileNameW(0, buf, mozilla::ArrayLength(buf)) &&
@@ -116,17 +104,17 @@ nsDirectoryService::GetCurrentProcessDir
         // This will resolve the relative portion of the CFURL against it base, giving a full
         // path, which CFURLCopyFileSystemPath doesn't do.
         char buffer[PATH_MAX];
         if (CFURLGetFileSystemRepresentation(parentURL, true,
                                              (UInt8*)buffer, sizeof(buffer))) {
 #ifdef DEBUG_conrad
           printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer);
 #endif
-          rv = localFile->InitWithNativePath(nsDependentCString(buffer));
+          nsresult rv = localFile->InitWithNativePath(nsDependentCString(buffer));
           if (NS_SUCCEEDED(rv)) {
             localFile.forget(aFile);
           }
         }
         CFRelease(parentURL);
       }
       CFRelease(bundleURL);
     }