Skip to content

Commit

Permalink
fix: calculate a hash for the Tag property of ToastNotification. (#42239
Browse files Browse the repository at this point in the history
)

* fix: calculate a hash for the Tag property of ToastNotification.

* fix: calculate a hash for the Tag property of ToastNotification.

---------

Co-authored-by: bill.shen <shenyb32768@gmail.com>
  • Loading branch information
cucbin and bill.shen committed May 24, 2024
1 parent 7ec8137 commit 3ffa35d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions shell/browser/notifications/win/windows_toast_notification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <wrl\wrappers\corewrappers.h>

#include "base/environment.h"
#include "base/hash/hash.h"
#include "base/logging.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
Expand Down Expand Up @@ -71,6 +72,10 @@ void DebugLog(std::string_view log_msg) {
LOG(INFO) << log_msg;
}

std::wstring GetTag(const std::string& notification_id) {
return base::NumberToWString(base::Hash(notification_id));
}

} // namespace

// static
Expand Down Expand Up @@ -146,7 +151,7 @@ void WindowsToastNotification::Remove() {
return;

ScopedHString group(kGroup);
ScopedHString tag(base::as_wcstr(base::UTF8ToUTF16(notification_id())));
ScopedHString tag(GetTag(notification_id()));
notification_history->RemoveGroupedTagWithId(tag, group, app_id);
}

Expand Down Expand Up @@ -199,7 +204,7 @@ HRESULT WindowsToastNotification::ShowInternal(
REPORT_AND_RETURN_IF_FAILED(toast2->put_Group(group),
"WinAPI: Setting group failed");

ScopedHString tag(base::as_wcstr(base::UTF8ToUTF16(notification_id())));
ScopedHString tag(GetTag(notification_id()));
REPORT_AND_RETURN_IF_FAILED(toast2->put_Tag(tag),
"WinAPI: Setting tag failed");

Expand Down

0 comments on commit 3ffa35d

Please sign in to comment.