Fixes 48888 - xpcom flat file backend. r=dp@netscape.com sr=waterson@netscape.com

git-svn-id: svn://10.0.0.236/trunk@123350 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dougt%netscape.com 2002-06-14 21:33:05 +00:00
parent e9bfb59882
commit dffd6e4f8a
20 changed files with 1092 additions and 1407 deletions

View File

@ -56,7 +56,7 @@
#ifndef NO_SUBSCRIPT_LOADER
#include "mozJSSubScriptLoader.h"
#endif
#include "nsIComponentLoaderManager.h"
// For reporting errors with the console service
#include "nsIScriptError.h"
#include "nsIConsoleService.h"
@ -391,8 +391,7 @@ BackstagePass::NewResolve(nsIXPConnectWrappedNative *wrapper,
}
mozJSComponentLoader::mozJSComponentLoader()
: mCompMgr(nsnull),
mRuntime(nsnull),
: mRuntime(nsnull),
mModules(nsnull),
mGlobals(nsnull),
mXPCOMKey(0),
@ -429,7 +428,8 @@ mozJSComponentLoader::~mozJSComponentLoader()
{
if (mInitialized) {
mInitialized = PR_FALSE;
PL_HashTableEnumerateEntries(mModules, UnloadAndReleaseModules,
PL_HashTableEnumerateEntries(mModules,
UnloadAndReleaseModules,
mCompMgr);
PL_HashTableDestroy(mModules);
mModules = nsnull;
@ -480,7 +480,11 @@ NS_IMETHODIMP
mozJSComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg)
{
mCompMgr = aCompMgr;
nsresult rv;
mLoaderManager = do_QueryInterface(mCompMgr, &rv);
if (NS_FAILED(rv))
return rv;
/* initialize registry handles */
mRegistry = do_QueryInterface(aReg, &rv);
@ -605,75 +609,29 @@ mozJSComponentLoader::SetRegistryInfo(const char *registryLocation,
nsIFile *component)
{
nsresult rv;
if (!mRegistry.get())
return NS_OK; // silent failure
PRUint32 length = strlen(registryLocation);
char* eRegistryLocation;
rv = mRegistry->EscapeKey((PRUint8*)registryLocation, 1, &length, (PRUint8**)&eRegistryLocation);
if (rv != NS_OK)
{
return rv;
}
if (eRegistryLocation == nsnull) // No escaping required
eRegistryLocation = (char*)registryLocation;
nsRegistryKey key;
rv = mRegistry->AddSubtreeRaw(mXPCOMKey, eRegistryLocation, &key);
if (registryLocation != eRegistryLocation)
nsMemory::Free(eRegistryLocation);
if (NS_FAILED(rv))
return rv;
if (!mLoaderManager)
return NS_ERROR_FAILURE;
PRInt64 modDate;
if (NS_FAILED(rv = component->GetLastModifiedTime(&modDate)) ||
NS_FAILED(rv = mRegistry->SetLongLong(key, JSlastModValueName, &modDate)))
return rv;
PRInt64 fileSize;
if (NS_FAILED(rv = component->GetFileSize(&fileSize)) ||
NS_FAILED(rv = mRegistry->SetLongLong(key, JSfileSizeValueName, &fileSize)))
rv = component->GetLastModifiedTime(&modDate);
if (NS_FAILED(rv))
return rv;
#ifdef DEBUG_shaver_off
fprintf(stderr, "SetRegistryInfo(%s) => (%d,%d)\n", registryLocation,
modDate, fileSize);
#endif
return NS_OK;
return mLoaderManager->SaveFileInfo(component, registryLocation, modDate);
}
nsresult
mozJSComponentLoader::RemoveRegistryInfo(const char *registryLocation)
mozJSComponentLoader::RemoveRegistryInfo(nsIFile *component, const char *registryLocation)
{
if (!mRegistry.get())
return NS_OK; // silent failure
nsresult rv;
if (!mRegistry.get())
return NS_OK; // silent failure
PRUint32 length = strlen(registryLocation);
char* eRegistryLocation;
rv = mRegistry->EscapeKey((PRUint8*)registryLocation, 1, &length, (PRUint8**)&eRegistryLocation);
if (rv != NS_OK)
{
return rv;
}
if (eRegistryLocation == nsnull) // No escaping required
eRegistryLocation = (char*)registryLocation;
rv = mRegistry->RemoveSubtree(mXPCOMKey, eRegistryLocation);
if (registryLocation != eRegistryLocation)
nsMemory::Free(eRegistryLocation);
return rv;
if (!mLoaderManager)
return NS_ERROR_FAILURE;
return mLoaderManager->RemoveFileInfo(component, registryLocation);
}
@ -681,46 +639,16 @@ PRBool
mozJSComponentLoader::HasChanged(const char *registryLocation,
nsIFile *component)
{
/* if we don't have a registry handle, force registration of component */
if (!mRegistry)
return PR_TRUE;
nsresult rv;
PRUint32 length = strlen(registryLocation);
char* eRegistryLocation;
rv = mRegistry->EscapeKey((PRUint8*)registryLocation, 1, &length, (PRUint8**)&eRegistryLocation);
if (rv != NS_OK)
{
return rv;
}
if (eRegistryLocation == nsnull) // No escaping required
eRegistryLocation = (char*)registryLocation;
nsRegistryKey key;
int r = NS_FAILED(mRegistry->GetSubtreeRaw(mXPCOMKey, eRegistryLocation, &key));
if (registryLocation != eRegistryLocation)
nsMemory::Free(eRegistryLocation);
if (r)
return PR_TRUE;
/* check modification date */
PRInt64 regTime, lastTime;
if (NS_FAILED(mRegistry->GetLongLong(key, JSlastModValueName, &regTime)))
return PR_TRUE;
if (!mLoaderManager)
return NS_ERROR_FAILURE;
if (NS_FAILED(component->GetLastModifiedTime(&lastTime)) || LL_NE(lastTime, regTime))
return PR_TRUE;
PRInt64 lastTime;
component->GetLastModifiedTime(&lastTime);
/* check file size */
PRInt64 regSize;
if (NS_FAILED(mRegistry->GetLongLong(key, JSfileSizeValueName, &regSize)))
return PR_TRUE;
PRInt64 size;
if (NS_FAILED(component->GetFileSize(&size)) || LL_NE(size,regSize) )
return PR_TRUE;
return PR_FALSE;
PRBool hasChanged = PR_TRUE;
mLoaderManager->HasFileChanged(component, registryLocation, lastTime, &hasChanged);
return hasChanged;
}
NS_IMETHODIMP
@ -829,7 +757,7 @@ mozJSComponentLoader::AttemptRegistration(nsIFile *component,
/* no need to check registry data on deferred reg */
if (!deferred && !HasChanged(registryLocation, component))
goto out;
return NS_OK;
module = ModuleForLocation(registryLocation, component);
if (!module)
@ -926,7 +854,7 @@ mozJSComponentLoader::UnregisterComponent(nsIFile *component)
if (NS_SUCCEEDED(rv))
{
// Remove any autoreg specific info. Ignore error.
RemoveRegistryInfo(registryLocation);
RemoveRegistryInfo(component, registryLocation);
}
return rv;

View File

@ -19,6 +19,7 @@
#include "plhash.h"
#include "jsapi.h"
#include "nsIComponentLoader.h"
#include "nsIComponentLoaderManager.h"
#include "nsIJSRuntimeService.h"
#include "nsIJSContextStack.h"
#include "nsIRegistry.h"
@ -58,9 +59,10 @@ public:
nsIModule *ModuleForLocation(const char *aLocation, nsIFile *component);
PRBool HasChanged(const char *registryLocation, nsIFile *component);
nsresult SetRegistryInfo(const char *registryLocation, nsIFile *component);
nsresult RemoveRegistryInfo(const char *registryLocation);
nsresult RemoveRegistryInfo(nsIFile *component, const char *registryLocation);
nsIComponentManager* mCompMgr; // weak ref, should make it strong?
nsCOMPtr<nsIComponentManager> mCompMgr;
nsCOMPtr<nsIComponentLoaderManager> mLoaderManager;
nsCOMPtr<nsIRegistry> mRegistry;
nsCOMPtr<nsIJSRuntimeService> mRuntimeService;
#ifndef XPCONNECT_STANDALONE

View File

@ -105,6 +105,14 @@
#include "nsLeakDetector.h"
#endif
// Registry Factory creation function defined in nsRegistry.cpp
// We hook into this function locally to create and register the registry
// Since noone outside xpcom needs to know about this and nsRegistry.cpp
// does not have a local include file, we are putting this definition
// here rather than in nsIRegistry.h
extern "C" NS_EXPORT nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
@ -158,26 +166,6 @@ nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* outer,
return iim->QueryInterface(aIID, aInstancePtr);
}
////////////////////////////////////////////////////////////////////////////////
// XPCOM initialization
//
// To Control the order of initialization of these key components I am putting
// this function.
//
// - nsServiceManager
// - nsComponentManager
// - nsRegistry
//
// Here are key points to remember:
// - A global of all these need to exist. nsServiceManager is an independent object.
// nsComponentManager uses both the globalServiceManager and its own registry.
//
// - A static object of both the nsComponentManager and nsServiceManager
// are in use. Hence InitXPCOM() gets triggered from both
// NS_GetGlobale{Service/Component}Manager() calls.
//
// - There exists no global Registry. Registry can be created from the component manager.
//
static nsresult
RegisterGenericFactory(nsIComponentManager* compMgr,
@ -425,6 +413,7 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
// clients can create new objects.
// Registry
nsIFactory *registryFactory = NULL;
rv = NS_RegistryGetFactory(&registryFactory);
if (NS_FAILED(rv)) return rv;
@ -436,6 +425,7 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
NS_REGISTRY_CONTRACTID,
registryFactory, PR_TRUE);
NS_RELEASE(registryFactory);
if (NS_FAILED(rv)) return rv;
// Category Manager
@ -457,10 +447,12 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
for (int i = 0; i < components_length; i++)
RegisterGenericFactory(compMgr, &components[i]);
// Prepopulate registry for performance
// Ignore return value. It is ok if this fails.
nsComponentManagerImpl::gComponentManager->PlatformPrePopulateRegistry();
rv = nsComponentManagerImpl::gComponentManager->ReadPersistentRegistry();
#ifdef DEBUG
if (NS_FAILED(rv)) {
printf("No Persistent Registry Found.\n");
}
#endif
// Pay the cost at startup time of starting this singleton.
nsIInterfaceInfoManager* iim = XPTI_GetInterfaceInfoManager();
NS_IF_RELEASE(iim);

View File

@ -2,6 +2,7 @@ nsICategoryHandler.idl
nsICategoryManager.idl
nsIClassInfo.idl
nsIComponentLoader.idl
nsIComponentLoaderManager.idl
nsIComponentManager.idl
nsIComponentManagerObsolete.idl
nsIComponentRegistrar.idl

View File

@ -67,6 +67,7 @@ XPIDLSRCS = \
nsICategoryHandler.idl \
nsICategoryManager.idl \
nsIComponentLoader.idl \
nsIComponentLoaderManager.idl \
nsIComponentManagerObsolete.idl \
nsIComponentRegistrar.idl \
nsIRegistry.idl \
@ -82,7 +83,7 @@ SDK_XPIDLSRCS = \
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
LOCAL_INCLUDES = -I$(srcdir)/../base -I$(srcdir)/../thread
LOCAL_INCLUDES = -I$(srcdir)/../base -I$(srcdir)/../thread -I$(srcdir)/../ds
# we don't want the shared lib, but we want to force the creation of a static lib.
FORCE_STATIC_LIB = 1
@ -91,8 +92,7 @@ FORCE_STATIC_LIB = 1
FORCE_USE_PIC = 1
include $(topsrcdir)/config/rules.mk
DEFINES += -DUSE_NSREG -D_IMPL_NS_COM -D_IMPL_NS_BASE
DEFINES += -D_IMPL_NS_COM -D_IMPL_NS_BASE
ifeq ($(OS_ARCH), WINNT)
DEFINES += -DWIN32_LEAN_AND_MEAN
endif

View File

@ -51,6 +51,7 @@ XPIDLSRCS = \
.\nsICategoryManager.idl \
.\nsIClassInfo.idl \
.\nsIComponentLoader.idl \
.\nsIComponentLoaderManager.idl \
.\nsIComponentManager.idl \
.\nsIComponentManagerObsolete.idl \
.\nsIComponentRegistrar.idl \
@ -71,7 +72,7 @@ LINCS = \
-I..\io \
$(NULL)
LCFLAGS = -DUSE_NSREG -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN
LCFLAGS = -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN
!ifdef MOZ_STATIC_COMPONENT_LIBS
LCFLAGS = $(LCFLAGS) -DENABLE_STATIC_COMPONENT_LOADER

View File

@ -42,7 +42,7 @@
#include "nsHashtable.h"
#include "nsIFactory.h"
#include "nsIRegistry.h"
#include "nsISupportsPrimitives.h"
#include "nsSupportsPrimitives.h"
#include "nsIObserver.h"
#include "nsComponentManager.h"
#include "nsReadableUtils.h"
@ -70,7 +70,8 @@ ExtractKeyString( nsHashKey* key, void*, void*, nsISupports** _retval )
*/
{
nsresult status;
nsCOMPtr<nsISupportsString> obj = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &status);
nsCOMPtr<nsISupportsString> obj = new nsSupportsStringImpl();
if ( obj ) {
nsCStringKey* strkey = NS_STATIC_CAST(nsCStringKey*, key);
status = obj->SetDataWithLength(strkey->GetStringLength(), strkey->GetString());
@ -146,8 +147,6 @@ class nsCategoryManager
private:
friend class nsCategoryManagerFactory;
nsCategoryManager();
nsresult initialize();
// Warning: whoever creates an instance must call |initialize()| before any other method
public:
virtual ~nsCategoryManager();
@ -157,13 +156,6 @@ class nsCategoryManager
private:
CategoryNode* find_category( const char* );
nsresult persist( const char* aCategoryName, const char* aKey, const char* aValue );
nsresult dont_persist( const char* aCategoryName, const char* aKey );
private:
// |mRegistry != 0| after |initialize()|... I can't live without it
nsCOMPtr<nsIRegistry> mRegistry;
nsRegistryKey mCategoriesRegistryKey;
};
NS_IMPL_ISUPPORTS1(nsCategoryManager, nsICategoryManager)
@ -176,71 +168,6 @@ nsCategoryManager::nsCategoryManager()
NS_INIT_REFCNT();
}
nsresult
nsCategoryManager::initialize()
{
const char* kCategoriesRegistryPath = "software/mozilla/XPCOM/categories";
// Alas, this is kind of buried down here, but you can't put constant strings in a class declaration... oh, well
// Get a pointer to the registry, and get it open and ready for us
nsresult status;
if ( mRegistry = do_GetService(NS_REGISTRY_CONTRACTID, &status) )
if ( NS_SUCCEEDED(status = mRegistry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry)) )
if ( (status = mRegistry->GetSubtree(nsIRegistry::Common, kCategoriesRegistryPath, &mCategoriesRegistryKey)) == NS_ERROR_REG_NOT_FOUND )
status = mRegistry->AddSubtree(nsIRegistry::Common, kCategoriesRegistryPath, &mCategoriesRegistryKey);
// All right, we've got the registry now (or not), that's the important thing.
// Returning an error will cause callers to destroy me. So not getting the registry
// is worth returning an error for (I can't live without it). Now we'll load in our
// persistent data from the registry, but that's _not_ worth getting killed over, so
// don't save any errors from this process.
// Now load the registry data
if ( NS_SUCCEEDED(status) )
{
nsCOMPtr<nsIEnumerator> keys;
mRegistry->EnumerateSubtrees(mCategoriesRegistryKey, getter_AddRefs(keys));
for ( keys->First(); keys->IsDone() == NS_ENUMERATOR_FALSE; keys->Next() )
{
nsXPIDLCString categoryName;
nsRegistryKey categoryKey;
{
nsCOMPtr<nsISupports> supportsNode;
keys->CurrentItem(getter_AddRefs(supportsNode));
nsCOMPtr<nsIRegistryNode> registryNode = do_QueryInterface(supportsNode);
registryNode->GetNameUTF8(getter_Copies(categoryName));
registryNode->GetKey(&categoryKey);
}
nsCOMPtr<nsIEnumerator> values;
mRegistry->EnumerateValues(categoryKey, getter_AddRefs(values));
for ( values->First(); values->IsDone() == NS_ENUMERATOR_FALSE; values->Next() )
{
nsXPIDLCString entryName;
{
nsCOMPtr<nsISupports> supportsValue;
values->CurrentItem(getter_AddRefs(supportsValue));
nsCOMPtr<nsIRegistryValue> registryValue = do_QueryInterface(supportsValue);
registryValue->GetNameUTF8(getter_Copies(entryName));
}
nsXPIDLCString value;
mRegistry->GetStringUTF8(categoryKey, entryName, getter_Copies(value));
AddCategoryEntry(categoryName, entryName, value, PR_FALSE, PR_FALSE, 0);
}
}
}
return status;
}
nsCategoryManager::~nsCategoryManager()
{
}
@ -252,39 +179,6 @@ nsCategoryManager::find_category( const char* aCategoryName )
return NS_STATIC_CAST(CategoryNode*, Get(&categoryNameKey));
}
nsresult
nsCategoryManager::persist( const char* aCategoryName, const char* aKey, const char* aValue )
{
NS_ASSERTION(mRegistry, "mRegistry is NULL!");
nsRegistryKey categoryRegistryKey;
nsresult status = mRegistry->GetSubtreeRaw(mCategoriesRegistryKey, aCategoryName, &categoryRegistryKey);
if ( status == NS_ERROR_REG_NOT_FOUND )
status = mRegistry->AddSubtreeRaw(mCategoriesRegistryKey, aCategoryName, &categoryRegistryKey);
if ( NS_SUCCEEDED(status) )
status = mRegistry->SetStringUTF8(categoryRegistryKey, aKey, aValue);
return status;
}
nsresult
nsCategoryManager::dont_persist( const char* aCategoryName, const char* aKey )
{
NS_ASSERTION(mRegistry, "mRegistry is NULL!");
nsRegistryKey categoryRegistryKey;
nsresult status = mRegistry->GetSubtreeRaw(mCategoriesRegistryKey, aCategoryName, &categoryRegistryKey);
if ( NS_SUCCEEDED(status) )
status = mRegistry->DeleteValue(categoryRegistryKey, aKey);
return status;
}
NS_IMETHODIMP
nsCategoryManager::GetCategoryEntry( const char *aCategoryName,
const char *aEntryName,
@ -387,16 +281,12 @@ nsCategoryManager::AddCategoryEntry( const char *aCategoryName,
nsCStringKey entryNameKey(aEntryName);
category->Put(&entryNameKey, entry);
// If you said 'persist' but not 'replace', and an entry
// got in the way ... sorry, you won't go into the persistent store.
// This was probably an error on your part. If this was _really_
// what you wanted to do, i.e., have a different value in the backing
// store than in the live database, then do it by setting the value
// with 'persist' and 'replace' and saving the returned old value, then
// restoring the old value with 'replace' but _not_ 'persist'.
if ( aPersist )
status = persist(aCategoryName, aEntryName, aValue);
// this function is not public yet, hence it is externed here.
extern nsresult NS_GetComponentLoaderManager(nsIComponentLoaderManager* *result);
nsCOMPtr<nsIComponentLoaderManager> mgr;
NS_GetComponentLoaderManager(getter_AddRefs(mgr));
if (mgr)
mgr->FlushPersistentStore(PR_FALSE);
}
return status;
@ -426,11 +316,7 @@ nsCategoryManager::DeleteCategoryEntry( const char *aCategoryName,
category->RemoveAndDelete(&entryKey);
}
nsresult status = NS_OK;
if ( aDontPersist )
status = dont_persist(aCategoryName, aEntryName);
return status;
return NS_OK;
}
@ -478,18 +364,26 @@ nsCategoryManager::EnumerateCategory( const char *aCategoryName,
}
NS_IMETHODIMP
nsCategoryManager::EnumerateCategories(nsISimpleEnumerator **_retval)
{
NS_ASSERTION(_retval, "_retval is NULL!");
*_retval = 0;
NS_IMETHODIMP
nsCategoryManager::GetCategoryContents( const char *category,
char ***entries,
char ***values,
PRUint32 *count )
{
// BULLSHIT ALERT: Wasn't implemented in JS either.
// Will people use this? If not, let's get rid of it
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult status = NS_ERROR_NOT_AVAILABLE;
nsCOMPtr<nsIEnumerator> innerEnumerator;
if ( NS_SUCCEEDED(status = NS_NewHashtableEnumerator(this, ExtractKeyString, 0, getter_AddRefs(innerEnumerator))))
status = NS_NewAdapterEnumerator(_retval, innerEnumerator);
// If you couldn't find the category, or had trouble creating an enumerator...
if ( NS_FAILED(status) )
{
NS_IF_RELEASE(*_retval);
status = NS_NewEmptyEnumerator(_retval);
}
return status;
}
NS_IMETHODIMP
@ -546,10 +440,7 @@ nsCategoryManagerFactory::CreateInstance( nsISupports* aOuter, const nsIID& aIID
nsCategoryManager* raw_category_manager;
nsCOMPtr<nsICategoryManager> new_category_manager = (raw_category_manager = new nsCategoryManager);
if ( new_category_manager )
{
if ( NS_SUCCEEDED(status = raw_category_manager->initialize()) )
status = new_category_manager->QueryInterface(aIID, aResult);
}
else
status = NS_ERROR_OUT_OF_MEMORY;
}

File diff suppressed because it is too large Load Diff

View File

@ -45,9 +45,10 @@
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIComponentManagerObsolete.h"
#include "nsIComponentLoaderManager.h"
#include "nsICategoryManager.h"
#include "nsIServiceManager.h"
#include "nsIFactory.h"
#include "nsRegistry.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "pldhash.h"
@ -63,12 +64,6 @@ class nsFactoryEntry;
class nsDll;
class nsIServiceManager;
// Registry Factory creation function defined in nsRegistry.cpp
// We hook into this function locally to create and register the registry
// Since noone outside xpcom needs to know about this and nsRegistry.cpp
// does not have a local include file, we are putting this definition
// here rather than in nsIRegistry.h
extern "C" NS_EXPORT nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
// Predefined loader types. Do not change the numbers.
// NATIVE should be 0 as it is being used as the first array index.
@ -82,6 +77,11 @@ extern const char XPCOM_LIB_PREFIX[];
////////////////////////////////////////////////////////////////////////////////
// Array of Loaders and their type strings
struct nsLoaderdata {
nsIComponentLoader *loader;
const char *type;
};
class nsComponentManagerImpl
: public nsIComponentManager,
@ -89,6 +89,7 @@ class nsComponentManagerImpl
public nsIComponentRegistrar,
public nsSupportsWeakReference,
public nsIInterfaceRequestor,
public nsIComponentLoaderManager,
public nsIServiceManagerObsolete,
public nsIComponentManagerObsolete
{
@ -127,6 +128,7 @@ public:
NS_DECL_NSISERVICEMANAGER
NS_DECL_NSISERVICEMANAGEROBSOLETE
NS_DECL_NSICOMPONENTLOADERMANAGER
// nsComponentManagerImpl methods:
nsComponentManagerImpl();
@ -134,7 +136,13 @@ public:
static nsComponentManagerImpl* gComponentManager;
nsresult Init(void);
nsresult PlatformPrePopulateRegistry();
nsresult WritePersistentRegistry();
nsresult ReadPersistentRegistry();
private:
nsresult WriteCategoryManagerToRegistry(PRFileDesc* fd);
public:
nsresult Shutdown(void);
nsresult FreeServices();
@ -153,18 +161,14 @@ protected:
const char *aRegistryName,
PRBool aReplace, PRBool aPersist,
const char *aType);
nsresult AddComponentToRegistry(const nsCID &aCID, const char *aClassName,
const char *aContractID,
const char *aRegistryName,
const char *aType);
nsresult GetLoaderForType(int aType,
nsIComponentLoader **aLoader);
nsresult FindFactory(const char *contractID, nsIFactory **aFactory) ;
nsresult LoadFactory(nsFactoryEntry *aEntry, nsIFactory **aFactory);
nsFactoryEntry *GetFactoryEntry(const char *aContractID, int checkRegistry = -1);
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass, int checkRegistry = -1);
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass, nsIDKey &cidKey, int checkRegistry = -1);
nsFactoryEntry *GetFactoryEntry(const char *aContractID);
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass);
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass, nsIDKey &cidKey);
nsresult SyncComponentsInDir(PRInt32 when, nsIFile *dirSpec);
nsresult SelfRegisterDll(nsDll *dll);
@ -178,16 +182,6 @@ protected:
nsresult UnloadLibraries(nsIServiceManager *servmgr, PRInt32 when);
// The following functions are the only ones that operate on the persistent
// registry
nsresult PlatformInit(void);
nsresult PlatformVersionCheck(nsRegistryKey *aXPCOMRootKey);
nsresult PlatformRegister(const char *cidString, const char *className, const char *contractID, nsDll *dll);
nsresult PlatformUnregister(const char *cidString, const char *aLibrary);
nsresult PlatformFind(const nsCID &aCID, nsFactoryEntry* *result);
nsresult PlatformContractIDToCLSID(const char *aContractID, nsCID *aClass);
nsresult PlatformCLSIDToContractID(const nsCID *aClass, char* *aClassName, char* *aContractID);
// Convert a loader type string into an index into the loader data
// array. Empty loader types are converted to NATIVE. Returns -1 if
// loader type cannot be determined.
@ -206,12 +200,6 @@ protected:
PLDHashTable mContractIDs;
PRMonitor* mMon;
nsIRegistry* mRegistry;
nsRegistryKey mXPCOMKey;
nsRegistryKey mClassesKey;
nsRegistryKey mCLSIDKey;
PRBool mPrePopulationDone;
nsRegistryKey mLoadersKey;
nsNativeComponentLoader *mNativeComponentLoader;
nsIComponentLoader *mStaticComponentLoader;
nsCOMPtr<nsIFile> mComponentsDir;
@ -223,16 +211,14 @@ protected:
#define NS_SHUTDOWN_COMPLETE 2
PRUint32 mShuttingDown;
// Array of Loaders and their type strings
struct nsLoaderdata {
nsIComponentLoader *loader;
const char *type;
};
nsLoaderdata *mLoaderData;
int mNLoaderData;
int mMaxNLoaderData;
PRBool mRegistryDirty;
nsVoidArray mAutoRegEntries;
nsCOMPtr<nsICategoryManager> mCategoryManager;
PLArenaPool mArena;
};
@ -350,5 +336,21 @@ struct nsContractIDTableEntry : public PLDHashEntryHdr {
char *mContractID;
nsFactoryEntry *mFactoryEntry;
};
class AutoRegEntry
{
public:
AutoRegEntry(){};
AutoRegEntry(const char* name, PRInt64* modDate);
virtual ~AutoRegEntry();
char* GetName() {return mName;}
PRInt64 GetDate() {return mModDate;}
void SetDate(PRInt64 *date) { mModDate = *date;}
PRBool Modified(PRInt64 *date);
private:
char* mName;
PRInt64 mModDate;
};
#endif // nsComponentManager_h__

