Bug 1403366 - Don't use nsDirectoryService::Create in nsDirectoryService::GetCurrentProcessDirectory. r?froydnj draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 28 Sep 2017 08:46:43 +0900
changeset 674062 8645ba5f445fe393242e8d640655b211a8eaa845
parent 674061 08016ead783ded2b5877d406bfde9987da0962a8
child 674063 a2f9d45c2d3bccb64e5174e5858668e41e551614
push id82722
push userbmo:mh+mozilla@glandium.org
push dateTue, 03 Oct 2017 06:57:08 +0000
reviewersfroydnj
bugs1403366
milestone58.0a1
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);
     }