Chromium Code Reviews| 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/glib_util.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 std::string notification_id; | |
|
Lei Zhang
2017/04/06 03:59:54
Make the members set via ctor const?
Tom (Use chromium acct)
2017/04/06 05:05:35
Done.
| |
| 50 std::string profile_id; | |
| 51 bool is_incognito; | |
|
Lei Zhang
2017/04/06 03:59:54
This is set but never read from right now. Is this
Tom (Use chromium acct)
2017/04/06 05:05:35
It will be used by GetDisplayed()
| |
| 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; | |
| 64 | |
| 65 // If true, indicates the notification should be closed once | |
| 66 // |dbus_id| becomes available. | |
| 67 bool should_close = false; | |
| 68 }; | |
| 69 | |
| 70 // Callback used by GLib when the "Notify" message completes. | |
|
Lei Zhang
2017/04/06 03:59:54
... the first time.
Tom (Use chromium acct)
2017/04/06 05:05:35
Done.
| |
| 71 friend void OnNotifyComplete(GObject* source_object, | |
| 72 GAsyncResult* result, | |
| 73 gpointer user_data); | |
| 74 | |
| 75 // Called from ::OnNotifyComplete(). | |
| 76 void OnNotifyComplete(NotificationData* data, GVariant* value); | |
| 77 | |
| 78 ScopedGObject<GDBusProxy> notification_proxy_; | |
| 79 | |
| 80 // A std::set<std::unique_ptr<T>> doesn't work well because | |
|
Lei Zhang
2017/04/06 03:59:54
You'd need something like the ListValue::Find() im
Tom (Use chromium acct)
2017/04/06 05:05:35
Acknowledged.
| |
| 81 // eg. std::set::erase(T) would require a std::unique_ptr<T> | |
| 82 // argument, so the data would get double-destructed. | |
| 83 template <typename T> | |
| 84 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; | |
| 85 | |
| 86 UnorderedUniqueSet<NotificationData> notifications_; | |
| 87 | |
| 88 // Makes the "Notify" call to D-Bus. | |
| 89 void NotifyNow(uint32_t dbus_id, | |
| 90 NotificationCommon::Type notification_type, | |
| 91 const Notification& notification, | |
| 92 GCancellable* cancellable, | |
| 93 GAsyncReadyCallback callback, | |
| 94 gpointer user_data); | |
| 95 | |
| 96 // Makes the "CloseNotification" call to D-Bus. | |
| 97 void CloseNow(uint32_t dbus_id); | |
| 98 | |
| 99 NotificationData* FindNotificationData(const std::string& notification_id, | |
| 100 const std::string& profile_id); | |
| 34 | 101 |
| 35 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); | 102 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); |
| 36 }; | 103 }; |
| 37 | 104 |
| 38 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ | 105 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ |
| OLD | NEW |