From d9fb7a4c74ee74ca69fae8cfe00120a746efa600 Mon Sep 17 00:00:00 2001 From: Tom Ritter Date: Wed, 20 Apr 2022 15:44:37 +0000 Subject: [PATCH] Bug 1752332: Rename ShouldSyncPreference to ShouldSanitizePreference r=KrisWright This simplifies the number of negations needed, and makes things easy to understand. I think anyway; I know that without renaming it I made several annoying-to-diagnose negation errors... Depends on D141411 Differential Revision: https://phabricator.services.mozilla.com/D141412 --- dom/ipc/ContentParent.cpp | 6 +++--- dom/media/ipc/RDDProcessHost.cpp | 2 +- dom/media/ipc/RDDProcessManager.cpp | 3 +-- gfx/ipc/GPUProcessHost.cpp | 2 +- gfx/ipc/GPUProcessManager.cpp | 3 +-- gfx/vr/ipc/VRProcessManager.cpp | 3 +-- gfx/vr/ipc/VRProcessParent.cpp | 2 +- ipc/glue/ProcessUtils.h | 4 ++-- ipc/glue/ProcessUtils_common.cpp | 6 +++--- ipc/glue/UtilityProcessHost.cpp | 2 +- ipc/glue/UtilityProcessManager.cpp | 2 +- ipc/ipdl/test/gtest/IPDLUnitTest.cpp | 2 +- modules/libpref/Preferences.cpp | 13 +++++++------ modules/libpref/Preferences.h | 2 +- modules/libpref/test/gtest/Basics.cpp | 8 +++++--- netwerk/ipc/SocketProcessHost.cpp | 2 +- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 3f7c1eb5efe7..05010c87fb10 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2510,7 +2510,7 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) { // Instantiate the pref serializer. It will be cleaned up in // `LaunchSubprocessReject`/`LaunchSubprocessResolve`. mPrefSerializer = MakeUnique( - ShouldSyncPreference); + ShouldSanitizePreference); if (!mPrefSerializer->SerializeToSharedMemory()) { NS_WARNING("SharedPreferenceSerializer::SerializeToSharedMemory failed"); MarkAsDead(); @@ -3633,8 +3633,8 @@ ContentParent::Observe(nsISupports* aSubject, const char* aTopic, NS_LossyConvertUTF16toASCII strData(aData); // A pref changed. If it is useful to do so, inform child processes. - if (!ShouldSyncPreference(strData.Data(), - /* will be fixed later */ false)) { + if (ShouldSanitizePreference(strData.Data(), + /* will be fixed later */ false)) { return NS_OK; } diff --git a/dom/media/ipc/RDDProcessHost.cpp b/dom/media/ipc/RDDProcessHost.cpp index 750e154b8d7d..c42bee622d61 100644 --- a/dom/media/ipc/RDDProcessHost.cpp +++ b/dom/media/ipc/RDDProcessHost.cpp @@ -47,7 +47,7 @@ bool RDDProcessHost::Launch(StringVector aExtraOpts) { MOZ_ASSERT(!mRDDChild); mPrefSerializer = - MakeUnique(ShouldSyncPreference); + MakeUnique(ShouldSanitizePreference); if (!mPrefSerializer->SerializeToSharedMemory()) { return false; } diff --git a/dom/media/ipc/RDDProcessManager.cpp b/dom/media/ipc/RDDProcessManager.cpp index 066b60c85af2..b3ae4fe49274 100644 --- a/dom/media/ipc/RDDProcessManager.cpp +++ b/dom/media/ipc/RDDProcessManager.cpp @@ -97,10 +97,9 @@ void RDDProcessManager::OnPreferenceChange(const char16_t* aData) { NS_LossyConvertUTF16toASCII strData(aData); // A pref changed. If it is useful to do so, inform child processes. - if (!ShouldSyncPreference(strData.Data(), false)) { + if (ShouldSanitizePreference(strData.Data(), false)) { return; } - mozilla::dom::Pref pref(strData, /* isLocked */ false, /* isSanitized */ false, Nothing(), Nothing()); Preferences::GetPreference(&pref); diff --git a/gfx/ipc/GPUProcessHost.cpp b/gfx/ipc/GPUProcessHost.cpp index 92949b60d3b8..6770b594478c 100644 --- a/gfx/ipc/GPUProcessHost.cpp +++ b/gfx/ipc/GPUProcessHost.cpp @@ -43,7 +43,7 @@ bool GPUProcessHost::Launch(StringVector aExtraOpts) { MOZ_ASSERT(!gfxPlatform::IsHeadless()); mPrefSerializer = - MakeUnique(ShouldSyncPreference); + MakeUnique(ShouldSanitizePreference); if (!mPrefSerializer->SerializeToSharedMemory()) { return false; } diff --git a/gfx/ipc/GPUProcessManager.cpp b/gfx/ipc/GPUProcessManager.cpp index c77ec9fa7c6a..2febb755f93b 100644 --- a/gfx/ipc/GPUProcessManager.cpp +++ b/gfx/ipc/GPUProcessManager.cpp @@ -164,10 +164,9 @@ void GPUProcessManager::OnPreferenceChange(const char16_t* aData) { NS_LossyConvertUTF16toASCII strData(aData); // A pref changed. If it is useful to do so, inform child processes. - if (!ShouldSyncPreference(strData.Data(), false)) { + if (ShouldSanitizePreference(strData.Data(), false)) { return; } - mozilla::dom::Pref pref(strData, /* isLocked */ false, /* isSanitized */ false, Nothing(), Nothing()); Preferences::GetPreference(&pref); diff --git a/gfx/vr/ipc/VRProcessManager.cpp b/gfx/vr/ipc/VRProcessManager.cpp index a6dca8db3064..44d6304bd80b 100644 --- a/gfx/vr/ipc/VRProcessManager.cpp +++ b/gfx/vr/ipc/VRProcessManager.cpp @@ -217,10 +217,9 @@ void VRProcessManager::OnPreferenceChange(const char16_t* aData) { NS_LossyConvertUTF16toASCII strData(aData); // A pref changed. If it is useful to do so, inform child processes. - if (!ShouldSyncPreference(strData.Data(), false)) { + if (ShouldSanitizePreference(strData.Data(), false)) { return; } - mozilla::dom::Pref pref(strData, /* isLocked */ false, /* isSanitized */ false, Nothing(), Nothing()); Preferences::GetPreference(&pref); diff --git a/gfx/vr/ipc/VRProcessParent.cpp b/gfx/vr/ipc/VRProcessParent.cpp index 63b91e1868b3..dfb06e05f395 100644 --- a/gfx/vr/ipc/VRProcessParent.cpp +++ b/gfx/vr/ipc/VRProcessParent.cpp @@ -56,7 +56,7 @@ bool VRProcessParent::Launch() { ProcessChild::AddPlatformBuildID(extraArgs); mPrefSerializer = - MakeUnique(ShouldSyncPreference); + MakeUnique(ShouldSanitizePreference); if (!mPrefSerializer->SerializeToSharedMemory()) { return false; } diff --git a/ipc/glue/ProcessUtils.h b/ipc/glue/ProcessUtils.h index 3f28ffb89235..6851693d40b4 100644 --- a/ipc/glue/ProcessUtils.h +++ b/ipc/glue/ProcessUtils.h @@ -26,7 +26,7 @@ void SetThisProcessName(const char* aName); class SharedPreferenceSerializer final { public: explicit SharedPreferenceSerializer( - std::function&& aShouldSerializeFn); + std::function&& aShouldSanitizeFn); SharedPreferenceSerializer(SharedPreferenceSerializer&& aOther); ~SharedPreferenceSerializer(); @@ -48,7 +48,7 @@ class SharedPreferenceSerializer final { size_t mPrefsLength; UniqueFileHandle mPrefMapHandle; UniqueFileHandle mPrefsHandle; - std::function mShouldSerializeFn; + std::function mShouldSanitizeFn; }; class SharedPreferenceDeserializer final { diff --git a/ipc/glue/ProcessUtils_common.cpp b/ipc/glue/ProcessUtils_common.cpp index fd3e066b6f7f..7d5e8cc23850 100644 --- a/ipc/glue/ProcessUtils_common.cpp +++ b/ipc/glue/ProcessUtils_common.cpp @@ -18,8 +18,8 @@ namespace mozilla { namespace ipc { SharedPreferenceSerializer::SharedPreferenceSerializer( - std::function&& aShouldSerializeFn) - : mPrefMapSize(0), mPrefsLength(0), mShouldSerializeFn(aShouldSerializeFn) { + std::function&& aShouldSanitizeFn) + : mPrefMapSize(0), mPrefsLength(0), mShouldSanitizeFn(aShouldSanitizeFn) { MOZ_COUNT_CTOR(SharedPreferenceSerializer); } @@ -42,7 +42,7 @@ bool SharedPreferenceSerializer::SerializeToSharedMemory() { // Serialize the early prefs. nsAutoCStringN<1024> prefs; - Preferences::SerializePreferences(prefs, mShouldSerializeFn); + Preferences::SerializePreferences(prefs, mShouldSanitizeFn); mPrefsLength = prefs.Length(); base::SharedMemory shm; diff --git a/ipc/glue/UtilityProcessHost.cpp b/ipc/glue/UtilityProcessHost.cpp index 2a7b217cbef0..fb3643bd569b 100644 --- a/ipc/glue/UtilityProcessHost.cpp +++ b/ipc/glue/UtilityProcessHost.cpp @@ -61,7 +61,7 @@ bool UtilityProcessHost::Launch(StringVector aExtraOpts) { MOZ_ASSERT(!mUtilityProcessParent); mPrefSerializer = - MakeUnique(ShouldSyncPreference); + MakeUnique(ShouldSanitizePreference); if (!mPrefSerializer->SerializeToSharedMemory()) { return false; } diff --git a/ipc/glue/UtilityProcessManager.cpp b/ipc/glue/UtilityProcessManager.cpp index bdb9848a29dc..4d5b638af776 100644 --- a/ipc/glue/UtilityProcessManager.cpp +++ b/ipc/glue/UtilityProcessManager.cpp @@ -95,7 +95,7 @@ void UtilityProcessManager::OnPreferenceChange(const char16_t* aData) { NS_LossyConvertUTF16toASCII strData(aData); // A pref changed. If it is useful to do so, inform child processes. - if (!ShouldSyncPreference(strData.Data(), false)) { + if (ShouldSanitizePreference(strData.Data(), false)) { return; } diff --git a/ipc/ipdl/test/gtest/IPDLUnitTest.cpp b/ipc/ipdl/test/gtest/IPDLUnitTest.cpp index 9fc53bae4a65..882e5395c64f 100644 --- a/ipc/ipdl/test/gtest/IPDLUnitTest.cpp +++ b/ipc/ipdl/test/gtest/IPDLUnitTest.cpp @@ -50,7 +50,7 @@ already_AddRefed IPDLUnitTestParent::CreateCrossProcess() { std::vector extraArgs; auto prefSerializer = MakeUnique( - ShouldSyncPreference); + ShouldSanitizePreference); if (!prefSerializer->SerializeToSharedMemory()) { ADD_FAILURE() << "SharedPreferenceSerializer::SerializeToSharedMemory failed"; diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index 90021e650e5b..75cbb1d27427 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -3588,7 +3588,7 @@ NS_IMPL_ISUPPORTS(Preferences, nsIPrefService, nsIObserver, nsIPrefBranch, /* static */ void Preferences::SerializePreferences( nsCString& aStr, - const std::function& aShouldSerializeFn) { + const std::function& aShouldSanitizeFn) { MOZ_RELEASE_ASSERT(InitStaticMembers()); aStr.Truncate(); @@ -3597,8 +3597,8 @@ void Preferences::SerializePreferences( Pref* pref = iter.get().get(); if (!pref->IsTypeNone() && pref->HasAdvisablySizedValues()) { pref->SerializeAndAppend( - aStr, !aShouldSerializeFn(pref->Name(), - /* will be fixed later */ false)); + aStr, + aShouldSanitizeFn(pref->Name(), /* will be fixed later */ false)); } } @@ -5675,7 +5675,8 @@ namespace mozilla { void UnloadPrefsModule() { Preferences::Shutdown(); } -bool ShouldSyncPreference(const char* aPref, bool aIsDestWebContentProcess) { +bool ShouldSanitizePreference(const char* aPref, + bool aIsDestWebContentProcess) { #define PREF_LIST_ENTRY(s) \ { s, (sizeof(s) / sizeof(char)) - 1 } struct PrefListEntry { @@ -5700,11 +5701,11 @@ bool ShouldSyncPreference(const char* aPref, bool aIsDestWebContentProcess) { for (const auto& entry : sParentOnlyPrefBranchList) { if (strncmp(entry.mPrefBranch, aPref, entry.mLen) == 0) { - return false; + return true; } } - return true; + return false; } } // namespace mozilla diff --git a/modules/libpref/Preferences.h b/modules/libpref/Preferences.h index d953f8404ad4..07c6e0654f2b 100644 --- a/modules/libpref/Preferences.h +++ b/modules/libpref/Preferences.h @@ -532,7 +532,7 @@ class Preferences final : public nsIPrefService, static bool InitStaticMembers(); }; -bool ShouldSyncPreference(const char* aPref, bool aIsDestWebContentProcess); +bool ShouldSanitizePreference(const char* aPref, bool aIsDestWebContentProcess); } // namespace mozilla diff --git a/modules/libpref/test/gtest/Basics.cpp b/modules/libpref/test/gtest/Basics.cpp index 4f0ee3a17d7b..cfb991b166b0 100644 --- a/modules/libpref/test/gtest/Basics.cpp +++ b/modules/libpref/test/gtest/Basics.cpp @@ -44,11 +44,13 @@ TEST(PrefsBasics, Serialize) nsCString str; Preferences::SerializePreferences( - str, [](const char* aPref, bool) -> bool { return false; }); - ASSERT_STREQ(str.Data(), ""); + str, [](const char* aPref, bool) -> bool { return true; }); + // Assert everything was marked sanitized + ASSERT_EQ(nullptr, strstr(str.Data(), "--:")); Preferences::SerializePreferences(str, [](const char* aPref, bool) -> bool { return strncmp(aPref, "foo.bool", 8) == 0; }); - ASSERT_STREQ(str.Data(), "B-:8/foo.bool:T:F\n"); + // Assert the sanitized serializtion was found + ASSERT_NE(nullptr, strstr(str.Data(), "B-S:8/foo.bool:T:\n")); } diff --git a/netwerk/ipc/SocketProcessHost.cpp b/netwerk/ipc/SocketProcessHost.cpp index 2fe74cc178ce..4ae8299bcc7e 100644 --- a/netwerk/ipc/SocketProcessHost.cpp +++ b/netwerk/ipc/SocketProcessHost.cpp @@ -68,7 +68,7 @@ bool SocketProcessHost::Launch() { std::vector extraArgs; ProcessChild::AddPlatformBuildID(extraArgs); - SharedPreferenceSerializer prefSerializer(ShouldSyncPreference); + SharedPreferenceSerializer prefSerializer(ShouldSanitizePreference); if (!prefSerializer.SerializeToSharedMemory()) { return false; }