NS_IMETHODIMP DelayedPathSetter::Observe(nsISupports*, const char * aTopic, const char16_t*) { if (gPaths == nullptr) { // Initialization of gPaths has not taken place, something is wrong, // don't make things worse. return NS_OK; } nsresult rv = GetPathToSpecialDir(NS_APP_USER_PROFILE_50_DIR, gPaths->profileDir); if (NS_FAILED(rv)) { return rv; } rv = GetPathToSpecialDir(NS_APP_USER_PROFILE_LOCAL_50_DIR, gPaths->localProfileDir); if (NS_FAILED(rv)) { return rv; } return NS_OK; }
/** * Perform the part of initialization that can only be * executed on the main thread. */ nsresult InitOSFileConstants() { MOZ_ASSERT(NS_IsMainThread()); if (gInitialized) { return NS_OK; } gInitialized = true; nsAutoPtr<Paths> paths(new Paths); // Initialize paths->libDir nsCOMPtr<nsIFile> file; nsresult rv = NS_GetSpecialDirectory("XpcomLib", getter_AddRefs(file)); if (NS_FAILED(rv)) { return rv; } nsCOMPtr<nsIFile> libDir; rv = file->GetParent(getter_AddRefs(libDir)); if (NS_FAILED(rv)) { return rv; } rv = libDir->GetPath(paths->libDir); if (NS_FAILED(rv)) { return rv; } // For other directories, ignore errors (they may be undefined on // some platforms or in non-Firefox embeddings of Gecko). GetPathToSpecialDir(NS_OS_TEMP_DIR, paths->tmpDir); GetPathToSpecialDir(NS_APP_USER_PROFILE_50_DIR, paths->profileDir); gPaths = paths.forget(); return NS_OK; }
/** * Perform the part of initialization that can only be * executed on the main thread. */ nsresult InitOSFileConstants() { MOZ_ASSERT(NS_IsMainThread()); if (gInitialized) { return NS_OK; } gInitialized = true; nsAutoPtr<Paths> paths(new Paths); // Initialize paths->libDir nsCOMPtr<nsIFile> file; nsresult rv = NS_GetSpecialDirectory(NS_XPCOM_LIBRARY_FILE, getter_AddRefs(file)); if (NS_FAILED(rv)) { return rv; } nsCOMPtr<nsIFile> libDir; rv = file->GetParent(getter_AddRefs(libDir)); if (NS_FAILED(rv)) { return rv; } rv = libDir->GetPath(paths->libDir); if (NS_FAILED(rv)) { return rv; } // Setup profileDir and localProfileDir immediately if possible (we // assume that NS_APP_USER_PROFILE_50_DIR and // NS_APP_USER_PROFILE_LOCAL_50_DIR are set simultaneously) rv = GetPathToSpecialDir(NS_APP_USER_PROFILE_50_DIR, paths->profileDir); if (NS_SUCCEEDED(rv)) { rv = GetPathToSpecialDir(NS_APP_USER_PROFILE_LOCAL_50_DIR, paths->localProfileDir); } // Otherwise, delay setup of profileDir/localProfileDir until they // become available. if (NS_FAILED(rv)) { nsCOMPtr<nsIObserverService> obsService = do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) { return rv; } RefPtr<DelayedPathSetter> pathSetter = new DelayedPathSetter(); rv = obsService->AddObserver(pathSetter, "profile-do-change", false); if (NS_FAILED(rv)) { return rv; } } // For other directories, ignore errors (they may be undefined on // some platforms or in non-Firefox embeddings of Gecko). GetPathToSpecialDir(NS_OS_TEMP_DIR, paths->tmpDir); GetPathToSpecialDir(NS_OS_HOME_DIR, paths->homeDir); GetPathToSpecialDir(NS_OS_DESKTOP_DIR, paths->desktopDir); GetPathToSpecialDir(XRE_USER_APP_DATA_DIR, paths->userApplicationDataDir); #if defined(XP_WIN) GetPathToSpecialDir(NS_WIN_APPDATA_DIR, paths->winAppDataDir); GetPathToSpecialDir(NS_WIN_PROGRAMS_DIR, paths->winStartMenuProgsDir); #endif // defined(XP_WIN) #if defined(XP_MACOSX) GetPathToSpecialDir(NS_MAC_USER_LIB_DIR, paths->macUserLibDir); GetPathToSpecialDir(NS_OSX_LOCAL_APPLICATIONS_DIR, paths->macLocalApplicationsDir); GetPathToSpecialDir(NS_MAC_TRASH_DIR, paths->macTrashDir); #endif // defined(XP_MACOSX) gPaths = paths.forget(); // Get the umask from the system-info service. // The property will always be present, but it will be zero on // non-Unix systems. nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1"); MOZ_ASSERT(infoService, "Could not access the system information service"); rv = infoService->GetPropertyAsUint32(NS_LITERAL_STRING("umask"), &gUserUmask); if (NS_FAILED(rv)) { return rv; } return NS_OK; }