View File

@ -73,13 +73,12 @@ interface nsICategoryManager : nsISupports
*/
nsISimpleEnumerator enumerateCategory(in string aCategory);
/**
* Get all the category contents.
* Enumerate the entries in a category.
* @param aCategory The category to be enumerated.
*/
void getCategoryContents(in string category,
[array, size_is(count)] out string entries,
[array, size_is(count)] out string values,
[retval] out unsigned long count);
nsISimpleEnumerator enumerateCategories();
const long OVERRIDE = 0;
const long FALLBACK = 1;

View File

@ -0,0 +1,69 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is XPCOM.
*
* The Initial Developer of the Original Code is Netscape Communications.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* The nsIComponentRegistrar interface.
* @status EXPERIMENTAL
*
* USE AT YOUR OWN RISK
* USE AT YOUR OWN RISK
* USE AT YOUR OWN RISK
* USE AT YOUR OWN RISK
* USE AT YOUR OWN RISK
* USE AT YOUR OWN RISK
*/
#include "nsISupports.idl"
interface nsIFile;
[scriptable, uuid(fce83d37-a3c0-4e09-ad9f-6842a984dbdf)]
interface nsIComponentLoaderManager : nsISupports
{
boolean hasFileChanged(in nsIFile file, in string loaderString, in PRInt64 modDate);
void saveFileInfo(in nsIFile file, in string loaderString, in PRInt64 modDate);
void removeFileInfo(in nsIFile file, in string loaderString);
void flushPersistentStore(in boolean now);
};

