зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1752332: Rename ShouldSyncPreference to ShouldSanitizePreference r=necko-reviewers,KrisWright,dragana
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... Differential Revision: https://phabricator.services.mozilla.com/D138682
This commit is contained in:
Родитель
69c064a961
Коммит
1c8c5ab5d0
|
@ -2512,7 +2512,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();
|
||||
|
@ -3531,12 +3531,13 @@ 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())) {
|
||||
if (ShouldSanitizePreference(strData.Data())) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Pref pref(strData, /* isLocked */ false,
|
||||
!ShouldSyncPreference(strData.Data()), Nothing(), Nothing());
|
||||
ShouldSanitizePreference(strData.Data()), Nothing(), Nothing());
|
||||
|
||||
Preferences::GetPreference(&pref);
|
||||
if (IsInitialized()) {
|
||||
MOZ_ASSERT(mQueuedPrefs.IsEmpty());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -97,13 +97,12 @@ 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,
|
||||
!ShouldSyncPreference(strData.Data()), Nothing(),
|
||||
Nothing());
|
||||
ShouldSanitizePreference(strData.Data(), false),
|
||||
Nothing(), Nothing());
|
||||
|
||||
Preferences::GetPreference(&pref);
|
||||
if (!!mRDDChild) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -162,13 +162,12 @@ 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,
|
||||
!ShouldSyncPreference(strData.Data()), Nothing(),
|
||||
Nothing());
|
||||
ShouldSanitizePreference(strData.Data(), false),
|
||||
Nothing(), Nothing());
|
||||
|
||||
Preferences::GetPreference(&pref);
|
||||
if (!!mGPUChild) {
|
||||
|
|
|
@ -217,13 +217,12 @@ 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,
|
||||
!ShouldSyncPreference(strData.Data()), Nothing(),
|
||||
Nothing());
|
||||
ShouldSanitizePreference(strData.Data(), false),
|
||||
Nothing(), Nothing());
|
||||
|
||||
Preferences::GetPreference(&pref);
|
||||
if (!!mVRChild) {
|
||||
|
|
|
@ -56,7 +56,7 @@ bool VRProcessParent::Launch() {
|
|||
ProcessChild::AddPlatformBuildID(extraArgs);
|
||||
|
||||
mPrefSerializer =
|
||||
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSyncPreference);
|
||||
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
|
||||
if (!mPrefSerializer->SerializeToSharedMemory()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -94,13 +94,12 @@ 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;
|
||||
}
|
||||
|
||||
mozilla::dom::Pref pref(strData, /* isLocked */ false,
|
||||
!ShouldSyncPreference(strData.Data()), Nothing(),
|
||||
Nothing());
|
||||
ShouldSanitizePreference(strData.Data(), false),
|
||||
Nothing(), Nothing());
|
||||
|
||||
Preferences::GetPreference(&pref);
|
||||
if (bool(mProcessParent)) {
|
||||
|
|
|
@ -3579,7 +3579,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();
|
||||
|
@ -3588,7 +3588,7 @@ void Preferences::SerializePreferences(
|
|||
Pref* pref = iter.get().get();
|
||||
if (!pref->IsTypeNone() && pref->HasAdvisablySizedValues()) {
|
||||
pref->SerializeAndAppend(
|
||||
aStr, !aShouldSerializeFn(pref->Name(), XRE_IsContentProcess()));
|
||||
aStr, aShouldSanitizeFn(pref->Name(), XRE_IsContentProcess()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5671,7 +5671,7 @@ namespace mozilla {
|
|||
|
||||
void UnloadPrefsModule() { Preferences::Shutdown(); }
|
||||
|
||||
bool ShouldSyncPreference(const char* aPref,
|
||||
bool ShouldSanitizePreference(const char* aPref,
|
||||
bool aIsContentProcess /* = true */) {
|
||||
#define PREF_LIST_ENTRY(s) \
|
||||
{ s, (sizeof(s) / sizeof(char)) - 1 }
|
||||
|
@ -5697,11 +5697,11 @@ bool ShouldSyncPreference(const char* aPref,
|
|||
|
||||
for (const auto& entry : sParentOnlyPrefBranchList) {
|
||||
if (strncmp(entry.mPrefBranch, aPref, entry.mLen) == 0) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -532,7 +532,7 @@ class Preferences final : public nsIPrefService,
|
|||
static bool InitStaticMembers();
|
||||
};
|
||||
|
||||
bool ShouldSyncPreference(const char* aPref, bool aIsContentProcess = true);
|
||||
bool ShouldSanitizePreference(const char* aPref, bool aIsContentProcess = true);
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -644,7 +644,7 @@ void nsIOService::NotifySocketProcessPrefsChanged(const char* aName) {
|
|||
}
|
||||
|
||||
dom::Pref pref(nsCString(aName), /* isLocked */ false,
|
||||
!ShouldSyncPreference(aName), Nothing(), Nothing());
|
||||
ShouldSanitizePreference(aName, false), Nothing(), Nothing());
|
||||
|
||||
Preferences::GetPreference(&pref);
|
||||
auto sendPrefUpdate = [pref]() {
|
||||
|
|
|
@ -64,7 +64,7 @@ bool SocketProcessHost::Launch() {
|
|||
std::vector<std::string> extraArgs;
|
||||
ProcessChild::AddPlatformBuildID(extraArgs);
|
||||
|
||||
SharedPreferenceSerializer prefSerializer(ShouldSyncPreference);
|
||||
SharedPreferenceSerializer prefSerializer(ShouldSanitizePreference);
|
||||
if (!prefSerializer.SerializeToSharedMemory()) {
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче