PRBool exists; rv = cacheDirectory->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) cacheDirectory->Create(nsIFile::DIRECTORY_TYPE, 0777);
rv = ensureCacheDirectory(cacheDirectory); if (NS_FAILED(rv)) return rv;
static nsresult installPrefListeners(nsDiskCacheDevice* device){	nsresult rv;	NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);	if (NS_FAILED(rv))		return rv;	rv = prefs->RegisterCallback(CACHE_DISK_CAPACITY, cacheCapacityChanged, device);	if (NS_FAILED(rv))		return rv;    PRInt32 cacheCapacity;    rv = prefs->GetIntPref(CACHE_DISK_CAPACITY, &cacheCapacity);    if (NS_FAILED(rv)) {#if DEBUG        const PRInt32 kTenMegabytes = 10 * 1024 * 1024;        rv = prefs->SetIntPref(CACHE_DISK_CAPACITY, kTenMegabytes);#else		return rv;#endif    } else {        device->setCacheCapacity(cacheCapacity);    }	rv = prefs->RegisterCallback(CACHE_DIR_PREF, cacheDirectoryChanged, device);	if (NS_FAILED(rv))		return rv;	nsCOMPtr<nsILocalFile> cacheDirectory;    rv = prefs->GetFileXPref(CACHE_DIR_PREF, getter_AddRefs(cacheDirectory));    if (NS_FAILED(rv)) {#if DEBUG        // XXX use current process directory during development only.        nsCOMPtr<nsIFile> currentProcessDir;        rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,                                     getter_AddRefs(currentProcessDir));    	if (NS_FAILED(rv))    		return rv;        cacheDirectory = do_QueryInterface(currentProcessDir, &rv);    	if (NS_FAILED(rv))    		return rv;        rv = cacheDirectory->Append("Cache");    	if (NS_FAILED(rv))    		return rv;        // make sure the Cache directory exists.        PRBool exists;        rv = cacheDirectory->Exists(&exists);        if (NS_SUCCEEDED(rv) && !exists)            cacheDirectory->Create(nsIFile::DIRECTORY_TYPE, 0777);        rv = prefs->SetFileXPref(CACHE_DIR_PREF, cacheDirectory);    	if (NS_FAILED(rv))    		return rv;#else        return rv;#endif    } else {        // be a good citizen in the current Cache directory.        rv = cacheDirectory->Append("NewCache");        if (NS_FAILED(rv))            return rv;            // cause the preference to be set up initially.        device->setCacheDirectory(cacheDirectory);    }        return NS_OK;}