View File

@ -49,14 +49,6 @@
#include "nsILocalFileMac.h"
#endif
#define PRINT_CRITICAL_ERROR_TO_SCREEN 1
#define USE_REGISTRY 1
#undef OBSOLETE_MODULE_LOADING
#ifdef OBSOLETE_MODULE_LOADING
#include "nsObsoleteModuleLoading.h"
#endif
// Logging of debug output
#ifdef MOZ_LOGGING
#define FORCE_PR_LOG /* Allow logging in the release build */
@ -65,7 +57,7 @@
extern PRLogModuleInfo *nsComponentManagerLog;
nsNativeComponentLoader::nsNativeComponentLoader() :
mRegistry(nsnull), mCompMgr(nsnull), mDllStore(nsnull)
mCompMgr(nsnull), mDllStore(nsnull)
{
NS_INIT_REFCNT();
}
@ -80,7 +72,6 @@ nsDll_Destroy(nsHashKey *aKey, void *aData, void* closure)
nsNativeComponentLoader::~nsNativeComponentLoader()
{
mRegistry = nsnull;
mCompMgr = nsnull;
delete mDllStore;
@ -103,8 +94,7 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID,
/* Should this all live in xcDll? */
nsDll *dll;
PRInt64 mod = LL_Zero(), size = LL_Zero();
rv = CreateDll(nsnull, aLocation, &mod, &size, &dll);
rv = CreateDll(nsnull, aLocation, &dll);
if (NS_FAILED(rv))
return rv;
@ -167,82 +157,15 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID,
NS_IMETHODIMP
nsNativeComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg)
{
nsresult rv;
mCompMgr = aCompMgr;
mRegistry = do_QueryInterface(aReg);
if (!mCompMgr || !mRegistry)
if (!mCompMgr)
return NS_ERROR_INVALID_ARG;
rv = mRegistry->GetSubtree(nsIRegistry::Common, xpcomComponentsKeyName,
&mXPCOMKey);
if (NS_FAILED(rv))
return rv;
NS_ASSERTION(!mDllStore, "Init must not be called more than once");
mDllStore = new nsObjectHashtable(nsnull,
nsnull, // never copy
nsDll_Destroy,
nsnull,
256,
PR_TRUE); // thread safe
mDllStore = new nsObjectHashtable(nsnull, nsnull, // never copy
nsDll_Destroy, nsnull,
256, /* Thead Safe */ PR_TRUE);
if (!mDllStore)
return NS_ERROR_OUT_OF_MEMORY;
// Read in all dll entries and populate the mDllStore
nsCOMPtr<nsIEnumerator> dllEnum;
rv = mRegistry->EnumerateSubtrees( mXPCOMKey, getter_AddRefs(dllEnum));
if (NS_FAILED(rv)) return rv;
rv = dllEnum->First();
for (; NS_SUCCEEDED(rv) && (dllEnum->IsDone() != NS_OK); (rv = dllEnum->Next()))
{
nsCOMPtr<nsISupports> base;
rv = dllEnum->CurrentItem(getter_AddRefs(base));
if (NS_FAILED(rv)) continue;
// Get specific interface.
nsIID nodeIID = NS_IREGISTRYNODE_IID;
nsCOMPtr<nsIRegistryNode> node;
rv = base->QueryInterface( nodeIID, getter_AddRefs(node) );
if (NS_FAILED(rv)) continue;
// Get library name
nsXPIDLCString library;
rv = node->GetNameUTF8(getter_Copies(library));
if (NS_FAILED(rv)) continue;
char* uLibrary;
char* eLibrary = (char*)library.operator const char*();
PRUint32 length = strlen(eLibrary);
rv = mRegistry->UnescapeKey((PRUint8*)eLibrary, 1, &length, (PRUint8**)&uLibrary);
if (NS_FAILED(rv)) continue;
if (uLibrary == nsnull)
uLibrary = eLibrary;
// Get key associated with library
nsRegistryKey libKey;
rv = node->GetKey(&libKey);
if (NS_SUCCEEDED(rv)) // Cannot continue here, because we have to free unescape
{
// Create nsDll with this name
nsDll *dll = NULL;
PRInt64 lastModTime;
PRInt64 fileSize;
GetRegistryDllInfo(libKey, &lastModTime, &fileSize);
rv = CreateDll(NULL, uLibrary, &lastModTime, &fileSize, &dll);
}
if (uLibrary && (uLibrary != eLibrary))
nsMemory::Free(uLibrary);
if (NS_FAILED(rv)) continue;
}
return NS_OK;
}
@ -471,11 +394,11 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll,
("nsNativeComponentLoader: Loaded \"%s\".", dll->GetDisplayPath()));
// Tell the module to self register
nsCOMPtr<nsIFile> fs;
nsCOMPtr<nsIModule> mobj;
res = dll->GetModule(mCompMgr, getter_AddRefs(mobj));
if (NS_SUCCEEDED(res))
{
nsCOMPtr<nsIFile> fs;
/*************************************************************
* WARNING: Why are use introducing 'res2' here and then *
* later assigning it to 'res' rather than just using 'res'? *
@ -519,13 +442,20 @@ nsNativeComponentLoader::SelfRegisterDll(nsDll *dll,
// able to register on some later autoreg, after another component has been
// installed.
if (res != NS_ERROR_FACTORY_REGISTER_AGAIN) {
dll->Sync();
PRInt64 modTime;
if (!fs)
return res;
PRInt64 modTime, size;
dll->GetLastModifiedTime(&modTime);
dll->GetSize(&size);
SetRegistryDllInfo(registryLocation, &modTime, &size);
fs->GetLastModifiedTime(&modTime);
nsCOMPtr<nsIComponentLoaderManager> manager = do_QueryInterface(mCompMgr);
if (!manager)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIFile> fs;
res = dll->GetDllSpec(getter_AddRefs(fs));
if (NS_FAILED(res)) return res;
manager->SaveFileInfo(fs, registryLocation, modTime);
}
return res;
@ -698,15 +628,19 @@ nsNativeComponentLoader::AutoUnregisterComponent(PRInt32 when,
}
nsDll *dll = NULL;
PRInt64 mod = LL_Zero(), size = LL_Zero();
rv = CreateDll(component, persistentDescriptor, &mod, &size, &dll);
rv = CreateDll(component, persistentDescriptor, &dll);
if (NS_FAILED(rv) || dll == NULL) return rv;
rv = SelfUnregisterDll(dll);
// Remove any autoreg info about this dll
if (NS_SUCCEEDED(rv))
RemoveRegistryDllInfo(persistentDescriptor);
nsCStringKey key(persistentDescriptor);
mDllStore->RemoveAndDelete(&key);
nsCOMPtr<nsIComponentLoaderManager> manager = do_QueryInterface(mCompMgr, &rv);
if (NS_FAILED(rv))
return rv;
manager->RemoveFileInfo(component, nsnull);
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
("nsNativeComponentLoader: AutoUnregistration for %s %s.",
@ -812,8 +746,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
// Get the registry representation of the dll, if any
nsDll *dll;
PRInt64 mod = LL_Zero(), size = LL_Zero();
rv = CreateDll(component, persistentDescriptor, &mod, &size, &dll);
rv = CreateDll(component, persistentDescriptor, &dll);
if (NS_FAILED(rv))
return rv;
@ -1016,98 +949,6 @@ nsNativeComponentLoader::UnloadAll(PRInt32 aWhen)
return NS_OK;
}
nsresult
nsNativeComponentLoader::GetRegistryDllInfo(const char *aLocation,
PRInt64 *lastModifiedTime,
PRInt64 *fileSize)
{
nsresult rv;
PRUint32 length = strlen(aLocation);
char* eLocation;
rv = mRegistry->EscapeKey((PRUint8*)aLocation, 1, &length, (PRUint8**)&eLocation);
if (rv != NS_OK)
{
return rv;
}
if (eLocation == nsnull) // No escaping required
eLocation = (char*)aLocation;
nsRegistryKey key;
rv = mRegistry->GetSubtreeRaw(mXPCOMKey, eLocation, &key);
if (NS_FAILED(rv)) return rv;
rv = GetRegistryDllInfo(key, lastModifiedTime, fileSize);
if (aLocation != eLocation)
nsMemory::Free(eLocation);
return rv;
}
nsresult
nsNativeComponentLoader::GetRegistryDllInfo(nsRegistryKey key,
PRInt64 *lastModifiedTime,
PRInt64 *fileSize)
{
PRInt64 lastMod;
nsresult rv = mRegistry->GetLongLong(key, lastModValueName, &lastMod);
if (NS_FAILED(rv)) return rv;
*lastModifiedTime = lastMod;
PRInt64 fsize;
rv = mRegistry->GetLongLong(key, fileSizeValueName, &fsize);
if (NS_FAILED(rv)) return rv;
*fileSize = fsize;
return NS_OK;
}
nsresult
nsNativeComponentLoader::SetRegistryDllInfo(const char *aLocation,
PRInt64 *lastModifiedTime,
PRInt64 *fileSize)
{
nsresult rv;
PRUint32 length = strlen(aLocation);
char* eLocation;
rv = mRegistry->EscapeKey((PRUint8*)aLocation, 1, &length, (PRUint8**)&eLocation);
if (rv != NS_OK)
{
return rv;
}
if (eLocation == nsnull) // No escaping required
eLocation = (char*)aLocation;
nsRegistryKey key;
rv = mRegistry->GetSubtreeRaw(mXPCOMKey, eLocation, &key);
if (NS_FAILED(rv)) return rv;
rv = mRegistry->SetLongLong(key, lastModValueName, lastModifiedTime);
if (NS_FAILED(rv)) return rv;
rv = mRegistry->SetLongLong(key, fileSizeValueName, fileSize);
if (aLocation != eLocation)
nsMemory::Free(eLocation);
return rv;
}
nsresult
nsNativeComponentLoader::RemoveRegistryDllInfo(const char *aLocation)
{
nsresult rv;
PRUint32 length = strlen(aLocation);
char* eLocation;
rv = mRegistry->EscapeKey((PRUint8*)aLocation, 1, &length, (PRUint8**)&eLocation);
if (rv != NS_OK)
{
return rv;
}
if (eLocation == nsnull) // No escaping required
eLocation = (char*)aLocation;
rv = mRegistry->RemoveSubtree(mXPCOMKey, eLocation);
if (aLocation != eLocation)
nsMemory::Free(eLocation);
return rv;
}
//
// CreateDll
// The only way to create a dll or get it from the dll cache. This will
@ -1127,8 +968,8 @@ nsNativeComponentLoader::RemoveRegistryDllInfo(const char *aLocation)
// registry along with its lastModTime and fileSize.
// {NULL, rel:libpref.so, 8985659, 20987}
nsresult
nsNativeComponentLoader::CreateDll(nsIFile *aSpec, const char *aLocation,
PRInt64 *modificationTime, PRInt64 *fileSize,
nsNativeComponentLoader::CreateDll(nsIFile *aSpec,
const char *aLocation,
nsDll **aDll)
{
nsDll *dll;
@ -1167,22 +1008,11 @@ nsNativeComponentLoader::CreateDll(nsIFile *aSpec, const char *aLocation,
if (!dll)
{
PR_ASSERT(modificationTime != NULL);
PR_ASSERT(fileSize != NULL);
PRInt64 zit = LL_Zero();
if (LL_EQ(*modificationTime,zit) && LL_EQ(*fileSize,zit))
{
// Get the modtime and filesize from the registry
rv = GetRegistryDllInfo(aLocation, modificationTime, fileSize);
}
dll = new nsDll(spec, aLocation, modificationTime, fileSize);
dll = new nsDll(spec, aLocation);
if (!dll)
return NS_ERROR_OUT_OF_MEMORY;
}
if (!dll)
return NS_ERROR_OUT_OF_MEMORY;
*aDll = dll;
mDllStore->Put(&key, dll);
return NS_OK;
@ -1210,27 +1040,5 @@ nsNativeComponentLoader::GetFactoryFromNSGetFactory(nsDll *aDll,
nsIServiceManager *aServMgr,
nsIFactory **aFactory)
{
#ifdef OBSOLETE_MODULE_LOADING
nsFactoryProc getFactory =
(nsFactoryProc) aDll->FindSymbol("NSGetFactory");
if (!getFactory)
return NS_ERROR_FACTORY_NOT_LOADED;
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
("nsNativeComponentLoader: %s using OBSOLETE NSGetFactory()\n",
aDll->GetDisplayPath()));
/*
* There was a time when CLSIDToContractID was used to get className
* and contractID, but that day is long past. This code is not long
* for this earth, so we just pass nsnull.
*/
return getFactory(aServMgr, aCID, nsnull /*className */,
nsnull /* contractID */, aFactory);
#else /* !OBSOLETE_MODULE_LOADING */
return NS_ERROR_FACTORY_NOT_LOADED;
#endif /* OBSOLETE_MODULE_LOADING */
}

