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

Side by Side Diff: chrome/browser/extensions/api/notifications/extension_notification_display_helper.h

Issue 2703213004: Migrate extension notifications to the new NotificationDisplayService (Closed)
Patch Set: another rebase Created 3 years, 8 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
(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>
Devlin 2017/04/10 21:23:55 needed?
Peter Beverloo 2017/04/10 23:30:06 Will remove.
Peter Beverloo 2017/04/11 14:19:24 Done.
12 #include <vector>
13
14 #include "base/macros.h"
15 #include "chrome/browser/notifications/notification.h"
Devlin 2017/04/10 21:23:55 needed? If so, remove the forward declaration. I
Peter Beverloo 2017/04/10 23:30:06 Nope, I'm able to forward declare.
Peter Beverloo 2017/04/11 14:19:24 Done.
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 {
Devlin 2017/04/11 01:51:56 Forgot one comment - is there a reason this needs
Peter Beverloo 2017/04/11 14:19:25 It needs a holistic view of the notifications show
Devlin 2017/04/11 14:55:23 Whoops! Many APIs have a FooAPI object that's alr
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 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 // Removes stored state for the notification identified by |notification_id|.
49 // Returns whether there was local state.
50 bool EraseDataForNotificationId(const std::string& notification_id);
51
52 // Closes the notification identified by |notification_id|. Returns whether a
53 // notification was closed in response to the call.
54 bool Close(const std::string& notification_id);
55
56 // KeyedService overrides:
57 void Shutdown() override;
58
59 private:
60 // Returns the notification display service instance to communicate with.
61 NotificationDisplayService* GetDisplayService();
62
63 // The Profile instance that owns this keyed service.
64 Profile* profile_;
65
66 // Vector of notifications that are being shown for extensions.
67 NotificationVector notifications_;
68
69 DISALLOW_COPY_AND_ASSIGN(ExtensionNotificationDisplayHelper);
70 };
71
72 } // namespace extensions
73
74 #endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_EXTENSION_NOTIFICATION_DI SPLAY_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698