From 593fb8cdf06e1bb45a857a3fbf3d827d943f0d36 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 15 Apr 2016 16:20:36 +0900 Subject: [PATCH] Delay notification events to next tick It is possible that the events get emitted when calling Show(), which would then delete the class before Show() ends, results in using members of a deleted class. By delaying the events to next tick we can effectively avoid this. --- brightray/browser/win/windows_toast_notification.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index efa30f2fe1..4d4b5bfc34 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -12,6 +12,7 @@ #include "browser/win/scoped_hstring.h" #include "browser/win/notification_presenter_win.h" #include "common/application_info.h" +#include "content/public/browser/browser_thread.h" using namespace ABI::Windows::Data::Xml::Dom; @@ -384,21 +385,27 @@ ToastEventHandler::~ToastEventHandler() { IFACEMETHODIMP ToastEventHandler::Invoke( ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args) { - notification_->NotificationClicked(); + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&Notification::NotificationClicked, notification_)); return S_OK; } IFACEMETHODIMP ToastEventHandler::Invoke( ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e) { - notification_->NotificationDismissed(); + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&Notification::NotificationDismissed, notification_)); return S_OK; } IFACEMETHODIMP ToastEventHandler::Invoke( ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastFailedEventArgs* e) { - notification_->NotificationFailed(); + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&Notification::NotificationFailed, notification_)); return S_OK; }