View File

@ -17,11 +17,9 @@
*/
#include "nsISupports.h"
#include "nsIRegistry.h"
#include "nsIComponentLoader.h"
#include "nsIComponentManager.h"
#include "nsIFile.h"
#include "nsIRegistry.h"
#include "nsDirectoryService.h"
#include "nsCOMPtr.h"
#include "nsHashtable.h"
@ -39,32 +37,18 @@ class nsNativeComponentLoader : public nsIComponentLoader {
nsNativeComponentLoader();
virtual ~nsNativeComponentLoader();
nsresult RegistryNameForLib(const char *aLibName,
char **aRegistryName);
nsresult RegistryNameForSpec(nsIFile *aSpec,
char **aRegistryName);
protected:
nsCOMPtr<nsIRegistry> mRegistry;
nsIComponentManager* mCompMgr; // weak reference -- backpointer
nsObjectHashtable* mDllStore;
NS_IMETHOD RegisterComponentsInDir(PRInt32 when, nsIFile *dir);
nsRegistryKey mXPCOMKey;
nsVoidArray mDeferredComponents;
NS_IMETHOD RegisterComponentsInDir(PRInt32 when, nsIFile *dir);
private:
nsresult CreateDll(nsIFile *aSpec, const char *aLocation,
PRInt64 *modifiedTime, PRInt64 *fileSize, nsDll **aDll);
nsresult CreateDll(nsIFile *aSpec, const char *aLocation, nsDll **aDll);
nsresult SelfRegisterDll(nsDll *dll, const char *registryLocation,
PRBool deferred);
nsresult SelfUnregisterDll(nsDll *dll);
nsresult GetRegistryDllInfo(const char *aLocation, PRInt64 *lastModifiedTime,
PRInt64 *fileSize);
nsresult GetRegistryDllInfo(nsRegistryKey key, PRInt64 *lastModifiedTime,
PRInt64 *fileSize);
nsresult SetRegistryDllInfo(const char *aLocation, PRInt64 *lastModifiedTime,
PRInt64 *fileSize);
nsresult RemoveRegistryDllInfo(const char *aLocation);
nsresult GetFactoryFromModule(nsDll *aDll, const nsCID &aCID,
nsIFactory **aFactory);
/* obsolete! already! */
@ -93,3 +77,4 @@ typedef nsresult (PR_CALLBACK *nsGetModuleProc)(nsIComponentManager *aCompMgr,
#endif /* nsNativeComponentLoader_h__ */

View File

@ -46,6 +46,7 @@
#include "xcDll.h"
#include "nsDebug.h"
#include "nsIComponentManager.h"
#include "nsIComponentLoaderManager.h"
#include "nsIModule.h"
#include "nsILocalFile.h"
#include "nsCOMPtr.h"
@ -70,9 +71,6 @@ nsDll::nsDll(const char *codeDllName, int type)
m_markForUnload(PR_FALSE), m_registryLocation(0)
{
m_modDate = LL_Zero();
m_size = LL_Zero();
if (!codeDllName || !*codeDllName)
{
m_status = DLL_INVALID_PARAM;
@ -92,40 +90,10 @@ nsDll::nsDll(nsIFile *dllSpec, const char *registryLocation)
m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE)
{
m_modDate = LL_Zero();
m_size = LL_Zero();
m_dllSpec = dllSpec;
m_registryLocation = nsCRT::strdup(registryLocation);
Init(dllSpec);
// Populate m_modDate and m_size
if (NS_FAILED(Sync()))
{
m_status = DLL_INVALID_PARAM;
}
}
nsDll::nsDll(nsIFile *dllSpec, const char *registryLocation, PRInt64* modDate, PRInt64* fileSize)
: m_dllName(NULL),
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE)
{
m_modDate = LL_Zero();
m_size = LL_Zero();
m_registryLocation = nsCRT::strdup(registryLocation);
Init(dllSpec);
if (modDate)
m_modDate = *modDate;
else
m_modDate = LL_Zero();
if (fileSize)
m_size = *fileSize;
else
m_size = LL_Zero();
}
nsDll::nsDll(const char *libPersistentDescriptor)
@ -135,42 +103,9 @@ nsDll::nsDll(const char *libPersistentDescriptor)
m_markForUnload(PR_FALSE), m_registryLocation(0)
{
m_modDate = LL_Zero();
m_size = LL_Zero();
Init(libPersistentDescriptor);
// Populate m_modDate and m_size
if (NS_FAILED(Sync()))
{
m_status = DLL_INVALID_PARAM;
}
}
nsDll::nsDll(const char *libPersistentDescriptor, PRInt64* modDate, PRInt64* fileSize)
: m_dllName(NULL),
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
m_persistentDescriptor(NULL), m_nativePath(NULL),
m_markForUnload(PR_FALSE), m_registryLocation(0)
{
m_modDate = LL_Zero();
m_size = LL_Zero();
Init(libPersistentDescriptor);
// and overwrite the modData and fileSize
if (modDate)
m_modDate = *modDate;
else
m_modDate = LL_Zero();
if (fileSize)
m_size = *fileSize;
else
m_size = LL_Zero();
}
void
nsDll::Init(nsIFile *dllSpec)
{
@ -184,9 +119,7 @@ void
nsDll::Init(const char *libPersistentDescriptor)
{
nsresult rv;
m_modDate = LL_Zero();
m_size = LL_Zero();
if (libPersistentDescriptor == NULL)
{
m_status = DLL_INVALID_PARAM;
@ -235,19 +168,6 @@ nsDll::~nsDll(void)
}
nsresult
nsDll::Sync()
{
if (!m_dllSpec)
return NS_ERROR_FAILURE;
// Populate m_modDate and m_size
nsresult rv = m_dllSpec->GetLastModifiedTime(&m_modDate);
if (NS_FAILED(rv)) return rv;
rv = m_dllSpec->GetFileSize(&m_size);
return rv;
}
const char *
nsDll::GetDisplayPath()
@ -277,26 +197,20 @@ nsDll::HasChanged()
if (m_dllName)
return PR_FALSE;
extern nsresult NS_GetComponentLoaderManager(nsIComponentLoaderManager* *result);
nsCOMPtr<nsIComponentLoaderManager> manager;
NS_GetComponentLoaderManager(getter_AddRefs(manager));
if (!manager)
return PR_TRUE;
// If mod date has changed, then dll has changed
PRInt64 currentDate;
nsresult rv = m_dllSpec->GetLastModifiedTime(&currentDate);
if (NS_FAILED(rv) || LL_NE(currentDate, m_modDate))
return PR_TRUE;
// If size has changed, then dll has changed
PRInt64 aSize;
rv = m_dllSpec->GetFileSize(&aSize);
if (NS_FAILED(rv) || LL_NE(aSize, m_size))
return PR_TRUE;
return PR_FALSE;
PRBool changed = PR_TRUE;
manager->HasFileChanged(m_dllSpec, nsnull, currentDate, &changed);
return changed;
}
PRBool nsDll::Load(void)
{
if (m_status != DLL_OK)
@ -314,7 +228,9 @@ PRBool nsDll::Load(void)
#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcnt::SetActivityIsLegal(PR_FALSE);
#endif
m_dllSpec->Load(&m_instance);
nsCOMPtr<nsILocalFile> lf(do_QueryInterface(m_dllSpec));
NS_ASSERTION(lf, "nsIFile here must implement a nsILocalFile");
lf->Load(&m_instance);
#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcnt::SetActivityIsLegal(PR_TRUE);

View File

@ -70,9 +70,7 @@ class nsDll
private:
char *m_dllName; // Stores the dllName to load.
nsCOMPtr<nsILocalFile> m_dllSpec; // Filespec representing the component
PRInt64 m_modDate; // last modified time at creation of this object
PRInt64 m_size; // size of the dynamic library at creation of this object
nsCOMPtr<nsIFile> m_dllSpec; // Filespec representing the component
PRLibrary *m_instance; // Load instance
nsDllStatus m_status; // holds current status
@ -93,16 +91,11 @@ private:
public:
nsDll(nsIFile *dllSpec, const char *registryLocation);
nsDll(nsIFile *dllSpec, const char *registryLocation, PRInt64* modDate, PRInt64* fileSize);
nsDll(const char *persistentDescriptor);
nsDll(const char *persistentDescriptor, PRInt64* modDate, PRInt64* fileSize);
nsDll(const char *dll, int type /* dummy */);
~nsDll(void);
// Sync : Causes update of file information
nsresult Sync(void);
// Status checking on operations completed
nsDllStatus GetStatus(void) { return (m_status); }
@ -130,8 +123,6 @@ public:
const char *GetPersistentDescriptorString(void);
// WARNING: DONT FREE string returned.
const char *GetRegistryLocation(void) { return m_registryLocation; }
void GetLastModifiedTime(PRInt64 *val) { *val = m_modDate; }
void GetSize(PRInt64 *val) { *val = m_size; }
PRLibrary *GetInstance(void) { return (m_instance); }
// NS_RELEASE() is required to be done on objects returned

View File

@ -0,0 +1,115 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsManifestLineReader_h__
#define nsManifestLineReader_h__
#include "nspr.h"
#include "nsDebug.h"
class nsManifestLineReader
{
public:
nsManifestLineReader() : mBase(nsnull) {}
~nsManifestLineReader() {}
void Init(char* base, PRUint32 flen)
{
mBase = mCur = mNext = base;
mLength = 0;
mLimit = base + flen;
}
PRBool NextLine()
{
if(mNext >= mLimit)
return PR_FALSE;
mCur = mNext;
mLength = 0;
while(mNext < mLimit)
{
if(IsEOL(*mNext))
{
*mNext = '\0';
for(++mNext; mNext < mLimit; ++mNext)
if(!IsEOL(*mNext))
break;
return PR_TRUE;
}
++mNext;
++mLength;
}
return PR_FALSE;
}
int ParseLine(char** chunks, int maxChunks)
{
NS_ASSERTION(mCur && maxChunks && chunks, "bad call to ParseLine");
int found = 0;
chunks[found++] = mCur;
if(found < maxChunks)
{
for(char* cur = mCur; *cur; cur++)
{
if(*cur == ',')
{
*cur = 0;
chunks[found++] = cur+1;
if(found == maxChunks)
break;
}
}
}
return found;
}
char* LinePtr() {return mCur;}
PRUint32 LineLength() {return mLength;}
PRBool IsEOL(char c) {return c == '\n' || c == '\r';}
private:
char* mCur;
PRUint32 mLength;
char* mNext;
char* mBase;
char* mLimit;
};
#endif

View File

@ -913,6 +913,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentLoaderManager.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentManager.idl</PATH>
@ -1416,6 +1423,11 @@
<PATH>nsIComponentLoader.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentLoaderManager.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentManagerObsolete.idl</PATH>
@ -2568,6 +2580,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentLoaderManager.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentManager.idl</PATH>
@ -3071,6 +3090,11 @@
<PATH>nsIComponentLoader.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentLoaderManager.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentManager.idl</PATH>
@ -3431,6 +3455,12 @@
<PATH>nsIComponentLoader.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIComponentLoaderManager.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

View File

@ -52,7 +52,11 @@ FORCE_USE_PIC = 1
include $(topsrcdir)/config/rules.mk
# For nsManifestLineReader class.
LOCAL_INCLUDES = -I$(srcdir)/../../../ds
DEFINES += -DEXPORT_XPTI_API -DEXPORT_XPT_API
ifeq ($(OS_ARCH), WINNT)
DEFINES += -DWIN32_LEAN_AND_MEAN
endif

View File

@ -28,6 +28,11 @@ REQUIRES = \
LIBRARY_NAME=xpcomxptinfo_s
# For nsManifestLineReader class.
LINCS = \
-I..\..\..\ds \
$(NULL)
LCFLAGS = -DWIN32_LEAN_AND_MEAN -DEXPORT_XPTI_API -DEXPORT_XPT_API
CPP_OBJS = \

View File

@ -40,9 +40,9 @@
/* Implementation of xptiManifest. */
#include "xptiprivate.h"
#include "nsManifestLineReader.h"
#include "nsString.h"
#define g_MainManifestFilename NS_LITERAL_CSTRING("xpti.dat")
#define g_TempManifestFilename NS_LITERAL_CSTRING("xptitemp.dat")
@ -344,87 +344,8 @@ ReadManifestIntoMemory(xptiInterfaceInfoManager* aMgr,
return whole;
}
/***************************************************/
class ManifestLineReader
{
public:
ManifestLineReader() : mBase(nsnull) {}
~ManifestLineReader() {}
void Init(char* base, PRUint32 flen)
{mBase = mCur = mNext = base;
mLength = 0;
mLimit = base + flen;}
PRBool NextLine();
char* LinePtr() {return mCur;}
PRUint32 LineLength() {return mLength;}
int ParseLine(char** chunks, int maxChunks);
private:
char* mCur;
PRUint32 mLength;
char* mNext;
char* mBase;
char* mLimit;
};
inline static PRBool is_eol(char c) {return c == '\n' || c == '\r';}
PRBool
ManifestLineReader::NextLine()
{
if(mNext >= mLimit)
return PR_FALSE;
mCur = mNext;
mLength = 0;
while(mNext < mLimit)
{
if(is_eol(*mNext))
{
*mNext = '\0';
for(++mNext; mNext < mLimit; ++mNext)
if(!is_eol(*mNext))
break;
return PR_TRUE;
}
++mNext;
++mLength;
}
return PR_FALSE;
}
int
ManifestLineReader::ParseLine(char** chunks, int maxChunks)
{
NS_ASSERTION(mCur && maxChunks && chunks, "bad call to ParseLine");
int found = 0;
chunks[found++] = mCur;
if(found < maxChunks)
{
for(char* cur = mCur; *cur; cur++)
{
if(*cur == ',')
{
*cur = 0;
chunks[found++] = cur+1;
if(found == maxChunks)
break;
}
}
}
return found;
}
/***************************************************/
static
PRBool ReadSectionHeader(ManifestLineReader& reader,
PRBool ReadSectionHeader(nsManifestLineReader& reader,
const char *token, int minCount, int* count)
{
while(1)
@ -464,7 +385,7 @@ PRBool xptiManifest::Read(xptiInterfaceInfoManager* aMgr,
char* whole = nsnull;
PRBool succeeded = PR_FALSE;
PRUint32 flen;
ManifestLineReader reader;
nsManifestLineReader reader;
xptiHashEntry* hashEntry;
int headerCount = 0;
int dirCount = 0;