From adb9a5e72234ca941df10e579cdaf8f1e2044dbc Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Thu, 15 Jun 2023 14:38:03 +0000 Subject: [PATCH] Bug 1838542 - Eliminate the most common warning spam from nsXREDirProvider::GetFile(). r=xpcom-reviewers,jstutte Currently, this function warns any time it fails to return something. However, this warning happens extremely frequently in two cases: when the property is unknown or when somebody tries to get a profile directory in a child process. This patch eliminates those. It also consolidates some profile cases. Hopefully an additional 2 strcmps on common cases won't matter. Differential Revision: https://phabricator.services.mozilla.com/D181007 --- toolkit/xre/nsXREDirProvider.cpp | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp index ea1e5a80613e..41d2353fe843 100644 --- a/toolkit/xre/nsXREDirProvider.cpp +++ b/toolkit/xre/nsXREDirProvider.cpp @@ -327,13 +327,29 @@ nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent, nsCOMPtr file; - if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR)) { + if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR) || + !strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) { if (mProfileLocalDir) { rv = mProfileLocalDir->Clone(getter_AddRefs(file)); + } else { + // Profile directories are only set up in the parent process. + // We don't expect every caller to check if they are in the right process, + // so fail immediately to avoid warning spam. + NS_WARNING_ASSERTION(!XRE_IsParentProcess(), + "tried to get profile in parent too early"); + return NS_ERROR_FAILURE; } - } else if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR)) { + } else if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR) || + !strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP)) { if (mProfileDir) { rv = mProfileDir->Clone(getter_AddRefs(file)); + } else { + // Profile directories are only set up in the parent process. + // We don't expect every caller to check if they are in the right process, + // so fail immediately to avoid warning spam. + NS_WARNING_ASSERTION(!XRE_IsParentProcess(), + "tried to get profile in parent too early"); + return NS_ERROR_FAILURE; } } else if (!strcmp(aProperty, NS_GRE_DIR)) { // On Android, internal files are inside the APK, a zip file, so this @@ -388,14 +404,6 @@ nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent, rv = GetUserProfilesLocalDir(getter_AddRefs(file)); } else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE)) { rv = XRE_GetBinaryPath(getter_AddRefs(file)); - } else if (!strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP)) { - if (mProfileDir) { - rv = mProfileDir->Clone(getter_AddRefs(file)); - } - } else if (!strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) { - if (mProfileLocalDir) { - rv = mProfileLocalDir->Clone(getter_AddRefs(file)); - } } #if defined(XP_UNIX) || defined(XP_MACOSX) else if (!strcmp(aProperty, XRE_SYS_LOCAL_EXTENSION_PARENT_DIR)) { @@ -470,6 +478,11 @@ nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent, rv = file->AppendNative(nsLiteralCString(PREF_OVERRIDE_DIRNAME)); NS_ENSURE_SUCCESS(rv, rv); rv = EnsureDirectoryExists(file); + } else { + // We don't know anything about this property. Fail without warning, because + // otherwise we'll get too much warning spam due to + // nsDirectoryService::Get() trying everything it gets with every provider. + return NS_ERROR_FAILURE; } NS_ENSURE_SUCCESS(rv, rv);