From b662df4c6160ec638678be6d9e3b3cde451efea5 Mon Sep 17 00:00:00 2001 From: Tom Ritter Date: Thu, 21 Apr 2022 13:22:47 +0000 Subject: [PATCH] Bug 1752332: Move ShouldSyncPreferences to Preferences module r=KrisWright Depends on D141409 Differential Revision: https://phabricator.services.mozilla.com/D141410 --- dom/ipc/ContentParent.cpp | 33 ---------------------------- dom/ipc/ContentParent.h | 2 -- dom/media/ipc/RDDProcessHost.cpp | 4 ++-- dom/media/ipc/RDDProcessManager.cpp | 2 +- gfx/ipc/GPUProcessHost.cpp | 4 ++-- gfx/ipc/GPUProcessManager.cpp | 2 +- gfx/vr/ipc/VRProcessManager.cpp | 2 +- gfx/vr/ipc/VRProcessParent.cpp | 5 +++-- ipc/glue/UtilityProcessHost.cpp | 4 ++-- ipc/glue/UtilityProcessManager.cpp | 2 +- ipc/ipdl/test/gtest/IPDLUnitTest.cpp | 2 +- modules/libpref/Preferences.cpp | 32 +++++++++++++++++++++++++++ modules/libpref/Preferences.h | 2 ++ netwerk/ipc/SocketProcessHost.cpp | 3 +-- 14 files changed, 49 insertions(+), 50 deletions(-) diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 9db31001a90e..f0c2ff26f7b3 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -3786,39 +3786,6 @@ ContentParent::Observe(nsISupports* aSubject, const char* aTopic, return NS_OK; } -/* static */ -bool ContentParent::ShouldSyncPreference(const char* aPref) { -#define PREF_LIST_ENTRY(s) \ - { s, (sizeof(s) / sizeof(char)) - 1 } - struct PrefListEntry { - const char* mPrefBranch; - size_t mLen; - }; - - // These prefs are not useful in child processes. - static const PrefListEntry sParentOnlyPrefBranchList[] = { - PREF_LIST_ENTRY("app.update.lastUpdateTime."), - PREF_LIST_ENTRY("datareporting.policy."), - PREF_LIST_ENTRY("browser.safebrowsing.provider."), - PREF_LIST_ENTRY("browser.shell."), - PREF_LIST_ENTRY("browser.slowStartup."), - PREF_LIST_ENTRY("browser.startup."), - PREF_LIST_ENTRY("extensions.getAddons.cache."), - PREF_LIST_ENTRY("media.gmp-manager."), - PREF_LIST_ENTRY("media.gmp-gmpopenh264."), - PREF_LIST_ENTRY("privacy.sanitize."), - }; -#undef PREF_LIST_ENTRY - - for (const auto& entry : sParentOnlyPrefBranchList) { - if (strncmp(entry.mPrefBranch, aPref, entry.mLen) == 0) { - return false; - } - } - - return true; -} - void ContentParent::UpdateNetworkLinkType() { nsresult rv; nsCOMPtr nls = diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index b6276ef19df0..a63419ed37de 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -1460,8 +1460,6 @@ class ContentParent final void UpdateNetworkLinkType(); - static bool ShouldSyncPreference(const char* aPref); - already_AddRefed InitJSActor(JS::HandleObject aMaybeActor, const nsACString& aName, ErrorResult& aRv) override; diff --git a/dom/media/ipc/RDDProcessHost.cpp b/dom/media/ipc/RDDProcessHost.cpp index c3cff03123bd..750e154b8d7d 100644 --- a/dom/media/ipc/RDDProcessHost.cpp +++ b/dom/media/ipc/RDDProcessHost.cpp @@ -46,8 +46,8 @@ bool RDDProcessHost::Launch(StringVector aExtraOpts) { MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched); MOZ_ASSERT(!mRDDChild); - mPrefSerializer = MakeUnique( - dom::ContentParent::ShouldSyncPreference); + mPrefSerializer = + MakeUnique(ShouldSyncPreference); if (!mPrefSerializer->SerializeToSharedMemory()) { return false; } diff --git a/dom/media/ipc/RDDProcessManager.cpp b/dom/media/ipc/RDDProcessManager.cpp index 5a1358c91aec..ab14bab50cdc 100644 --- a/dom/media/ipc/RDDProcessManager.cpp +++ b/dom/media/ipc/RDDProcessManager.cpp @@ -97,7 +97,7 @@ 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 (!dom::ContentParent::ShouldSyncPreference(strData.Data())) { + if (!ShouldSyncPreference(strData.Data())) { return; } diff --git a/gfx/ipc/GPUProcessHost.cpp b/gfx/ipc/GPUProcessHost.cpp index 69e79c8b98ce..92949b60d3b8 100644 --- a/gfx/ipc/GPUProcessHost.cpp +++ b/gfx/ipc/GPUProcessHost.cpp @@ -42,8 +42,8 @@ bool GPUProcessHost::Launch(StringVector aExtraOpts) { MOZ_ASSERT(!mGPUChild); MOZ_ASSERT(!gfxPlatform::IsHeadless()); - mPrefSerializer = MakeUnique( - dom::ContentParent::ShouldSyncPreference); + mPrefSerializer = + MakeUnique(ShouldSyncPreference); if (!mPrefSerializer->SerializeToSharedMemory()) { return false; } diff --git a/gfx/ipc/GPUProcessManager.cpp b/gfx/ipc/GPUProcessManager.cpp index 19f1068f7d75..e7ba83817964 100644 --- a/gfx/ipc/GPUProcessManager.cpp +++ b/gfx/ipc/GPUProcessManager.cpp @@ -164,7 +164,7 @@ 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 (!dom::ContentParent::ShouldSyncPreference(strData.Data())) { + if (!ShouldSyncPreference(strData.Data())) { return; } diff --git a/gfx/vr/ipc/VRProcessManager.cpp b/gfx/vr/ipc/VRProcessManager.cpp index 29246ac3057a..1d489d5c42e4 100644 --- a/gfx/vr/ipc/VRProcessManager.cpp +++ b/gfx/vr/ipc/VRProcessManager.cpp @@ -217,7 +217,7 @@ 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 (!dom::ContentParent::ShouldSyncPreference(strData.Data())) { + if (!ShouldSyncPreference(strData.Data())) { return; } diff --git a/gfx/vr/ipc/VRProcessParent.cpp b/gfx/vr/ipc/VRProcessParent.cpp index 37187bb57693..63b91e1868b3 100644 --- a/gfx/vr/ipc/VRProcessParent.cpp +++ b/gfx/vr/ipc/VRProcessParent.cpp @@ -16,6 +16,7 @@ #include "mozilla/ipc/ProcessUtils.h" #include "mozilla/ipc/ProtocolTypes.h" #include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol +#include "mozilla/Preferences.h" #include "mozilla/StaticPrefs_dom.h" #include "mozilla/TimeStamp.h" // for TimeStamp #include "mozilla/Unused.h" @@ -54,8 +55,8 @@ bool VRProcessParent::Launch() { std::vector extraArgs; ProcessChild::AddPlatformBuildID(extraArgs); - mPrefSerializer = MakeUnique( - dom::ContentParent::ShouldSyncPreference); + mPrefSerializer = + MakeUnique(ShouldSyncPreference); if (!mPrefSerializer->SerializeToSharedMemory()) { return false; } diff --git a/ipc/glue/UtilityProcessHost.cpp b/ipc/glue/UtilityProcessHost.cpp index 45e7e59f02d6..2a7b217cbef0 100644 --- a/ipc/glue/UtilityProcessHost.cpp +++ b/ipc/glue/UtilityProcessHost.cpp @@ -60,8 +60,8 @@ bool UtilityProcessHost::Launch(StringVector aExtraOpts) { MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched); MOZ_ASSERT(!mUtilityProcessParent); - mPrefSerializer = MakeUnique( - dom::ContentParent::ShouldSyncPreference); + mPrefSerializer = + MakeUnique(ShouldSyncPreference); if (!mPrefSerializer->SerializeToSharedMemory()) { return false; } diff --git a/ipc/glue/UtilityProcessManager.cpp b/ipc/glue/UtilityProcessManager.cpp index e95cb9220227..b5f11e56143d 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 (!dom::ContentParent::ShouldSyncPreference(strData.Data())) { + if (!ShouldSyncPreference(strData.Data())) { return; } diff --git a/ipc/ipdl/test/gtest/IPDLUnitTest.cpp b/ipc/ipdl/test/gtest/IPDLUnitTest.cpp index 4eab8031c3f2..9fc53bae4a65 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( - mozilla::dom::ContentParent::ShouldSyncPreference); + ShouldSyncPreference); if (!prefSerializer->SerializeToSharedMemory()) { ADD_FAILURE() << "SharedPreferenceSerializer::SerializeToSharedMemory failed"; diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index 05d1d2cefdf8..8c190b1adb34 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -5673,6 +5673,38 @@ namespace mozilla { void UnloadPrefsModule() { Preferences::Shutdown(); } +bool ShouldSyncPreference(const char* aPref) { +#define PREF_LIST_ENTRY(s) \ + { s, (sizeof(s) / sizeof(char)) - 1 } + struct PrefListEntry { + const char* mPrefBranch; + size_t mLen; + }; + + // These prefs are not useful in child processes. + static const PrefListEntry sParentOnlyPrefBranchList[] = { + PREF_LIST_ENTRY("app.update.lastUpdateTime."), + PREF_LIST_ENTRY("datareporting.policy."), + PREF_LIST_ENTRY("browser.safebrowsing.provider."), + PREF_LIST_ENTRY("browser.shell."), + PREF_LIST_ENTRY("browser.slowStartup."), + PREF_LIST_ENTRY("browser.startup."), + PREF_LIST_ENTRY("extensions.getAddons.cache."), + PREF_LIST_ENTRY("media.gmp-manager."), + PREF_LIST_ENTRY("media.gmp-gmpopenh264."), + PREF_LIST_ENTRY("privacy.sanitize."), + }; +#undef PREF_LIST_ENTRY + + for (const auto& entry : sParentOnlyPrefBranchList) { + if (strncmp(entry.mPrefBranch, aPref, entry.mLen) == 0) { + return false; + } + } + + return true; +} + } // namespace mozilla // This file contains the C wrappers for the C++ static pref getters, as used diff --git a/modules/libpref/Preferences.h b/modules/libpref/Preferences.h index 1060130f858b..044380cb9135 100644 --- a/modules/libpref/Preferences.h +++ b/modules/libpref/Preferences.h @@ -532,6 +532,8 @@ class Preferences final : public nsIPrefService, static bool InitStaticMembers(); }; +bool ShouldSyncPreference(const char* aPref); + } // namespace mozilla #endif // mozilla_Preferences_h diff --git a/netwerk/ipc/SocketProcessHost.cpp b/netwerk/ipc/SocketProcessHost.cpp index b9e3ca93b512..2fe74cc178ce 100644 --- a/netwerk/ipc/SocketProcessHost.cpp +++ b/netwerk/ipc/SocketProcessHost.cpp @@ -68,8 +68,7 @@ bool SocketProcessHost::Launch() { std::vector extraArgs; ProcessChild::AddPlatformBuildID(extraArgs); - SharedPreferenceSerializer prefSerializer( - mozilla::dom::ContentParent::ShouldSyncPreference); + SharedPreferenceSerializer prefSerializer(ShouldSyncPreference); if (!prefSerializer.SerializeToSharedMemory()) { return false; }