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

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

Issue 2821533003: Refactor NotificationPlatformBridgeLinux (Closed)
Patch Set: final comments 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 "base/callback_forward.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/notifications/notification_platform_bridge.h"
9 12
10 #include <unordered_map> 13 class NotificationPlatformBridgeLinuxImpl;
11 14
12 #include "base/macros.h" 15 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: 16 public:
23 explicit NotificationPlatformBridgeLinux(GDBusProxy* notification_proxy); 17 NotificationPlatformBridgeLinux();
24 18
25 ~NotificationPlatformBridgeLinux() override; 19 ~NotificationPlatformBridgeLinux() override;
26 20
27 // NotificationPlatformBridge: 21 // NotificationPlatformBridge:
28 void Display(NotificationCommon::Type notification_type, 22 void Display(NotificationCommon::Type notification_type,
29 const std::string& notification_id, 23 const std::string& notification_id,
30 const std::string& profile_id, 24 const std::string& profile_id,
31 bool is_incognito, 25 bool is_incognito,
32 const Notification& notification) override; 26 const Notification& notification) override;
33 void Close(const std::string& profile_id, 27 void Close(const std::string& profile_id,
34 const std::string& notification_id) override; 28 const std::string& notification_id) override;
35 void GetDisplayed( 29 void GetDisplayed(
36 const std::string& profile_id, 30 const std::string& profile_id,
37 bool incognito, 31 bool incognito,
38 const GetDisplayedNotificationsCallback& callback) const override; 32 const GetDisplayedNotificationsCallback& callback) const override;
39 33 void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
40 // Called from NotifyCompleteReceiver().
41 void NotifyCompleteInternal(gpointer user_data, GVariant* value);
42 34
43 private: 35 private:
44 struct NotificationData; 36 scoped_refptr<NotificationPlatformBridgeLinuxImpl> impl_;
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 37
106 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux); 38 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinux);
107 }; 39 };
108 40
109 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_ 41 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698