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