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

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

Issue 2821533003: Refactor NotificationPlatformBridgeLinux (Closed)
Patch Set: Fix icon file getting prematurely deleted 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>
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"
14 #include "chrome/browser/notifications/notification_platform_bridge.h" 11 #include "chrome/browser/notifications/notification_platform_bridge.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "ui/base/glib/glib_signal.h"
18 #include "ui/base/glib/scoped_gobject.h"
19 12
20 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge, 13 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge {
21 public content::NotificationObserver {
22 public: 14 public:
23 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); 15 NotificationPlatformBridgeLinux();
24 16
25 ~NotificationPlatformBridgeLinux() override; 17 ~NotificationPlatformBridgeLinux() override;
26 18
27 // NotificationPlatformBridge: 19 // NotificationPlatformBridge:
28 void Display(NotificationCommon::Type notification_type, 20 void Display(NotificationCommon::Type notification_type,
29 const std::string& notification_id, 21 const std::string& notification_id,
30 const std::string& profile_id, 22 const std::string& profile_id,
31 bool is_incognito, 23 bool is_incognito,
32 const Notification& notification) override; 24 const Notification& notification) override;
33 void Close(const std::string& profile_id, 25 void Close(const std::string& profile_id,
34 const std::string& notification_id) override; 26 const std::string& notification_id) override;
35 void GetDisplayed( 27 void GetDisplayed(
36 const std::string& profile_id, 28 const std::string& profile_id,
37 bool incognito, 29 bool incognito,
38 const DisplayedNotificationsCallback& callback) const override; 30 const DisplayedNotificationsCallback& callback) const override;
39 31
40 // Called from NotifyCompleteReceiver(). 32 // Waits until the D-Bus connection has been created. Returns true
41 void NotifyCompleteInternal(gpointer user_data, GVariant* value); 33 // if the connection was successful.
34 bool BlockUntilReady();
42 35
43 private: 36 private:
44 struct NotificationData; 37 class NativeNotificationThread;
45 struct ResourceFiles;
46 38
47 // content::NotificationObserver: 39 std::unique_ptr<NativeNotificationThread> thread_;
Lei Zhang 2017/04/17 23:32:14 Is there an easy way to reuse an existing thread?
Tom (Use chromium acct) 2017/04/18 01:41:11 Create() needs to block, so I'm reluctant to put t
Lei Zhang 2017/04/18 02:39:58 Yes, that sounds like how many other DBus clients
48 void Observe(int type,
49 const content::NotificationSource& source,
50 const content::NotificationDetails& details) override;
51
52 // Sets up a task to call NotifyNow() after an IO thread writes the
53 // necessary resource files.
54 void Notify(const Notification& notification,
55 NotificationData* data,
56 GAsyncReadyCallback callback,
57 gpointer user_data);
58
59 // Makes the "Notify" call to D-Bus.
60 void NotifyNow(const Notification& notification,
61 base::WeakPtr<NotificationData> data,
62 GAsyncReadyCallback callback,
63 gpointer user_data,
64 std::unique_ptr<ResourceFiles> resource_files);
65
66 // Makes the "CloseNotification" call to D-Bus.
67 void CloseNow(uint32_t dbus_id);
68
69 void ForwardNotificationOperation(uint32_t dbus_id,
70 NotificationCommon::Operation operation,
71 int action_index);
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
83 NotificationData* FindNotificationData(const std::string& notification_id,
84 const std::string& profile_id,
85 bool is_incognito);
86
87 NotificationData* FindNotificationData(uint32_t dbus_id);
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 40
106 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); 41 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux);
107 }; 42 };
108 43
109 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ 44 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698