From 9fb7e92244fe4502bd73010582148ab6370e5fe6 Mon Sep 17 00:00:00 2001 From: Greg Stoll Date: Mon, 21 Nov 2022 19:15:56 +0000 Subject: [PATCH] Bug 1793834 - part 8: add preference for number of messages to keep r=handyman One thing to note is that if the user shrinks this number we won't reclaim any memory - this is because I wanted to avoid doing any more work than necessary when we're logging messages. Let me know if you think this is a problem! Differential Revision: https://phabricator.services.mozilla.com/D161156 --- modules/libpref/init/StaticPrefList.yaml | 7 +++++++ widget/windows/nsWindowLoggedMessages.cpp | 13 +++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 598d64653de2..56b4325b7e55 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -14671,6 +14671,13 @@ type: RelaxedAtomicInt32 value: 0 mirror: always + +# The number of messages of each type to keep for display in +# about:windows-messages +- name: widget.windows.messages_to_log + type: RelaxedAtomicUint32 + value: 6 + mirror: always #endif # Whether to flush the Ole clipboard synchronously. diff --git a/widget/windows/nsWindowLoggedMessages.cpp b/widget/windows/nsWindowLoggedMessages.cpp index 9a0e749e792c..cade8e9c33f3 100644 --- a/widget/windows/nsWindowLoggedMessages.cpp +++ b/widget/windows/nsWindowLoggedMessages.cpp @@ -79,8 +79,6 @@ struct CircularMessageBuffer { }; static std::map> gWindowMessages; -const size_t kNumberOfWindowMessages = 5; - static HWND GetHwndFromWidget(nsIWidget* windowWidget) { nsWindow* window = static_cast(windowWidget); return window->GetWindowHandle(); @@ -264,7 +262,9 @@ void LogWindowMessage(HWND hwnd, UINT event, bool isPreEvent, long eventCounter, WindowMessageData messageData = { eventCounter, isPreEvent, MakeMessageSpecificData(event, wParam, lParam), result, retValue}; - if (hwndWindowMessages.mMessages.size() < kNumberOfWindowMessages) { + uint32_t numberOfMessagesToKeep = + Preferences::GetUint("widget.windows.messages_to_log", 6); + if (hwndWindowMessages.mMessages.size() < numberOfMessagesToKeep) { // haven't reached limit yet hwndWindowMessages.mMessages.push_back(std::move(messageData)); } else { @@ -272,7 +272,7 @@ void LogWindowMessage(HWND hwnd, UINT event, bool isPreEvent, long eventCounter, std::move(messageData); } hwndWindowMessages.mNextFreeIndex = - (hwndWindowMessages.mNextFreeIndex + 1) % kNumberOfWindowMessages; + (hwndWindowMessages.mNextFreeIndex + 1) % numberOfMessagesToKeep; } void GetLatestWindowMessages(RefPtr windowWidget, @@ -281,8 +281,9 @@ void GetLatestWindowMessages(RefPtr windowWidget, const auto& rawMessages = gWindowMessages[hwnd]; nsTArray> sortKeyAndMessageArray; - sortKeyAndMessageArray.SetCapacity(rawMessages.size() * - kNumberOfWindowMessages); + sortKeyAndMessageArray.SetCapacity( + rawMessages.size() * + Preferences::GetUint("widget.windows.messages_to_log", 6)); for (const auto& eventAndMessage : rawMessages) { for (const auto& messageData : eventAndMessage.second.mMessages) { nsCString message = MakeFriendlyMessage(