Skip to content

Commit

Permalink
Bug 1752332: Move ShouldSyncPreferences to Preferences module r=KrisW…
Browse files Browse the repository at this point in the history
…right

Depends on D141409

Differential Revision: https://phabricator.services.mozilla.com/D141410
  • Loading branch information
tomrittervg committed Apr 20, 2022
1 parent 0e11fa9 commit df927bd
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 50 deletions.
33 changes: 0 additions & 33 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nsINetworkLinkService> nls =
Expand Down
2 changes: 0 additions & 2 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -1460,8 +1460,6 @@ class ContentParent final

void UpdateNetworkLinkType();

static bool ShouldSyncPreference(const char* aPref);

already_AddRefed<JSActor> InitJSActor(JS::HandleObject aMaybeActor,
const nsACString& aName,
ErrorResult& aRv) override;
Expand Down
4 changes: 2 additions & 2 deletions dom/media/ipc/RDDProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ bool RDDProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched);
MOZ_ASSERT(!mRDDChild);

mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>(
dom::ContentParent::ShouldSyncPreference);
mPrefSerializer =
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
if (!mPrefSerializer->SerializeToSharedMemory()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ipc/RDDProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions gfx/ipc/GPUProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ bool GPUProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(!mGPUChild);
MOZ_ASSERT(!gfxPlatform::IsHeadless());

mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>(
dom::ContentParent::ShouldSyncPreference);
mPrefSerializer =
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
if (!mPrefSerializer->SerializeToSharedMemory()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion gfx/ipc/GPUProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion gfx/vr/ipc/VRProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions gfx/vr/ipc/VRProcessParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -54,8 +55,8 @@ bool VRProcessParent::Launch() {
std::vector<std::string> extraArgs;
ProcessChild::AddPlatformBuildID(extraArgs);

mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>(
dom::ContentParent::ShouldSyncPreference);
mPrefSerializer =
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
if (!mPrefSerializer->SerializeToSharedMemory()) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions ipc/glue/UtilityProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ bool UtilityProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched);
MOZ_ASSERT(!mUtilityProcessParent);

mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>(
dom::ContentParent::ShouldSyncPreference);
mPrefSerializer =
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
if (!mPrefSerializer->SerializeToSharedMemory()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion ipc/glue/UtilityProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion ipc/ipdl/test/gtest/IPDLUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ already_AddRefed<IPDLUnitTestParent> IPDLUnitTestParent::CreateCrossProcess() {
std::vector<std::string> extraArgs;

auto prefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>(
mozilla::dom::ContentParent::ShouldSyncPreference);
ShouldSyncPreference);
if (!prefSerializer->SerializeToSharedMemory()) {
ADD_FAILURE()
<< "SharedPreferenceSerializer::SerializeToSharedMemory failed";
Expand Down
32 changes: 32 additions & 0 deletions modules/libpref/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions modules/libpref/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ class Preferences final : public nsIPrefService,
static bool InitStaticMembers();
};

bool ShouldSyncPreference(const char* aPref);

} // namespace mozilla

#endif // mozilla_Preferences_h
3 changes: 1 addition & 2 deletions netwerk/ipc/SocketProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ bool SocketProcessHost::Launch() {
std::vector<std::string> extraArgs;
ProcessChild::AddPlatformBuildID(extraArgs);

SharedPreferenceSerializer prefSerializer(
mozilla::dom::ContentParent::ShouldSyncPreference);
SharedPreferenceSerializer prefSerializer(ShouldSyncPreference);
if (!prefSerializer.SerializeToSharedMemory()) {
return false;
}
Expand Down

0 comments on commit df927bd

Please sign in to comment.