Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_linux.h

Issue 2806203003: Linux native notifications: Support icons (Closed)
Patch Set: Address thestig@'s comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
14 #include "ui/base/glib/glib_signal.h" 15 #include "ui/base/glib/glib_signal.h"
15 #include "ui/base/glib/scoped_gobject.h" 16 #include "ui/base/glib/scoped_gobject.h"
16 17
17 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge { 18 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge {
18 public: 19 public:
19 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); 20 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy);
20 21
21 ~NotificationPlatformBridgeLinux() override; 22 ~NotificationPlatformBridgeLinux() override;
22 23
23 // NotificationPlatformBridge: 24 // NotificationPlatformBridge:
24 void Display(NotificationCommon::Type notification_type, 25 void Display(NotificationCommon::Type notification_type,
25 const std::string& notification_id, 26 const std::string& notification_id,
26 const std::string& profile_id, 27 const std::string& profile_id,
27 bool is_incognito, 28 bool is_incognito,
28 const Notification& notification) override; 29 const Notification& notification) override;
29 void Close(const std::string& profile_id, 30 void Close(const std::string& profile_id,
30 const std::string& notification_id) override; 31 const std::string& notification_id) override;
31 void GetDisplayed( 32 void GetDisplayed(
32 const std::string& profile_id, 33 const std::string& profile_id,
33 bool incognito, 34 bool incognito,
34 const DisplayedNotificationsCallback& callback) const override; 35 const DisplayedNotificationsCallback& callback) const override;
35 36
36 // Called from NotifyCompleteReceiver(). 37 // Called from NotifyCompleteReceiver().
37 void NotifyCompleteInternal(gpointer user_data, GVariant* value); 38 void NotifyCompleteInternal(gpointer user_data, GVariant* value);
38 39
39 private: 40 private:
40 struct NotificationData; 41 struct NotificationData;
42 struct ResourceFiles;
41 43
42 ScopedGObject<GDBusProxy> notification_proxy_; 44 // Sets up a task to call NotifyNow() after an IO thread writes the
43 45 // necessary resource files.
44 // Used to disconnect from "g-signal" during destruction. 46 void Notify(const Notification& notification,
45 gulong proxy_signal_handler_ = 0; 47 NotificationData* data,
46 48 GAsyncReadyCallback callback,
47 // A std::set<std::unique_ptr<T>> doesn't work well because 49 gpointer user_data);
48 // eg. std::set::erase(T) would require a std::unique_ptr<T>
49 // argument, so the data would get double-destructed.
50 template <typename T>
51 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>;
52
53 UnorderedUniqueSet<NotificationData> notifications_;
54 50
55 // Makes the "Notify" call to D-Bus. 51 // Makes the "Notify" call to D-Bus.
56 void NotifyNow(uint32_t dbus_id, 52 void NotifyNow(const Notification& notification,
57 NotificationCommon::Type notification_type, 53 base::WeakPtr<NotificationData> data,
58 const Notification& notification,
59 GCancellable* cancellable,
60 GAsyncReadyCallback callback, 54 GAsyncReadyCallback callback,
61 gpointer user_data); 55 gpointer user_data,
56 std::unique_ptr<ResourceFiles> resource_files);
62 57
63 // Makes the "CloseNotification" call to D-Bus. 58 // Makes the "CloseNotification" call to D-Bus.
64 void CloseNow(uint32_t dbus_id); 59 void CloseNow(uint32_t dbus_id);
65 60
66 void ForwardNotificationOperation(uint32_t dbus_id, 61 void ForwardNotificationOperation(uint32_t dbus_id,
67 NotificationCommon::Operation operation, 62 NotificationCommon::Operation operation,
68 int action_index); 63 int action_index);
69 64
70 // GSignalReceiver: The function that GLib calls into for 65 // GSignalReceiver: The function that GLib calls into for
71 // ActionInvoked and NotificationClosed signals. 66 // ActionInvoked and NotificationClosed signals.
72 CHROMEG_CALLBACK_3(NotificationPlatformBridgeLinux, 67 CHROMEG_CALLBACK_3(NotificationPlatformBridgeLinux,
73 void, 68 void,
74 GSignalReceiver, 69 GSignalReceiver,
75 GDBusProxy*, 70 GDBusProxy*,
76 const char*, 71 const char*,
77 const char*, 72 const char*,
78 GVariant*); 73 GVariant*);
79 74
80 NotificationData* FindNotificationData(const std::string& notification_id, 75 NotificationData* FindNotificationData(const std::string& notification_id,
81 const std::string& profile_id, 76 const std::string& profile_id,
82 bool is_incognito); 77 bool is_incognito);
83 78
84 NotificationData* FindNotificationData(uint32_t dbus_id); 79 NotificationData* FindNotificationData(uint32_t dbus_id);
85 80
81 ScopedGObject<GDBusProxy> notification_proxy_;
82
83 // Used to disconnect from "g-signal" during destruction.
84 gulong proxy_signal_handler_ = 0;
85
86 // A std::set<std::unique_ptr<T>> doesn't work well because
87 // eg. std::set::erase(T) would require a std::unique_ptr<T>
88 // argument, so the data would get double-destructed.
89 template <typename T>
90 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>;
91
92 UnorderedUniqueSet<NotificationData> notifications_;
93
94 base::WeakPtrFactory<NotificationPlatformBridgeLinux> weak_factory_;
95
86 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); 96 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux);
87 }; 97 };
88 98
89 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ 99 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698