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> | |
9 | |
10 #include <unordered_map> | 8 #include <unordered_map> |
11 | 9 |
12 #include "base/macros.h" | 10 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 11 #include "base/optional.h" |
14 #include "chrome/browser/notifications/notification_platform_bridge.h" | 12 #include "chrome/browser/notifications/notification_platform_bridge.h" |
15 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
17 #include "ui/base/glib/glib_signal.h" | 15 |
18 #include "ui/base/glib/scoped_gobject.h" | 16 namespace dbus { |
17 class Bus; | |
18 class ObjectProxy; | |
19 class Signal; | |
20 } | |
19 | 21 |
20 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge, | 22 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge, |
21 public content::NotificationObserver { | 23 public content::NotificationObserver { |
22 public: | 24 public: |
23 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); | 25 NotificationPlatformBridgeLinux(); |
24 | 26 |
25 ~NotificationPlatformBridgeLinux() override; | 27 ~NotificationPlatformBridgeLinux() override; |
26 | 28 |
27 // NotificationPlatformBridge: | 29 // NotificationPlatformBridge: |
28 void Display(NotificationCommon::Type notification_type, | 30 void Display(NotificationCommon::Type notification_type, |
29 const std::string& notification_id, | 31 const std::string& notification_id, |
30 const std::string& profile_id, | 32 const std::string& profile_id, |
31 bool is_incognito, | 33 bool is_incognito, |
32 const Notification& notification) override; | 34 const Notification& notification) override; |
33 void Close(const std::string& profile_id, | 35 void Close(const std::string& profile_id, |
34 const std::string& notification_id) override; | 36 const std::string& notification_id) override; |
35 void GetDisplayed( | 37 void GetDisplayed( |
36 const std::string& profile_id, | 38 const std::string& profile_id, |
37 bool incognito, | 39 bool incognito, |
38 const GetDisplayedNotificationsCallback& callback) const override; | 40 const GetDisplayedNotificationsCallback& callback) const override; |
39 | 41 |
40 // Called from NotifyCompleteReceiver(). | 42 void IsConnected(base::OnceCallback<void(bool)> callback); |
Lei Zhang
2017/04/21 22:45:18
Maybe rename to CheckConnection? IsConnected sound
Tom (Use chromium acct)
2017/04/24 20:46:15
Done.
| |
41 void NotifyCompleteInternal(gpointer user_data, GVariant* value); | |
42 | 43 |
43 private: | 44 private: |
45 struct ResourceFile; | |
Lei Zhang
2017/04/21 22:45:18
Leave as it was, AKA sorted.
Tom (Use chromium acct)
2017/04/24 20:46:15
Done.
| |
44 struct NotificationData; | 46 struct NotificationData; |
45 struct ResourceFiles; | |
46 | 47 |
47 // content::NotificationObserver: | 48 // content::NotificationObserver: |
48 void Observe(int type, | 49 void Observe(int type, |
49 const content::NotificationSource& source, | 50 const content::NotificationSource& source, |
50 const content::NotificationDetails& details) override; | 51 const content::NotificationDetails& details) override; |
51 | 52 |
52 // Sets up a task to call NotifyNow() after an IO thread writes the | 53 // Sets up the D-Bus connection. |
53 // necessary resource files. | 54 void Init(); |
54 void Notify(const Notification& notification, | 55 |
55 NotificationData* data, | 56 // Closes the D-Bus connection and deletes notification resources. |
56 GAsyncReadyCallback callback, | 57 void CleanUp(); |
57 gpointer user_data); | 58 void CleanUpInternal(); |
Lei Zhang
2017/04/21 22:45:18
CleanUpOnFileThread?
Tom (Use chromium acct)
2017/04/24 20:46:15
Done.
| |
58 | 59 |
59 // Makes the "Notify" call to D-Bus. | 60 // Makes the "Notify" call to D-Bus. |
60 void NotifyNow(const Notification& notification, | 61 void DisplayNow(NotificationCommon::Type notification_type, |
61 base::WeakPtr<NotificationData> data, | 62 const std::string& notification_id, |
62 GAsyncReadyCallback callback, | 63 const std::string& profile_id, |
63 gpointer user_data, | 64 bool is_incognito, |
64 std::unique_ptr<ResourceFiles> resource_files); | 65 std::unique_ptr<Notification> notification); |
65 | 66 |
66 // Makes the "CloseNotification" call to D-Bus. | 67 // Makes the "CloseNotification" call to D-Bus. |
67 void CloseNow(uint32_t dbus_id); | 68 void CloseNow(const std::string& profile_id, |
69 const std::string& notification_id); | |
68 | 70 |
69 void ForwardNotificationOperation(uint32_t dbus_id, | 71 void GetDisplayedNow(const std::string& profile_id, |
70 NotificationCommon::Operation operation, | 72 bool incognito, |
71 int action_index); | 73 const GetDisplayedNotificationsCallback& callback) const; |
72 | |
73 // GSignalReceiver: The function that GLib calls into for | |
74 // ActionInvoked and NotificationClosed signals. | |
75 CHROMEG_CALLBACK_3(NotificationPlatformBridgeLinux, | |
76 void, | |
77 GSignalReceiver, | |
78 GDBusProxy*, | |
79 const char*, | |
80 const char*, | |
81 GVariant*); | |
82 | 74 |
83 NotificationData* FindNotificationData(const std::string& notification_id, | 75 NotificationData* FindNotificationData(const std::string& notification_id, |
84 const std::string& profile_id, | 76 const std::string& profile_id, |
85 bool is_incognito); | 77 bool is_incognito); |
86 | 78 |
87 NotificationData* FindNotificationData(uint32_t dbus_id); | 79 NotificationData* FindNotificationData(uint32_t dbus_id); |
88 | 80 |
89 ScopedGObject<GDBusProxy> notification_proxy_; | 81 void ForwardNotificationOperation(NotificationData* data, |
82 NotificationCommon::Operation operation, | |
83 int action_index); | |
90 | 84 |
91 // Used to disconnect from "g-signal" during destruction. | 85 void OnActionInvoked(dbus::Signal* signal); |
92 gulong proxy_signal_handler_ = 0; | 86 |
87 void OnNotificationClosed(dbus::Signal* signal); | |
88 | |
89 // Called once the connection has been set up (or not). |success| | |
90 // indicates the connection is ready to use. | |
91 void OnConnected(bool success); | |
92 | |
93 // State necessary for OnConnected() and IsConnected(). | |
94 base::Optional<bool> connected_; | |
95 base::Lock connected_lock_; | |
Lei Zhang
2017/04/21 22:45:18
Does this only protect |connected_| or |on_connect
Tom (Use chromium acct)
2017/04/24 20:46:15
It protects both. Added a comment to clarify
| |
96 std::vector<base::OnceCallback<void(bool)>> on_connected_callbacks_; | |
97 | |
98 scoped_refptr<dbus::Bus> bus_; | |
99 | |
100 dbus::ObjectProxy* notification_proxy_ = nullptr; | |
93 | 101 |
94 // A std::set<std::unique_ptr<T>> doesn't work well because | 102 // 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> | 103 // eg. std::set::erase(T) would require a std::unique_ptr<T> |
96 // argument, so the data would get double-destructed. | 104 // argument, so the data would get double-destructed. |
97 template <typename T> | 105 template <typename T> |
98 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; | 106 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; |
99 | 107 |
100 UnorderedUniqueSet<NotificationData> notifications_; | 108 UnorderedUniqueSet<NotificationData> notifications_; |
101 | 109 |
102 content::NotificationRegistrar registrar_; | 110 content::NotificationRegistrar registrar_; |
103 | 111 |
104 base::WeakPtrFactory<NotificationPlatformBridgeLinux> weak_factory_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); | 112 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); |
107 }; | 113 }; |
108 | 114 |
109 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ | 115 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ |
OLD | NEW |