| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_EXTENSION_NOTIFICATION_DISPL
AY_HELPER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_EXTENSION_NOTIFICATION_DISPL
AY_HELPER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <set> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/macros.h" |
| 14 #include "components/keyed_service/core/keyed_service.h" |
| 15 |
| 16 class GURL; |
| 17 class Notification; |
| 18 class NotificationDisplayService; |
| 19 class Profile; |
| 20 |
| 21 namespace extensions { |
| 22 |
| 23 // Helper class for displaying notifications through the notification display |
| 24 // service. The NDS supports notifications that can outlive the browser process, |
| 25 // and therefore does not retain as much information as is necessary to support |
| 26 // the extensions API. (Notably the ability to partly update notifications.) |
| 27 class ExtensionNotificationDisplayHelper : public KeyedService { |
| 28 public: |
| 29 explicit ExtensionNotificationDisplayHelper(Profile* profile); |
| 30 ~ExtensionNotificationDisplayHelper() override; |
| 31 |
| 32 // Displays the |notification| using the notification display service. |
| 33 void Display(const Notification& notification); |
| 34 |
| 35 // Returns the notification identified by |notification_id| if it is currently |
| 36 // visible. May return a nullptr. |
| 37 Notification* GetByNotificationId(const std::string& notification_id); |
| 38 |
| 39 // Returns a set with the IDs of all notifications that are currently being |
| 40 // shown on behalf of the |extension_origin|. |
| 41 std::set<std::string> GetNotificationIdsForExtension( |
| 42 const GURL& extension_origin) const; |
| 43 |
| 44 // Removes stored state for the notification identified by |notification_id|. |
| 45 // Returns whether there was local state. |
| 46 bool EraseDataForNotificationId(const std::string& notification_id); |
| 47 |
| 48 // Closes the notification identified by |notification_id|. Returns whether a |
| 49 // notification was closed in response to the call. |
| 50 bool Close(const std::string& notification_id); |
| 51 |
| 52 // KeyedService overrides: |
| 53 void Shutdown() override; |
| 54 |
| 55 private: |
| 56 using NotificationVector = std::vector<std::unique_ptr<Notification>>; |
| 57 |
| 58 // Returns the notification display service instance to communicate with. |
| 59 NotificationDisplayService* GetDisplayService(); |
| 60 |
| 61 // The Profile instance that owns this keyed service. |
| 62 Profile* profile_; |
| 63 |
| 64 // Vector of notifications that are being shown for extensions. |
| 65 NotificationVector notifications_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(ExtensionNotificationDisplayHelper); |
| 68 }; |
| 69 |
| 70 } // namespace extensions |
| 71 |
| 72 #endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_EXTENSION_NOTIFICATION_DI
SPLAY_HELPER_H_ |
| OLD | NEW |