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

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

Issue 2821533003: Refactor NotificationPlatformBridgeLinux (Closed)
Patch Set: address latest comments from thestig Created 3 years, 7 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 "chrome/browser/notifications/notification_platform_bridge.h"
Peter Beverloo 2017/04/25 15:16:55 #include "base/callback_forward.h" #include "base/
Tom (Use chromium acct) 2017/04/25 18:35:21 Done.
9 9
10 #include <unordered_map> 10 class NotificationPlatformBridgeLinuxImpl;
11 11
12 #include "base/macros.h" 12 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge {
13 #include "base/memory/weak_ptr.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"
17 #include "ui/base/glib/glib_signal.h"
18 #include "ui/base/glib/scoped_gobject.h"
19
20 class NotificationPlatformBridgeLinux : public NotificationPlatformBridge,
21 public content::NotificationObserver {
22 public: 13 public:
23 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); 14 NotificationPlatformBridgeLinux();
24 15
25 ~NotificationPlatformBridgeLinux() override; 16 ~NotificationPlatformBridgeLinux() override;
26 17
27 // NotificationPlatformBridge: 18 // NotificationPlatformBridge:
28 void Display(NotificationCommon::Type notification_type, 19 void Display(NotificationCommon::Type notification_type,
29 const std::string& notification_id, 20 const std::string& notification_id,
30 const std::string& profile_id, 21 const std::string& profile_id,
31 bool is_incognito, 22 bool is_incognito,
32 const Notification& notification) override; 23 const Notification& notification) override;
33 void Close(const std::string& profile_id, 24 void Close(const std::string& profile_id,
34 const std::string& notification_id) override; 25 const std::string& notification_id) override;
35 void GetDisplayed( 26 void GetDisplayed(
36 const std::string& profile_id, 27 const std::string& profile_id,
37 bool incognito, 28 bool incognito,
38 const GetDisplayedNotificationsCallback& callback) const override; 29 const GetDisplayedNotificationsCallback& callback) const override;
39 30
40 // Called from NotifyCompleteReceiver(). 31 void CheckConnection(base::OnceCallback<void(bool)> callback);
41 void NotifyCompleteInternal(gpointer user_data, GVariant* value);
42 32
43 private: 33 private:
44 struct NotificationData; 34 scoped_refptr<NotificationPlatformBridgeLinuxImpl> impl_;
Peter Beverloo 2017/04/25 15:16:56 Please keep DISALLOW_COPY_AND_ASSIGN()
Tom (Use chromium acct) 2017/04/25 18:35:21 Done.
45 struct ResourceFiles;
46
47 // content::NotificationObserver:
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
106 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux);
107 }; 35 };
108 36
109 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ 37 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698