/* static */ nsresult AppProtocolHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) { // Instantiate the service here since that intializes gJarHandler, which we // use indirectly (via our new JarChannel) in NewChannel. nsCOMPtr<nsIProtocolHandler> jarInitializer( do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "jar")); AppProtocolHandler* ph = new AppProtocolHandler(); if (ph == nullptr) { return NS_ERROR_OUT_OF_MEMORY; } NS_ADDREF(ph); nsresult rv = ph->QueryInterface(aIID, aResult); NS_RELEASE(ph); return rv; }
nsresult StartupCache::Init() { // workaround for bug 653936 nsCOMPtr<nsIProtocolHandler> jarInitializer(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "jar")); nsresult rv; mTable.Init(); #ifdef DEBUG mWriteObjectMap.Init(); #endif // This allows to override the startup cache filename // which is useful from xpcshell, when there is no ProfLDS directory to keep cache in. char *env = PR_GetEnv("MOZ_STARTUP_CACHE"); if (env) { rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(env), false, getter_AddRefs(mFile)); } else { nsCOMPtr<nsIFile> file; rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(file)); if (NS_FAILED(rv)) { // return silently, this will fail in mochitests's xpcshell process. return rv; } nsCOMPtr<nsIFile> profDir; NS_GetSpecialDirectory("ProfDS", getter_AddRefs(profDir)); if (profDir) { bool same; if (NS_SUCCEEDED(profDir->Equals(file, &same)) && !same) { // We no longer store the startup cache in the main profile // directory, so we should cleanup the old one. if (NS_SUCCEEDED( profDir->AppendNative(NS_LITERAL_CSTRING("startupCache")))) { profDir->Remove(true); } } } rv = file->AppendNative(NS_LITERAL_CSTRING("startupCache")); NS_ENSURE_SUCCESS(rv, rv); // Try to create the directory if it's not there yet rv = file->Create(nsIFile::DIRECTORY_TYPE, 0777); if (NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv; rv = file->AppendNative(NS_LITERAL_CSTRING(sStartupCacheName)); NS_ENSURE_SUCCESS(rv, rv); mFile = do_QueryInterface(file); } NS_ENSURE_TRUE(mFile, NS_ERROR_UNEXPECTED); mObserverService = do_GetService("@mozilla.org/observer-service;1"); if (!mObserverService) { NS_WARNING("Could not get observerService."); return NS_ERROR_UNEXPECTED; } mListener = new StartupCacheListener(); rv = mObserverService->AddObserver(mListener, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); NS_ENSURE_SUCCESS(rv, rv); rv = mObserverService->AddObserver(mListener, "startupcache-invalidate", false); NS_ENSURE_SUCCESS(rv, rv); rv = LoadArchive(RECORD_AGE); // Sometimes we don't have a cache yet, that's ok. // If it's corrupted, just remove it and start over. if (gIgnoreDiskCache || (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)) { NS_WARNING("Failed to load startupcache file correctly, removing!"); InvalidateCache(); } mMappingReporter = new StartupCacheMappingReporter(); mDataReporter = new StartupCacheDataReporter(); NS_RegisterMemoryReporter(mMappingReporter); NS_RegisterMemoryReporter(mDataReporter); return NS_OK; }