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 <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 using NotificationVector = std::vector<std::unique_ptr<Notification>>; | |
|
Devlin
2017/04/11 14:55:23
nit: can this be private?
Peter Beverloo
2017/04/11 15:03:36
Yes. Done.
| |
| 30 | |
| 31 explicit ExtensionNotificationDisplayHelper(Profile* profile); | |
| 32 ~ExtensionNotificationDisplayHelper() override; | |
| 33 | |
| 34 // Displays the |notification| using the notification display service. | |
| 35 void Display(const Notification& notification); | |
| 36 | |
| 37 // Returns the notification identified by |notification_id| if it is currently | |
| 38 // visible. May return a nullptr. | |
| 39 Notification* GetByNotificationId(const std::string& notification_id); | |
| 40 | |
| 41 // Returns a set with the IDs of all notifications that are currently being | |
| 42 // shown on behalf of the |extension_origin|. | |
| 43 std::set<std::string> GetNotificationIdsForExtension( | |
| 44 const GURL& extension_origin) const; | |
| 45 | |
| 46 // Removes stored state for the notification identified by |notification_id|. | |
| 47 // Returns whether there was local state. | |
| 48 bool EraseDataForNotificationId(const std::string& notification_id); | |
| 49 | |
| 50 // Closes the notification identified by |notification_id|. Returns whether a | |
| 51 // notification was closed in response to the call. | |
| 52 bool Close(const std::string& notification_id); | |
| 53 | |
| 54 // KeyedService overrides: | |
| 55 void Shutdown() override; | |
| 56 | |
| 57 private: | |
| 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 |