Index: chrome/browser/notifications/notification_platform_bridge_win.h |
diff --git a/chrome/browser/notifications/notification_platform_bridge_win.h b/chrome/browser/notifications/notification_platform_bridge_win.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d2417f52607eb0cfad34f71f89f8497cfae50bb7 |
--- /dev/null |
+++ b/chrome/browser/notifications/notification_platform_bridge_win.h |
@@ -0,0 +1,121 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_ |
+#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_ |
+ |
+#include <windows.ui.notifications.h> |
+ |
+#include <map> |
+#include <string> |
+ |
+#include "base/files/file_path.h" |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include "chrome/browser/notifications/notification_platform_bridge.h" |
+ |
+namespace winui = ABI::Windows::UI; |
+ |
+class Notification; |
+struct NotificationToastSession; |
+ |
+// This class is an implementation of NotificationPlatformBridge that will |
+// send platform notifications to the Windows Notification Area. |
+class NotificationPlatformBridgeWin : public NotificationPlatformBridge { |
+ public: |
+ // Handler for Notification events from Windows. Special care is needed since |
+ // callback may occur at any time, including at shut down! To handle this: |
+ // - A static singleton NotificationPlatformBridgeWin::|toast_event_handler_| |
+ // is used throughout. As a result, constructor must be trivial. |
+ // - Operations related to NotificationPlatformBridgeWin need to be posted on |
+ // UI thread. |
+ class ToastEventHandler { |
+ public: |
+ enum EventType { |
+ EVENT_TYPE_ACTIVATED, |
+ EVENT_TYPE_DISMISSED, |
+ EVENT_TYPE_FAILED, |
+ }; |
+ |
+ HRESULT OnActivated(winui::Notifications::IToastNotification* notification, |
+ IInspectable* inspectable); |
+ |
+ HRESULT OnDismissed(winui::Notifications::IToastNotification* notification, |
+ winui::Notifications::IToastDismissedEventArgs* args); |
+ |
+ HRESULT OnFailed(winui::Notifications::IToastNotification* notification, |
+ winui::Notifications::IToastFailedEventArgs* args); |
+ |
+ private: |
+ friend NotificationPlatformBridgeWin; |
+ |
+ // Constructor must be trivial. |
+ ToastEventHandler() = default; |
+ |
+ static void PostHandlerOnUIThread(EventType type, |
+ winui::Notifications::IToastNotification* notification); |
+ |
+ // Runs on the UI thread. |
+ static void HandleOnUIThread(EventType type, |
+ const std::string& notification_id, |
+ const std::string& profile_id); |
+ }; |
+ |
+ NotificationPlatformBridgeWin() = default; |
+ ~NotificationPlatformBridgeWin() override; |
+ |
+ // NotificationPlatformBridge implementation. |
+ void Display(NotificationCommon::Type notification_type, |
+ const std::string& notification_id, |
+ const std::string& profile_id, |
+ bool incognito, |
+ const Notification& notification) override; |
+ void Close(const std::string& profile_id, |
+ const std::string& notification_id) override; |
+ void GetDisplayed(const std::string& profile_id, |
+ bool incognito, |
+ const GetDisplayedNotificationsCallback& callback) |
+ const override; |
+ void SetReadyCallback(NotificationBridgeReadyCallback callback) override; |
+ |
+ private: |
+ friend ToastEventHandler; |
+ |
+ // Runs on a worker thread. |
+ void DisplayStepFormatIconOnWorkerThread( |
+ scoped_refptr<NotificationToastSession> session); |
+ |
+ // Runs on FILE thread. |
+ void DisplayStepPrepareIconOnFileThread( |
+ scoped_refptr<NotificationToastSession> session); |
+ |
+ // Runs on UI thread. Returns true on success. |
+ bool DisplayStepMainWorker(scoped_refptr<NotificationToastSession> session); |
+ |
+ // Runs on UI thread. |
+ void DisplayStepMain(scoped_refptr<NotificationToastSession> session); |
+ |
+ // Called when toast notification gets clicked. This might not work on some |
+ // regions of the notification toast. |
+ void OnClickEvent(const std::string& notification_id, |
+ const std::string& profile_id); |
+ |
+ // Called when toast notification gets closed. |
+ void OnCloseEvent(const std::string& notification_id, |
+ const std::string& profile_id); |
+ |
+ // Removes |notification_id| from |session_map_|, cleans up resources used. |
+ void CleanupSession(std::string notification_id); |
+ |
+ // Static instance to handle Toast event callback from Windows. |
+ static ToastEventHandler toast_event_handler_; |
+ |
+ // Main storage of notification sessions. |
+ // TODO(huangs): Also key by |is_incognito| and |profile_id|?? |
+ std::map<std::string, scoped_refptr<NotificationToastSession>> session_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeWin); |
+}; |
+ |
+#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_ |