Fix review comments from Mossop, bug 570488 comment 5.

This commit is contained in:
Benjamin Smedberg 2010-06-11 13:35:25 -04:00
Родитель 703663d5db
Коммит cb0d5b8170
2 изменённых файлов: 30 добавлений и 67 удалений

Просмотреть файл

@ -63,8 +63,7 @@ static int gCallCount = 0;
xptiInterfaceInfoManager*
xptiInterfaceInfoManager::GetSingleton()
{
if(!gInterfaceInfoManager)
{
if (!gInterfaceInfoManager) {
NS_TIME_FUNCTION;
gInterfaceInfoManager = new xptiInterfaceInfoManager();
@ -93,13 +92,13 @@ xptiInterfaceInfoManager::~xptiInterfaceInfoManager()
// We only do this on shutdown of the service.
mWorkingSet.InvalidateInterfaceInfos();
if(mResolveLock)
if (mResolveLock)
PR_DestroyLock(mResolveLock);
if(mAutoRegLock)
if (mAutoRegLock)
PR_DestroyLock(mAutoRegLock);
if(mInfoMonitor)
if (mInfoMonitor)
nsAutoMonitor::DestroyMonitor(mInfoMonitor);
if(mAdditionalManagersLock)
if (mAdditionalManagersLock)
PR_DestroyLock(mAdditionalManagersLock);
gInterfaceInfoManager = nsnull;
@ -108,33 +107,8 @@ xptiInterfaceInfoManager::~xptiInterfaceInfoManager()
#endif
}
// this is safe to call during InitXPCOM
static already_AddRefed<nsIFile>
GetLocationFromDirectoryService(const char* prop, const char *const * append)
{
nsCOMPtr<nsIProperties> directoryService;
nsDirectoryService::Create(nsnull,
NS_GET_IID(nsIProperties),
getter_AddRefs(directoryService));
if (!directoryService)
return NULL;
nsCOMPtr<nsIFile> file;
nsresult rv = directoryService->Get(prop,
NS_GET_IID(nsIFile),
getter_AddRefs(file));
if (NS_FAILED(rv))
return NULL;
while (append && *append) {
file->AppendNative(nsDependentCString(*append));
++append;
}
return file.forget();
}
namespace {
struct AutoCloseFD
{
AutoCloseFD()
@ -187,7 +161,7 @@ xptiInterfaceInfoManager::ReadXPTFile(nsILocalFile* aFile)
PRInt32(fileInfo.size));
XPTCursor cursor;
if(!XPT_MakeCursor(state, XPT_HEADER, 0, &cursor)) {
if (!XPT_MakeCursor(state, XPT_HEADER, 0, &cursor)) {
XPT_DestroyXDRState(state);
return NULL;
}
@ -213,8 +187,6 @@ xptiInterfaceInfoManager::ReadXPTFileFromInputStream(nsIInputStream *stream)
if (!whole)
return nsnull;
// all exits from on here should be via 'goto out'
for (PRUint32 totalRead = 0; totalRead < flen; ) {
PRUint32 avail;
PRUint32 read;
@ -236,15 +208,13 @@ xptiInterfaceInfoManager::ReadXPTFileFromInputStream(nsIInputStream *stream)
return NULL;
XPTCursor cursor;
if(!XPT_MakeCursor(state, XPT_HEADER, 0, &cursor))
{
if (!XPT_MakeCursor(state, XPT_HEADER, 0, &cursor)) {
XPT_DestroyXDRState(state);
return NULL;
}
XPTHeader *header = nsnull;
if (!XPT_DoHeader(gXPTIStructArena, &cursor, &header))
{
if (!XPT_DoHeader(gXPTIStructArena, &cursor, &header)) {
XPT_DestroyXDRState(state);
return NULL;
}
@ -314,8 +284,7 @@ xptiInterfaceInfoManager::VerifyAndAddEntryIfNew(XPTInterfaceDirectoryEntry* ifa
return;
xptiInterfaceEntry* entry = mWorkingSet.mIIDTable.Get(iface->iid);
if (entry)
{
if (entry) {
// XXX validate this info to find possible inconsistencies
LOG_AUTOREG((" ignoring repeated interface: %s\n", iface->name));
return;
@ -327,7 +296,7 @@ xptiInterfaceInfoManager::VerifyAndAddEntryIfNew(XPTInterfaceDirectoryEntry* ifa
iface->iid,
iface->interface_descriptor,
typelib);
if(!entry)
if (!entry)
return;
//XXX We should SetHeader too as part of the validation, no?
@ -348,14 +317,13 @@ EntryToInfo(xptiInterfaceEntry* entry, nsIInterfaceInfo **_retval)
xptiInterfaceInfo* info;
nsresult rv;
if(!entry)
{
if (!entry) {
*_retval = nsnull;
return NS_ERROR_FAILURE;
}
rv = entry->GetInterfaceInfo(&info);
if(NS_FAILED(rv))
if (NS_FAILED(rv))
return rv;
// Transfer the AddRef done by GetInterfaceInfo.
@ -397,8 +365,7 @@ NS_IMETHODIMP xptiInterfaceInfoManager::GetIIDForName(const char *name, nsIID *
xptiInterfaceEntry* entry = mWorkingSet.mNameTable.Get(name);
if(!entry)
{
if (!entry) {
*_retval = nsnull;
return NS_ERROR_FAILURE;
}
@ -413,8 +380,7 @@ NS_IMETHODIMP xptiInterfaceInfoManager::GetNameForIID(const nsIID * iid, char **
NS_ASSERTION(_retval, "bad param");
xptiInterfaceEntry* entry = mWorkingSet.mIIDTable.Get(*iid);
if(!entry)
{
if (!entry) {
*_retval = nsnull;
return NS_ERROR_FAILURE;
}
@ -428,7 +394,7 @@ xpti_ArrayAppender(const char* name, xptiInterfaceEntry* entry, void* arg)
nsISupportsArray* array = (nsISupportsArray*) arg;
nsCOMPtr<nsIInterfaceInfo> ii;
if(NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii))))
if (NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii))))
array->AppendElement(ii);
return PL_DHASH_NEXT;
}
@ -443,7 +409,7 @@ NS_IMETHODIMP xptiInterfaceInfoManager::EnumerateInterfaces(nsIEnumerator **_ret
nsCOMPtr<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array));
if(!array)
if (!array)
return NS_ERROR_UNEXPECTED;
mWorkingSet.mNameTable.EnumerateRead(xpti_ArrayAppender, array);
@ -464,11 +430,11 @@ xpti_ArrayPrefixAppender(const char* keyname, xptiInterfaceEntry* entry, void* a
ArrayAndPrefix* args = (ArrayAndPrefix*) arg;
const char* name = entry->GetTheName();
if(name != PL_strnstr(name, args->prefix, args->length))
if (name != PL_strnstr(name, args->prefix, args->length))
return PL_DHASH_NEXT;
nsCOMPtr<nsIInterfaceInfo> ii;
if(NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii))))
if (NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii))))
args->array->AppendElement(ii);
return PL_DHASH_NEXT;
}
@ -478,7 +444,7 @@ NS_IMETHODIMP xptiInterfaceInfoManager::EnumerateInterfacesWhoseNamesStartWith(c
{
nsCOMPtr<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array));
if(!array)
if (!array)
return NS_ERROR_UNEXPECTED;
ArrayAndPrefix args = {array, prefix, PL_strlen(prefix)};
@ -506,9 +472,9 @@ NS_IMETHODIMP xptiInterfaceInfoManager::AddAdditionalManager(nsIInterfaceInfoMan
static_cast<nsISupports*>(manager);
{ // scoped lock...
nsAutoLock lock(mAdditionalManagersLock);
if(mAdditionalManagers.IndexOf(ptrToAdd) != -1)
if (mAdditionalManagers.IndexOf(ptrToAdd) != -1)
return NS_ERROR_FAILURE;
if(!mAdditionalManagers.AppendObject(ptrToAdd))
if (!mAdditionalManagers.AppendObject(ptrToAdd))
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
@ -523,7 +489,7 @@ NS_IMETHODIMP xptiInterfaceInfoManager::RemoveAdditionalManager(nsIInterfaceInfo
static_cast<nsISupports*>(manager);
{ // scoped lock...
nsAutoLock lock(mAdditionalManagersLock);
if(!mAdditionalManagers.RemoveObject(ptrToRemove))
if (!mAdditionalManagers.RemoveObject(ptrToRemove))
return NS_ERROR_FAILURE;
}
return NS_OK;
@ -543,23 +509,19 @@ NS_IMETHODIMP xptiInterfaceInfoManager::EnumerateAdditionalManagers(nsISimpleEnu
nsCOMArray<nsISupports> managerArray(mAdditionalManagers);
/* Resolve all the weak references in the array. */
for(PRInt32 i = managerArray.Count(); i--; )
{
for(PRInt32 i = managerArray.Count(); i--; ) {
nsISupports *raw = managerArray.ObjectAt(i);
if(!raw)
if (!raw)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIWeakReference> weakRef = do_QueryInterface(raw);
if(weakRef)
{
if (weakRef) {
nsCOMPtr<nsIInterfaceInfoManager> manager =
do_QueryReferent(weakRef);
if(manager)
{
if(!managerArray.ReplaceObjectAt(manager, i))
if (manager) {
if (!managerArray.ReplaceObjectAt(manager, i))
return NS_ERROR_FAILURE;
}
else
{
else {
// The manager is no more. Remove the element.
mAdditionalManagers.RemoveObjectAt(i);
managerArray.RemoveObjectAt(i);

Просмотреть файл

@ -77,6 +77,7 @@ xptiTypelibGuts::GetEntryAt(PRUint16 i)
r = set->mNameTable.Get(iface->name);
else
r = set->mIIDTable.Get(iface->iid);
if (r)
SetEntryAt(i, r);