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 "base/memory/weak_ptr.h" |
13 #include "chrome/browser/notifications/notification_platform_bridge.h" | 14 #include "chrome/browser/notifications/notification_platform_bridge.h" |
| 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" |
14 #include "ui/base/glib/glib_signal.h" | 17 #include "ui/base/glib/glib_signal.h" |
15 #include "ui/base/glib/scoped_gobject.h" | 18 #include "ui/base/glib/scoped_gobject.h" |
16 | 19 |
17 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge { | 20 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge, |
| 21 public content::NotificationObserver { |
18 public: | 22 public: |
19 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); | 23 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); |
20 | 24 |
21 ~NotificationPlatformBridgeLinux() override; | 25 ~NotificationPlatformBridgeLinux() override; |
22 | 26 |
23 // NotificationPlatformBridge: | 27 // NotificationPlatformBridge: |
24 void Display(NotificationCommon::Type notification_type, | 28 void Display(NotificationCommon::Type notification_type, |
25 const std::string& notification_id, | 29 const std::string& notification_id, |
26 const std::string& profile_id, | 30 const std::string& profile_id, |
27 bool is_incognito, | 31 bool is_incognito, |
28 const Notification& notification) override; | 32 const Notification& notification) override; |
29 void Close(const std::string& profile_id, | 33 void Close(const std::string& profile_id, |
30 const std::string& notification_id) override; | 34 const std::string& notification_id) override; |
31 void GetDisplayed( | 35 void GetDisplayed( |
32 const std::string& profile_id, | 36 const std::string& profile_id, |
33 bool incognito, | 37 bool incognito, |
34 const DisplayedNotificationsCallback& callback) const override; | 38 const DisplayedNotificationsCallback& callback) const override; |
35 | 39 |
36 // Called from NotifyCompleteReceiver(). | 40 // Called from NotifyCompleteReceiver(). |
37 void NotifyCompleteInternal(gpointer user_data, GVariant* value); | 41 void NotifyCompleteInternal(gpointer user_data, GVariant* value); |
38 | 42 |
39 private: | 43 private: |
40 struct NotificationData; | 44 struct NotificationData; |
| 45 struct ResourceFiles; |
41 | 46 |
42 ScopedGObject<GDBusProxy> notification_proxy_; | 47 // content::NotificationObserver: |
| 48 void Observe(int type, |
| 49 const content::NotificationSource& source, |
| 50 const content::NotificationDetails& details) override; |
43 | 51 |
44 // Used to disconnect from "g-signal" during destruction. | 52 // Sets up a task to call NotifyNow() after an IO thread writes the |
45 gulong proxy_signal_handler_ = 0; | 53 // necessary resource files. |
46 | 54 void Notify(const Notification& notification, |
47 // A std::set<std::unique_ptr<T>> doesn't work well because | 55 NotificationData* data, |
48 // eg. std::set::erase(T) would require a std::unique_ptr<T> | 56 GAsyncReadyCallback callback, |
49 // argument, so the data would get double-destructed. | 57 gpointer user_data); |
50 template <typename T> | |
51 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; | |
52 | |
53 UnorderedUniqueSet<NotificationData> notifications_; | |
54 | 58 |
55 // Makes the "Notify" call to D-Bus. | 59 // Makes the "Notify" call to D-Bus. |
56 void NotifyNow(uint32_t dbus_id, | 60 void NotifyNow(const Notification& notification, |
57 NotificationCommon::Type notification_type, | 61 base::WeakPtr<NotificationData> data, |
58 const Notification& notification, | |
59 GCancellable* cancellable, | |
60 GAsyncReadyCallback callback, | 62 GAsyncReadyCallback callback, |
61 gpointer user_data); | 63 gpointer user_data, |
| 64 std::unique_ptr<ResourceFiles> resource_files); |
62 | 65 |
63 // Makes the "CloseNotification" call to D-Bus. | 66 // Makes the "CloseNotification" call to D-Bus. |
64 void CloseNow(uint32_t dbus_id); | 67 void CloseNow(uint32_t dbus_id); |
65 | 68 |
66 void ForwardNotificationOperation(uint32_t dbus_id, | 69 void ForwardNotificationOperation(uint32_t dbus_id, |
67 NotificationCommon::Operation operation, | 70 NotificationCommon::Operation operation, |
68 int action_index); | 71 int action_index); |
69 | 72 |
70 // GSignalReceiver: The function that GLib calls into for | 73 // GSignalReceiver: The function that GLib calls into for |
71 // ActionInvoked and NotificationClosed signals. | 74 // ActionInvoked and NotificationClosed signals. |
72 CHROMEG_CALLBACK_3(NotificationPlatformBridgeLinux, | 75 CHROMEG_CALLBACK_3(NotificationPlatformBridgeLinux, |
73 void, | 76 void, |
74 GSignalReceiver, | 77 GSignalReceiver, |
75 GDBusProxy*, | 78 GDBusProxy*, |
76 const char*, | 79 const char*, |
77 const char*, | 80 const char*, |
78 GVariant*); | 81 GVariant*); |
79 | 82 |
80 NotificationData* FindNotificationData(const std::string& notification_id, | 83 NotificationData* FindNotificationData(const std::string& notification_id, |
81 const std::string& profile_id, | 84 const std::string& profile_id, |
82 bool is_incognito); | 85 bool is_incognito); |
83 | 86 |
84 NotificationData* FindNotificationData(uint32_t dbus_id); | 87 NotificationData* FindNotificationData(uint32_t dbus_id); |
85 | 88 |
| 89 ScopedGObject<GDBusProxy> notification_proxy_; |
| 90 |
| 91 // Used to disconnect from "g-signal" during destruction. |
| 92 gulong proxy_signal_handler_ = 0; |
| 93 |
| 94 // A std::set<std::unique_ptr<T>> doesn't work well because |
| 95 // eg. std::set::erase(T) would require a std::unique_ptr<T> |
| 96 // argument, so the data would get double-destructed. |
| 97 template <typename T> |
| 98 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; |
| 99 |
| 100 UnorderedUniqueSet<NotificationData> notifications_; |
| 101 |
| 102 content::NotificationRegistrar registrar_; |
| 103 |
| 104 base::WeakPtrFactory<NotificationPlatformBridgeLinux> weak_factory_; |
| 105 |
86 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); | 106 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); |
87 }; | 107 }; |
88 | 108 |
89 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ | 109 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ |
OLD | NEW |