OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "chrome/browser/notifications/displayed_notifications_dispatch_callback
.h" | 14 #include "chrome/browser/notifications/displayed_notifications_dispatch_callback
.h" |
15 #include "chrome/browser/notifications/notification_common.h" | 15 #include "chrome/browser/notifications/notification_common.h" |
16 | 16 |
17 class Notification; | 17 class Notification; |
18 | 18 |
19 // Provides the low-level interface that enables notifications to be displayed | 19 // Provides the low-level interface that enables notifications to be displayed |
20 // and interacted with on the user's screen, orthogonal of whether this | 20 // and interacted with on the user's screen, orthogonal of whether this |
21 // functionality is provided by the browser or by the operating system. | 21 // functionality is provided by the browser or by the operating system. |
22 // TODO(miguelg): Add support for click and close events. | 22 // TODO(miguelg): Add support for click and close events. |
23 class NotificationPlatformBridge { | 23 class NotificationPlatformBridge { |
24 public: | 24 public: |
| 25 using NotificationBridgeReadyCallback = |
| 26 base::OnceCallback<void(bool /* success */)>; |
| 27 |
25 static NotificationPlatformBridge* Create(); | 28 static NotificationPlatformBridge* Create(); |
26 | 29 |
27 virtual ~NotificationPlatformBridge() {} | 30 virtual ~NotificationPlatformBridge() {} |
28 | 31 |
29 // Shows a toast on screen using the data passed in |notification|. | 32 // Shows a toast on screen using the data passed in |notification|. |
30 virtual void Display(NotificationCommon::Type notification_type, | 33 virtual void Display(NotificationCommon::Type notification_type, |
31 const std::string& notification_id, | 34 const std::string& notification_id, |
32 const std::string& profile_id, | 35 const std::string& profile_id, |
33 bool is_incognito, | 36 bool is_incognito, |
34 const Notification& notification) = 0; | 37 const Notification& notification) = 0; |
35 | 38 |
36 // Closes a nofication with |notification_id| and |profile_id| if being | 39 // Closes a nofication with |notification_id| and |profile_id| if being |
37 // displayed. | 40 // displayed. |
38 virtual void Close(const std::string& profile_id, | 41 virtual void Close(const std::string& profile_id, |
39 const std::string& notification_id) = 0; | 42 const std::string& notification_id) = 0; |
40 | 43 |
41 // Writes the ids of all currently displaying notifications and posts | 44 // Writes the ids of all currently displaying notifications and posts |
42 // |callback| with the result. | 45 // |callback| with the result. |
43 virtual void GetDisplayed( | 46 virtual void GetDisplayed( |
44 const std::string& profile_id, | 47 const std::string& profile_id, |
45 bool incognito, | 48 bool incognito, |
46 const GetDisplayedNotificationsCallback& callback) const = 0; | 49 const GetDisplayedNotificationsCallback& callback) const = 0; |
47 | 50 |
| 51 // Calls |callback| once |this| is initialized. The argument is |
| 52 // true if |this| is ready to be used and false if initialization |
| 53 // failed. |callback| may be called directly or from a posted task. |
| 54 virtual void SetReadyCallback(NotificationBridgeReadyCallback callback) = 0; |
| 55 |
48 protected: | 56 protected: |
49 NotificationPlatformBridge() {} | 57 NotificationPlatformBridge() {} |
50 | 58 |
51 private: | 59 private: |
52 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridge); | 60 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridge); |
53 }; | 61 }; |
54 | 62 |
55 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_H_ | 63 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_H_ |
OLD | NEW |