mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
add caching of jar/zip files to help fix bug 46707. Also factor out conditional compilation of ziploader support to not just be dependent on XPCOM_STANDALONE. And, factor out manifest directory from component directory (even though they are the same for now) in prepatation for a better fix to bug 39808. r=rginda@netscape.com
This commit is contained in:
parent
68f3129d97
commit
45fd8ce1e8
@ -72,7 +72,6 @@ xptiInterfaceInfoManager::FreeInterfaceInfoManager()
|
||||
NS_IF_RELEASE(gInterfaceInfoManager);
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
xptiInterfaceInfoManager::IsValid()
|
||||
{
|
||||
@ -127,14 +126,18 @@ xptiInterfaceInfoManager::~xptiInterfaceInfoManager()
|
||||
// We only do this on shutdown of the service.
|
||||
mWorkingSet.InvalidateInterfaceInfos();
|
||||
|
||||
#ifdef XPTI_HAS_ZIP_SUPPORT
|
||||
xptiZipLoader::Shutdown();
|
||||
#endif /* XPTI_HAS_ZIP_SUPPORT */
|
||||
|
||||
if(mResolveLock)
|
||||
PR_DestroyLock(mResolveLock);
|
||||
if(mAutoRegLock)
|
||||
PR_DestroyLock(mAutoRegLock);
|
||||
}
|
||||
|
||||
PRBool
|
||||
xptiInterfaceInfoManager::GetComponentsDir(nsILocalFile** aDir)
|
||||
static PRBool
|
||||
GetDirectoryFromDirService(const char* codename, nsILocalFile** aDir)
|
||||
{
|
||||
NS_ASSERTION(aDir,"loser!");
|
||||
|
||||
@ -146,8 +149,7 @@ xptiInterfaceInfoManager::GetComponentsDir(nsILocalFile** aDir)
|
||||
if(dirService)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> dir;
|
||||
dirService->Get(NS_XPCOM_COMPONENT_DIR,
|
||||
NS_GET_IID(nsIFile), getter_AddRefs(dir));
|
||||
dirService->Get(codename, NS_GET_IID(nsIFile), getter_AddRefs(dir));
|
||||
if(dir)
|
||||
{
|
||||
NS_ADDREF(*aDir = dir);
|
||||
@ -157,6 +159,20 @@ xptiInterfaceInfoManager::GetComponentsDir(nsILocalFile** aDir)
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
xptiInterfaceInfoManager::GetComponentsDir(nsILocalFile** aDir)
|
||||
{
|
||||
return GetDirectoryFromDirService(NS_XPCOM_COMPONENT_DIR, aDir);
|
||||
}
|
||||
|
||||
PRBool
|
||||
xptiInterfaceInfoManager::GetManifestDir(nsILocalFile** aDir)
|
||||
{
|
||||
// XXX This does not look like the right place yet.
|
||||
// return GetDirectoryFromDirService(NS_XPCOM_APPLICATION_REGISTRY_DIR, aDir);
|
||||
return GetDirectoryFromDirService(NS_XPCOM_COMPONENT_DIR, aDir);
|
||||
}
|
||||
|
||||
PRBool
|
||||
xptiInterfaceInfoManager::BuildFileList(nsISupportsArray** aFileList)
|
||||
{
|
||||
@ -308,9 +324,13 @@ xptiInterfaceInfoManager::LoadFile(const xptiTypelib& aTypelibRecord,
|
||||
|
||||
if(aTypelibRecord.IsZip())
|
||||
{
|
||||
#ifdef XPTI_HAS_ZIP_SUPPORT
|
||||
zipItem = &aWorkingSet->GetZipItemAt(aTypelibRecord.GetZipItemIndex());
|
||||
LOG_LOAD(("# loading zip item %s::%s\n", fileRecord->GetName(), zipItem->GetName()));
|
||||
header = xptiZipLoader::ReadXPTFileFromZip(file, zipItem->GetName(), aWorkingSet);
|
||||
#else
|
||||
header = nsnull;
|
||||
#endif /* XPTI_HAS_ZIP_SUPPORT */
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -734,6 +754,7 @@ xptiInterfaceInfoManager::AddOnlyNewFileFromFileList(nsISupportsArray* aFileList
|
||||
// This will correspond to typelibRecord above.
|
||||
aWorkingSet->AppendFile(fileRecord);
|
||||
}
|
||||
#ifdef XPTI_HAS_ZIP_SUPPORT
|
||||
else // It is a zip file, Oh boy!
|
||||
{
|
||||
if(!xptiZipLoader::EnumerateZipEntries(file,
|
||||
@ -746,6 +767,7 @@ xptiInterfaceInfoManager::AddOnlyNewFileFromFileList(nsISupportsArray* aFileList
|
||||
// xptiInterfaceInfoManager::FoundEntry.
|
||||
aWorkingSet->AppendFile(fileRecord);
|
||||
}
|
||||
#endif /* XPTI_HAS_ZIP_SUPPORT */
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
@ -859,6 +881,7 @@ xptiInterfaceInfoManager::DoFullValidationMergeFromFileList(nsISupportsArray* aF
|
||||
// This will correspond to typelibRecord above.
|
||||
aWorkingSet->AppendFile(fileRecord);
|
||||
}
|
||||
#ifdef XPTI_HAS_ZIP_SUPPORT
|
||||
else // It is a zip file, Oh boy!
|
||||
{
|
||||
if(!xptiZipLoader::EnumerateZipEntries(file,
|
||||
@ -871,6 +894,7 @@ xptiInterfaceInfoManager::DoFullValidationMergeFromFileList(nsISupportsArray* aF
|
||||
// xptiInterfaceInfoManager::FoundEntry.
|
||||
aWorkingSet->AppendFile(fileRecord);
|
||||
}
|
||||
#endif /* XPTI_HAS_ZIP_SUPPORT */
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ PRBool xptiManifest::Write(xptiInterfaceInfoManager* aMgr,
|
||||
PRIntn interfaceCount = 0;
|
||||
|
||||
nsCOMPtr<nsILocalFile> tempFile;
|
||||
if(!aMgr->GetComponentsDir(getter_AddRefs(tempFile)) || !tempFile)
|
||||
if(!aMgr->GetManifestDir(getter_AddRefs(tempFile)) || !tempFile)
|
||||
return PR_FALSE;
|
||||
|
||||
if(NS_FAILED(tempFile->Append(g_TempManifestFilename)))
|
||||
@ -176,7 +176,7 @@ out:
|
||||
{
|
||||
// delete the old file and rename this
|
||||
nsCOMPtr<nsILocalFile> mainFile;
|
||||
if(!aMgr->GetComponentsDir(getter_AddRefs(mainFile)) || !mainFile)
|
||||
if(!aMgr->GetManifestDir(getter_AddRefs(mainFile)) || !mainFile)
|
||||
return PR_FALSE;
|
||||
|
||||
if(NS_FAILED(mainFile->Append(g_MainManifestFilename)))
|
||||
@ -192,13 +192,18 @@ out:
|
||||
// XXX Would prefer MoveTo with a 'null' newdir, the but nsILocalFile
|
||||
// implementation are broken.
|
||||
// http://bugzilla.mozilla.org/show_bug.cgi?id=33098
|
||||
|
||||
#if 1
|
||||
nsCOMPtr<nsILocalFile> dir;
|
||||
if(!aMgr->GetComponentsDir(getter_AddRefs(dir)) || !dir)
|
||||
if(!aMgr->GetManifestDir(getter_AddRefs(dir)) || !dir)
|
||||
return PR_FALSE;
|
||||
|
||||
if(NS_FAILED(tempFile->CopyTo(dir, g_MainManifestFilename)))
|
||||
return PR_FALSE;
|
||||
#else
|
||||
// so let's try the MoveTo!
|
||||
if(NS_FAILED(tempFile->MoveTo(nsnull, g_MainManifestFilename)))
|
||||
return PR_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
return succeeded;
|
||||
@ -215,12 +220,25 @@ ReadManifestIntoMemory(xptiInterfaceInfoManager* aMgr,
|
||||
char* whole = nsnull;
|
||||
|
||||
nsCOMPtr<nsILocalFile> aFile;
|
||||
if(!aMgr->GetComponentsDir(getter_AddRefs(aFile)) || !aFile)
|
||||
if(!aMgr->GetManifestDir(getter_AddRefs(aFile)) || !aFile)
|
||||
return nsnull;
|
||||
|
||||
if(NS_FAILED(aFile->Append(g_MainManifestFilename)))
|
||||
return nsnull;
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
static PRBool shown = PR_FALSE;
|
||||
char* path;
|
||||
if(!shown && NS_SUCCEEDED(aFile->GetPath(&path)) && path)
|
||||
{
|
||||
printf("Type Manifest File: %s\n", path);
|
||||
nsMemory::Free(path);
|
||||
shown = PR_TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(NS_FAILED(aFile->GetFileSize(&fileSize)) || !(flen = nsInt64(fileSize)))
|
||||
return nsnull;
|
||||
|
||||
|
@ -24,7 +24,41 @@
|
||||
|
||||
#include "xptiprivate.h"
|
||||
|
||||
static const char g_ZipReaderProgID[] = "component://netscape/libjar/zip-reader";
|
||||
#ifdef XPTI_HAS_ZIP_SUPPORT
|
||||
|
||||
static const char gCacheProgID[] = "component://netscape/libjar/zip-reader-cache";
|
||||
|
||||
static const PRUint32 gCacheSize = 1;
|
||||
|
||||
nsCOMPtr<nsIZipReaderCache> xptiZipLoader::gCache = nsnull;
|
||||
|
||||
// static
|
||||
nsIZipReader*
|
||||
xptiZipLoader::GetZipReader(nsILocalFile* file)
|
||||
{
|
||||
NS_ASSERTION(file, "bad file");
|
||||
|
||||
if(!gCache)
|
||||
{
|
||||
gCache = do_CreateInstance(gCacheProgID);
|
||||
if(!gCache || NS_FAILED(gCache->Init(gCacheSize)))
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsIZipReader* reader = nsnull;
|
||||
|
||||
if(NS_FAILED(gCache->GetZip(file, &reader)))
|
||||
return nsnull;
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
xptiZipLoader::Shutdown()
|
||||
{
|
||||
gCache = nsnull;
|
||||
}
|
||||
|
||||
// static
|
||||
PRBool
|
||||
@ -32,22 +66,14 @@ xptiZipLoader::EnumerateZipEntries(nsILocalFile* file,
|
||||
xptiEntrySink* sink,
|
||||
xptiWorkingSet* aWorkingSet)
|
||||
{
|
||||
#ifndef XPCOM_STANDALONE
|
||||
NS_ASSERTION(file, "loser!");
|
||||
NS_ASSERTION(sink, "loser!");
|
||||
NS_ASSERTION(aWorkingSet, "loser!");
|
||||
|
||||
nsCOMPtr<nsIZipReader> zip = do_CreateInstance(g_ZipReaderProgID);
|
||||
nsCOMPtr<nsIZipReader> zip = dont_AddRef(GetZipReader(file));
|
||||
if(!zip)
|
||||
return PR_FALSE;
|
||||
if(NS_FAILED(zip->Init(file)) || NS_FAILED(zip->Open()))
|
||||
return PR_FALSE;
|
||||
|
||||
// This is required before getting streams for some reason.
|
||||
// XXX and then someopne removed it from that interface!
|
||||
// if(NS_FAILED(zip->ParseManifest()))
|
||||
// return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> entries;
|
||||
if(NS_FAILED(zip->FindEntries("*.xpt", getter_AddRefs(entries))) ||
|
||||
!entries)
|
||||
@ -97,9 +123,6 @@ xptiZipLoader::EnumerateZipEntries(nsILocalFile* file,
|
||||
} while(1);
|
||||
|
||||
return PR_TRUE;
|
||||
#else
|
||||
return PR_FALSE;
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
}
|
||||
|
||||
// static
|
||||
@ -108,25 +131,9 @@ xptiZipLoader::ReadXPTFileFromZip(nsILocalFile* file,
|
||||
const char* entryName,
|
||||
xptiWorkingSet* aWorkingSet)
|
||||
{
|
||||
#ifndef XPCOM_STANDALONE
|
||||
nsCOMPtr<nsIZipReader> zip =
|
||||
do_CreateInstance(g_ZipReaderProgID);
|
||||
nsCOMPtr<nsIZipReader> zip = dont_AddRef(GetZipReader(file));
|
||||
if(!zip)
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
if(NS_FAILED(zip->Init(file)) || NS_FAILED(zip->Open()))
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
// This is required before getting streams for some reason.
|
||||
// XXX and then someopne removed it from that interface!
|
||||
//if(NS_FAILED(zip->ParseManifest()))
|
||||
//{
|
||||
// return nsnull;
|
||||
//}
|
||||
|
||||
nsCOMPtr<nsIZipEntry> entry;
|
||||
if(NS_FAILED(zip->GetEntry(entryName, getter_AddRefs(entry))) || !entry)
|
||||
@ -135,12 +142,8 @@ xptiZipLoader::ReadXPTFileFromZip(nsILocalFile* file,
|
||||
}
|
||||
|
||||
return ReadXPTFileFromOpenZip(zip, entry, entryName, aWorkingSet);
|
||||
#else
|
||||
return nsnull;
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
}
|
||||
|
||||
#ifndef XPCOM_STANDALONE
|
||||
// static
|
||||
XPTHeader*
|
||||
xptiZipLoader::ReadXPTFileFromOpenZip(nsIZipReader* zip,
|
||||
@ -228,8 +231,5 @@ xptiZipLoader::ReadXPTFileFromOpenZip(nsIZipReader* zip,
|
||||
delete [] whole;
|
||||
return header;
|
||||
}
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* XPTI_HAS_ZIP_SUPPORT */
|
||||
|
@ -25,6 +25,10 @@
|
||||
#ifndef xptiprivate_h___
|
||||
#define xptiprivate_h___
|
||||
|
||||
#ifndef XPCOM_STANDALONE
|
||||
#define XPTI_HAS_ZIP_SUPPORT 1
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
@ -50,9 +54,11 @@
|
||||
#include "nsInt64.h"
|
||||
|
||||
#include "nsQuickSort.h"
|
||||
#ifndef XPCOM_STANDALONE
|
||||
|
||||
#ifdef XPTI_HAS_ZIP_SUPPORT
|
||||
#include "nsIZipReader.h"
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
#endif /* XPTI_HAS_ZIP_SUPPORT */
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
|
||||
#include "nsAutoLock.h"
|
||||
@ -575,6 +581,8 @@ public:
|
||||
xptiWorkingSet* aWorkingSet) = 0;
|
||||
};
|
||||
|
||||
#ifdef XPTI_HAS_ZIP_SUPPORT
|
||||
|
||||
class xptiZipLoader
|
||||
{
|
||||
public:
|
||||
@ -590,16 +598,24 @@ public:
|
||||
const char* entryName,
|
||||
xptiWorkingSet* aWorkingSet);
|
||||
|
||||
static void
|
||||
Shutdown();
|
||||
|
||||
private:
|
||||
#ifndef XPCOM_STANDALONE
|
||||
static XPTHeader*
|
||||
ReadXPTFileFromOpenZip(nsIZipReader * zip,
|
||||
ReadXPTFileFromOpenZip(nsIZipReader* zip,
|
||||
nsIZipEntry* entry,
|
||||
const char* entryName,
|
||||
xptiWorkingSet* aWorkingSet);
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
|
||||
static nsIZipReader*
|
||||
GetZipReader(nsILocalFile* file);
|
||||
|
||||
static nsCOMPtr<nsIZipReaderCache> gCache;
|
||||
};
|
||||
|
||||
#endif /* XPTI_HAS_ZIP_SUPPORT */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
class xptiFileType
|
||||
@ -671,6 +687,7 @@ public:
|
||||
xptiWorkingSet* aWorkingSet = nsnull);
|
||||
|
||||
PRBool GetComponentsDir(nsILocalFile** aDir);
|
||||
PRBool GetManifestDir(nsILocalFile** aDir);
|
||||
|
||||
static PRLock* GetResolveLock(xptiInterfaceInfoManager* self = nsnull)
|
||||
{if(!self && !(self = GetInterfaceInfoManagerNoAddRef()))
|
||||
|
Loading…
Reference in New Issue
Block a user