bug #14889 Lazy loading wallet dll r=morse,gagan sr=jband a=asa

This commit is contained in:
dp%netscape.com 2001-08-28 22:05:30 +00:00
parent 6835cdd75e
commit 786ae7cdf5
2 changed files with 80 additions and 3 deletions

View File

@ -423,5 +423,18 @@ NS_ShutdownXPCOM(nsIServiceManager* servMgr);
#define NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID "xpcom-autoregistration"
////////////////////////////////////////////////////////////////////////////////
// Convenience functions
//
// CreateServicesFromCategory()
//
// Given a category, this convenience functions enumerates the category and
// creates a service of every CID or ContractID registered under the category.
// If observerTopic is non null and the service implements nsIObserver,
// this will attempt to notify the observer with this observerTopic string
// and origin as parameter.
//
extern NS_COM nsresult
NS_CreateServicesFromCategory(const char* category, nsISupports *origin, const PRUnichar *observerTopic);
#endif /* nsIServiceManager_h___ */

View File

@ -29,6 +29,8 @@
#include "prcmon.h"
#include "prthread.h" /* XXX: only used for the NSPR initialization hack (rick) */
#include "nsAutoLock.h"
#include "nsISupportsPrimitives.h"
#include "nsIObserver.h"
nsIServiceManager* gServiceManager = NULL;
PRBool gShuttingDown = PR_FALSE;
@ -303,9 +305,7 @@ nsServiceManagerImpl::GetService(const nsCID& aClass, const nsIID& aIID,
// occurs in the list
if (gShuttingDown) {
// When processing shutdown, dont process new GetService() requests
#ifdef DEBUG_dp
NS_WARN_IF_FALSE(PR_FALSE, "Creating new service on shutdown. Denied.");
#endif /* DEBUG_dp */
NS_WARNING("Creating new service on shutdown. Denied.");
return NS_ERROR_UNEXPECTED;
}
@ -639,3 +639,67 @@ nsServiceManager::UnregisterService(const char* aContractID)
}
////////////////////////////////////////////////////////////////////////////////
/*
* CreateServicesFromCategory()
*
* Given a category, this convenience functions enumerates the category and
* creates a service of every CID or ContractID registered under the category.
* If observerTopic is non null and the service implements nsIObserver,
* this will attempt to notify the observer with the origin, observerTopic string
* as parameter.
*/
nsresult
NS_CreateServicesFromCategory(const char *category,
nsISupports *origin,
const PRUnichar *observerTopic)
{
nsresult rv = NS_OK;
int nFailed = 0;
nsCOMPtr<nsICategoryManager> categoryManager =
do_GetService("@mozilla.org/categorymanager;1", &rv);
if (!categoryManager) return rv;
nsCOMPtr<nsISimpleEnumerator> enumerator;
rv = categoryManager->EnumerateCategory(category,
getter_AddRefs(enumerator));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupports> entry;
while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) {
// From here on just skip any error we get.
nsCOMPtr<nsISupportsString> catEntry = do_QueryInterface(entry, &rv);
if (NS_FAILED(rv)) {
nFailed++;
continue;
}
nsXPIDLCString entryString;
rv = catEntry->GetData(getter_Copies(entryString));
if (NS_FAILED(rv)) {
nFailed++;
continue;
}
nsXPIDLCString contractID;
rv = categoryManager->GetCategoryEntry(category,(const char *)entryString, getter_Copies(contractID));
if (NS_FAILED(rv)) {
nFailed++;
continue;
}
nsCOMPtr<nsISupports> instance = do_GetService(contractID, &rv);
if (NS_FAILED(rv)) {
nFailed++;
continue;
}
if (observerTopic) {
// try an observer, if it implements it.
nsCOMPtr<nsIObserver> observer = do_QueryInterface(instance, &rv);
if (NS_SUCCEEDED(rv) && observer)
observer->Observe(origin, observerTopic, NS_LITERAL_STRING("").get());
}
}
return (nFailed ? NS_ERROR_FAILURE : NS_OK);
}