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> | |
11 | |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "chrome/browser/notifications/notification_platform_bridge.h" | 13 #include "chrome/browser/notifications/notification_platform_bridge.h" |
14 #include "ui/base/glib/scoped_gobject.h" | |
12 | 15 |
13 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge { | 16 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge { |
14 public: | 17 public: |
15 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); | 18 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); |
16 | 19 |
17 ~NotificationPlatformBridgeLinux() override; | 20 ~NotificationPlatformBridgeLinux() override; |
18 | 21 |
19 // NotificationPlatformBridge: | 22 // NotificationPlatformBridge: |
20 void Display(NotificationCommon::Type notification_type, | 23 void Display(NotificationCommon::Type notification_type, |
21 const std::string& notification_id, | 24 const std::string& notification_id, |
22 const std::string& profile_id, | 25 const std::string& profile_id, |
23 bool is_incognito, | 26 bool is_incognito, |
24 const Notification& notification) override; | 27 const Notification& notification) override; |
25 void Close(const std::string& profile_id, | 28 void Close(const std::string& profile_id, |
26 const std::string& notification_id) override; | 29 const std::string& notification_id) override; |
27 void GetDisplayed( | 30 void GetDisplayed( |
28 const std::string& profile_id, | 31 const std::string& profile_id, |
29 bool incognito, | 32 bool incognito, |
30 const DisplayedNotificationsCallback& callback) const override; | 33 const DisplayedNotificationsCallback& callback) const override; |
31 | 34 |
32 private: | 35 private: |
33 GDBusProxy* const notification_proxy_; | 36 struct NotificationData { |
37 NotificationData(const std::string& notification_id, | |
38 const std::string& profile_id, | |
39 bool is_incognito, | |
40 NotificationPlatformBridgeLinux* platform_bridge); | |
41 | |
42 ~NotificationData(); | |
43 | |
44 // The ID used by the notification server. Will be 0 until the | |
45 // first "Notify" message completes. | |
46 uint32_t dbus_id = 0; | |
47 | |
48 // Same parameters used by NotificationPlatformBridge::Display(). | |
49 const std::string notification_id; | |
50 const std::string profile_id; | |
51 const bool is_incognito; | |
52 | |
53 NotificationPlatformBridgeLinux* platform_bridge; | |
54 | |
55 // Used to cancel the initial "Notify" message so we don't call | |
56 // NotificationPlatformBridgeLinux::OnNotifyComplete() with a | |
57 // destroyed Notification. | |
58 ScopedGObject<GCancellable> cancellable; | |
59 | |
60 // If not null, the data to update the notification with once | |
61 // |dbus_id| becomes available. | |
62 std::unique_ptr<Notification> update_data; | |
63 NotificationCommon::Type update_type; | |
Peter Beverloo
2017/04/06 17:56:57
Maybe initialize this as NotificationCommon::TYPE_
Tom (Use chromium acct)
2017/04/06 18:25:38
Done.
| |
64 | |
65 // If true, indicates the notification should be closed once | |
66 // |dbus_id| becomes available. | |
67 bool should_close = false; | |
68 }; | |
Peter Beverloo
2017/04/06 17:56:57
(You could decide to only forward declare the stru
Tom (Use chromium acct)
2017/04/06 18:25:38
Done.
| |
69 | |
70 // Callback used by GLib when the "Notify" message completes for the | |
71 // first time. | |
72 friend void OnNotifyComplete(GObject* source_object, | |
73 GAsyncResult* result, | |
74 gpointer user_data); | |
75 | |
76 // Called from ::OnNotifyComplete(). | |
77 void OnNotifyComplete(NotificationData* data, GVariant* value); | |
78 | |
79 ScopedGObject<GDBusProxy> notification_proxy_; | |
80 | |
81 // A std::set<std::unique_ptr<T>> doesn't work well because | |
82 // eg. std::set::erase(T) would require a std::unique_ptr<T> | |
83 // argument, so the data would get double-destructed. | |
84 template <typename T> | |
85 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; | |
86 | |
87 UnorderedUniqueSet<NotificationData> notifications_; | |
88 | |
89 // Makes the "Notify" call to D-Bus. | |
90 void NotifyNow(uint32_t dbus_id, | |
91 NotificationCommon::Type notification_type, | |
92 const Notification& notification, | |
93 GCancellable* cancellable, | |
94 GAsyncReadyCallback callback, | |
95 gpointer user_data); | |
96 | |
97 // Makes the "CloseNotification" call to D-Bus. | |
98 void CloseNow(uint32_t dbus_id); | |
99 | |
100 NotificationData* FindNotificationData(const std::string& notification_id, | |
101 const std::string& profile_id); | |
34 | 102 |
35 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); | 103 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); |
36 }; | 104 }; |
37 | 105 |
38 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ | 106 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ |
OLD | NEW |