Bug 710112 - cleanup xpcom/io for windows (reduce LoadLibrary/PR_LoadLibrary). r=jimm
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 16 Jan 2012 10:54:20 +0900
changeset 84571 3f378d354444754f1e072d55426155e56e8df80c
parent 84570 f64609a2123591ff07d78ad5fab542293e9acce0
child 84572 bccc0adeebd7263a0a6bc7293af57de9861fbf4d
push id21865
push userCallek@gmail.com
push dateTue, 17 Jan 2012 03:28:17 +0000
treeherdermozilla-central@34572943a3e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs710112
milestone12.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 710112 - cleanup xpcom/io for windows (reduce LoadLibrary/PR_LoadLibrary). r=jimm
xpcom/build/nsXPComInit.cpp
xpcom/io/SpecialSystemDirectory.cpp
xpcom/io/SpecialSystemDirectory.h
xpcom/io/nsLocalFileWin.cpp
xpcom/io/nsLocalFileWin.h
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -712,18 +712,16 @@ ShutdownXPCOM(nsIServiceManager* servMgr
     if (nsComponentManagerImpl::gComponentManager) {
       nsrefcnt cnt;
       NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
       NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
     }
     nsComponentManagerImpl::gComponentManager = nsnull;
     nsCategoryManager::Destroy();
 
-    ShutdownSpecialSystemDirectory();
-
     NS_PurgeAtomTable();
 
     NS_IF_RELEASE(gDebug);
 
     if (sIOThread) {
         delete sIOThread;
         sIOThread = nsnull;
     }
--- a/xpcom/io/SpecialSystemDirectory.cpp
+++ b/xpcom/io/SpecialSystemDirectory.cpp
@@ -96,42 +96,28 @@
 
 #ifdef XP_WIN
 typedef HRESULT (WINAPI* nsGetKnownFolderPath)(GUID& rfid,
                                                DWORD dwFlags,
                                                HANDLE hToken,
                                                PWSTR *ppszPath);
 
 static nsGetKnownFolderPath gGetKnownFolderPath = NULL;
-
-static HINSTANCE gShell32DLLInst = NULL;
 #endif
 
 void StartupSpecialSystemDirectory()
 {
 #if defined (XP_WIN)
     // SHGetKnownFolderPath is only available on Windows Vista
     // so that we need to use GetProcAddress to get the pointer.
-    gShell32DLLInst = LoadLibraryW(L"shell32.dll");
-    if(gShell32DLLInst)
+    HMODULE hShell32DLLInst = GetModuleHandleW(L"shell32.dll");
+    if(hShell32DLLInst)
     {
         gGetKnownFolderPath = (nsGetKnownFolderPath)
-            GetProcAddress(gShell32DLLInst, "SHGetKnownFolderPath");
-    }
-#endif
-}
-
-void ShutdownSpecialSystemDirectory()
-{
-#if defined (XP_WIN)
-    if (gShell32DLLInst)
-    {
-        FreeLibrary(gShell32DLLInst);
-        gShell32DLLInst = NULL;
-        gGetKnownFolderPath = NULL;
+            GetProcAddress(hShell32DLLInst, "SHGetKnownFolderPath");
     }
 #endif
 }
 
 #if defined (XP_WIN)
 
 static nsresult GetKnownFolder(GUID* guid, nsILocalFile** aFile)
 {
--- a/xpcom/io/SpecialSystemDirectory.h
+++ b/xpcom/io/SpecialSystemDirectory.h
@@ -46,17 +46,16 @@
 
 #ifdef MOZ_WIDGET_COCOA
 #include <Carbon/Carbon.h>
 #include "nsILocalFileMac.h"
 #include "prenv.h"
 #endif
 
 extern void StartupSpecialSystemDirectory();
-extern void ShutdownSpecialSystemDirectory();
 
 
 enum SystemDirectories {
   OS_DriveDirectory         =   1,   
   OS_TemporaryDirectory     =   2,   
   OS_CurrentProcessDirectory=   3,   
   OS_CurrentWorkingDirectory=   4,
   XPCOM_CurrentProcessComponentDirectory=   5,   
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -103,17 +103,16 @@ unsigned char *_mbsstr( const unsigned c
 #endif
 
 #ifndef FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000
 #endif
 
 ILCreateFromPathWPtr nsLocalFile::sILCreateFromPathW = NULL;
 SHOpenFolderAndSelectItemsPtr nsLocalFile::sSHOpenFolderAndSelectItems = NULL;
-PRLibrary *nsLocalFile::sLibShell = NULL;
 
 class nsDriveEnumerator : public nsISimpleEnumerator
 {
 public:
     nsDriveEnumerator();
     virtual ~nsDriveEnumerator();
     NS_DECL_ISUPPORTS
     NS_DECL_NSISIMPLEENUMERATOR
@@ -2768,17 +2767,17 @@ nsLocalFile::RevealClassic()
   return NS_OK;
 }
 
 nsresult 
 nsLocalFile::RevealUsingShell()
 {
   // All of these shell32.dll related pointers should be non NULL 
   // on XP and later.
-  if (!sLibShell || !sILCreateFromPathW || !sSHOpenFolderAndSelectItems) {
+  if (!sILCreateFromPathW || !sSHOpenFolderAndSelectItems) {
     return NS_ERROR_FAILURE;
   }
 
   bool isDirectory;
   nsresult rv = IsDirectory(&isDirectory);
   NS_ENSURE_SUCCESS(rv, rv);
 
   HRESULT hr;
@@ -3129,36 +3128,33 @@ nsLocalFile::GetHashCode(PRUint32 *aResu
 void
 nsLocalFile::GlobalInit()
 {
     nsresult rv = NS_CreateShortcutResolver();
     NS_ASSERTION(NS_SUCCEEDED(rv), "Shortcut resolver could not be created");
 
     // shell32.dll should be loaded already, so we are not actually 
     // loading the library here.
-    sLibShell = PR_LoadLibrary("shell32.dll");
-    if (sLibShell) {
+    HMODULE hLibShell = GetModuleHandleW(L"shell32.dll");
+    if (hLibShell) {
       // ILCreateFromPathW is available in XP and up.
       sILCreateFromPathW = (ILCreateFromPathWPtr) 
-                           PR_FindFunctionSymbol(sLibShell, 
-                                                 "ILCreateFromPathW");
+                            GetProcAddress(hLibShell, 
+                                           "ILCreateFromPathW");
 
       // SHOpenFolderAndSelectItems is available in XP and up.
       sSHOpenFolderAndSelectItems = (SHOpenFolderAndSelectItemsPtr) 
-                                     PR_FindFunctionSymbol(sLibShell, 
-                                                           "SHOpenFolderAndSelectItems");
+                                     GetProcAddress(hLibShell, 
+                                                    "SHOpenFolderAndSelectItems");
     }
 }
 
 void
 nsLocalFile::GlobalShutdown()
 {
-    if (sLibShell) {
-      PR_UnloadLibrary(sLibShell);
-    }
     NS_DestroyShortcutResolver();
 }
 
 NS_IMPL_ISUPPORTS1(nsDriveEnumerator, nsISimpleEnumerator)
 
 nsDriveEnumerator::nsDriveEnumerator()
 {
 }
--- a/xpcom/io/nsLocalFileWin.h
+++ b/xpcom/io/nsLocalFileWin.h
@@ -128,12 +128,11 @@ private:
     nsresult HasFileAttribute(DWORD fileAttrib, bool *_retval);
     nsresult AppendInternal(const nsAFlatString &node,
                             bool multipleComponents);
     nsresult RevealClassic(); // Reveals the path using explorer.exe cmdline
     nsresult RevealUsingShell(); // Uses newer shell API to reveal the path
 
     static ILCreateFromPathWPtr sILCreateFromPathW;
     static SHOpenFolderAndSelectItemsPtr sSHOpenFolderAndSelectItems;
-    static PRLibrary *sLibShell;
 };
 
 #endif