Skip to content

Commit

Permalink
Bug 1752332: Rename ShouldSyncPreference to ShouldSanitizePreference …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
tomrittervg committed Apr 20, 2022
1 parent 1431a4f commit 1a2f91c
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,7 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
// Instantiate the pref serializer. It will be cleaned up in
// `LaunchSubprocessReject`/`LaunchSubprocessResolve`.
mPrefSerializer = MakeUnique<mozilla::ipc::SharedPreferenceSerializer>(
ShouldSyncPreference);
ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory()) {
NS_WARNING("SharedPreferenceSerializer::SerializeToSharedMemory failed");
MarkAsDead();
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/media/ipc/RDDProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool RDDProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(!mRDDChild);

mPrefSerializer =
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory()) {
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions dom/media/ipc/RDDProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion gfx/ipc/GPUProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool GPUProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(!gfxPlatform::IsHeadless());

mPrefSerializer =
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory()) {
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions gfx/ipc/GPUProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions gfx/vr/ipc/VRProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion gfx/vr/ipc/VRProcessParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool VRProcessParent::Launch() {
ProcessChild::AddPlatformBuildID(extraArgs);

mPrefSerializer =
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory()) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions ipc/glue/ProcessUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void SetThisProcessName(const char* aName);
class SharedPreferenceSerializer final {
public:
explicit SharedPreferenceSerializer(
std::function<bool(const char*, bool)>&& aShouldSerializeFn);
std::function<bool(const char*, bool)>&& aShouldSanitizeFn);
SharedPreferenceSerializer(SharedPreferenceSerializer&& aOther);
~SharedPreferenceSerializer();

Expand All @@ -48,7 +48,7 @@ class SharedPreferenceSerializer final {
size_t mPrefsLength;
UniqueFileHandle mPrefMapHandle;
UniqueFileHandle mPrefsHandle;
std::function<bool(const char*, bool)> mShouldSerializeFn;
std::function<bool(const char*, bool)> mShouldSanitizeFn;
};

class SharedPreferenceDeserializer final {
Expand Down
6 changes: 3 additions & 3 deletions ipc/glue/ProcessUtils_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace mozilla {
namespace ipc {

SharedPreferenceSerializer::SharedPreferenceSerializer(
std::function<bool(const char*, bool)>&& aShouldSerializeFn)
: mPrefMapSize(0), mPrefsLength(0), mShouldSerializeFn(aShouldSerializeFn) {
std::function<bool(const char*, bool)>&& aShouldSanitizeFn)
: mPrefMapSize(0), mPrefsLength(0), mShouldSanitizeFn(aShouldSanitizeFn) {
MOZ_COUNT_CTOR(SharedPreferenceSerializer);
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ipc/glue/UtilityProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool UtilityProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(!mUtilityProcessParent);

mPrefSerializer =
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
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 (!ShouldSyncPreference(strData.Data(), false)) {
if (ShouldSanitizePreference(strData.Data(), false)) {
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>(
ShouldSyncPreference);
ShouldSanitizePreference);
if (!prefSerializer->SerializeToSharedMemory()) {
ADD_FAILURE()
<< "SharedPreferenceSerializer::SerializeToSharedMemory failed";
Expand Down
13 changes: 7 additions & 6 deletions modules/libpref/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3588,7 +3588,7 @@ NS_IMPL_ISUPPORTS(Preferences, nsIPrefService, nsIObserver, nsIPrefBranch,
/* static */
void Preferences::SerializePreferences(
nsCString& aStr,
const std::function<bool(const char*, bool)>& aShouldSerializeFn) {
const std::function<bool(const char*, bool)>& aShouldSanitizeFn) {
MOZ_RELEASE_ASSERT(InitStaticMembers());

aStr.Truncate();
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/libpref/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions modules/libpref/test/gtest/Basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
2 changes: 1 addition & 1 deletion netwerk/ipc/SocketProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool SocketProcessHost::Launch() {
std::vector<std::string> extraArgs;
ProcessChild::AddPlatformBuildID(extraArgs);

SharedPreferenceSerializer prefSerializer(ShouldSyncPreference);
SharedPreferenceSerializer prefSerializer(ShouldSanitizePreference);
if (!prefSerializer.SerializeToSharedMemory()) {
return false;
}
Expand Down

0 comments on commit 1a2f91c

Please sign in to comment.