OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ |
7 | 7 |
8 #include <gio/gio.h> | 8 #include <gio/gio.h> |
9 | 9 |
10 #include <unordered_map> | 10 #include <unordered_map> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "chrome/browser/notifications/notification_platform_bridge.h" | 13 #include "chrome/browser/notifications/notification_platform_bridge.h" |
| 14 #include "ui/base/glib/glib_signal.h" |
14 #include "ui/base/glib/scoped_gobject.h" | 15 #include "ui/base/glib/scoped_gobject.h" |
15 | 16 |
16 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge { | 17 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge { |
17 public: | 18 public: |
18 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); | 19 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); |
19 | 20 |
20 ~NotificationPlatformBridgeLinux() override; | 21 ~NotificationPlatformBridgeLinux() override; |
21 | 22 |
22 // NotificationPlatformBridge: | 23 // NotificationPlatformBridge: |
23 void Display(NotificationCommon::Type notification_type, | 24 void Display(NotificationCommon::Type notification_type, |
24 const std::string& notification_id, | 25 const std::string& notification_id, |
25 const std::string& profile_id, | 26 const std::string& profile_id, |
26 bool is_incognito, | 27 bool is_incognito, |
27 const Notification& notification) override; | 28 const Notification& notification) override; |
28 void Close(const std::string& profile_id, | 29 void Close(const std::string& profile_id, |
29 const std::string& notification_id) override; | 30 const std::string& notification_id) override; |
30 void GetDisplayed( | 31 void GetDisplayed( |
31 const std::string& profile_id, | 32 const std::string& profile_id, |
32 bool incognito, | 33 bool incognito, |
33 const DisplayedNotificationsCallback& callback) const override; | 34 const DisplayedNotificationsCallback& callback) const override; |
34 | 35 |
35 // Called from NotifyCompleteReceiver(). | 36 // Called from NotifyCompleteReceiver(). |
36 void NotifyCompleteInternal(gpointer user_data, GVariant* value); | 37 void NotifyCompleteInternal(gpointer user_data, GVariant* value); |
37 | 38 |
38 private: | 39 private: |
39 struct NotificationData; | 40 struct NotificationData; |
40 | 41 |
41 ScopedGObject<GDBusProxy> notification_proxy_; | 42 ScopedGObject<GDBusProxy> notification_proxy_; |
42 | 43 |
| 44 // Used to disconnect from "g-signal" during destruction. |
| 45 gulong proxy_signal_handler_ = 0; |
| 46 |
43 // A std::set<std::unique_ptr<T>> doesn't work well because | 47 // A std::set<std::unique_ptr<T>> doesn't work well because |
44 // eg. std::set::erase(T) would require a std::unique_ptr<T> | 48 // eg. std::set::erase(T) would require a std::unique_ptr<T> |
45 // argument, so the data would get double-destructed. | 49 // argument, so the data would get double-destructed. |
46 template <typename T> | 50 template <typename T> |
47 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; | 51 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; |
48 | 52 |
49 UnorderedUniqueSet<NotificationData> notifications_; | 53 UnorderedUniqueSet<NotificationData> notifications_; |
50 | 54 |
51 // Makes the "Notify" call to D-Bus. | 55 // Makes the "Notify" call to D-Bus. |
52 void NotifyNow(uint32_t dbus_id, | 56 void NotifyNow(uint32_t dbus_id, |
53 NotificationCommon::Type notification_type, | 57 NotificationCommon::Type notification_type, |
54 const Notification& notification, | 58 const Notification& notification, |
55 GCancellable* cancellable, | 59 GCancellable* cancellable, |
56 GAsyncReadyCallback callback, | 60 GAsyncReadyCallback callback, |
57 gpointer user_data); | 61 gpointer user_data); |
58 | 62 |
59 // Makes the "CloseNotification" call to D-Bus. | 63 // Makes the "CloseNotification" call to D-Bus. |
60 void CloseNow(uint32_t dbus_id); | 64 void CloseNow(uint32_t dbus_id); |
61 | 65 |
| 66 void ForwardNotificationOperation(uint32_t dbus_id, |
| 67 NotificationCommon::Operation operation, |
| 68 int action_index); |
| 69 |
| 70 // GSignalReceiver: The function that GLib calls into for |
| 71 // ActionInvoked and NotificationClosed signals. |
| 72 CHROMEG_CALLBACK_3(NotificationPlatformBridgeLinux, |
| 73 void, |
| 74 GSignalReceiver, |
| 75 GDBusProxy*, |
| 76 const char*, |
| 77 const char*, |
| 78 GVariant*); |
| 79 |
62 NotificationData* FindNotificationData(const std::string& notification_id, | 80 NotificationData* FindNotificationData(const std::string& notification_id, |
63 const std::string& profile_id); | 81 const std::string& profile_id, |
| 82 bool is_incognito); |
| 83 |
| 84 NotificationData* FindNotificationData(uint32_t dbus_id); |
64 | 85 |
65 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); | 86 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); |
66 }; | 87 }; |
67 | 88 |
68 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ | 89 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ |
OLD | NEW |