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

Side by Side Diff: chrome/browser/notifications/native_notification_display_service.h

Issue 2906913002: Move handler processing to NotificationDisplayService. (Closed)
Patch Set: Created 3 years, 7 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
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_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <queue> 10 #include <queue>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "chrome/browser/notifications/notification_common.h" 17 #include "chrome/browser/notifications/notification_common.h"
18 #include "chrome/browser/notifications/notification_display_service.h" 18 #include "chrome/browser/notifications/notification_display_service.h"
19 19
20 namespace base {
21 class NullableString16;
22 }
23
24 class MessageCenterDisplayService; 20 class MessageCenterDisplayService;
25 class Notification; 21 class Notification;
26 class NotificationHandler;
27 class NotificationPlatformBridge; 22 class NotificationPlatformBridge;
28 class Profile; 23 class Profile;
29 24
30 // A class to display and interact with notifications in native notification 25 // A class to display and interact with notifications in native notification
31 // centers on platforms that support it. 26 // centers on platforms that support it.
32 class NativeNotificationDisplayService : public NotificationDisplayService { 27 class NativeNotificationDisplayService : public NotificationDisplayService {
33 public: 28 public:
34 NativeNotificationDisplayService( 29 NativeNotificationDisplayService(
35 Profile* profile, 30 Profile* profile,
36 NotificationPlatformBridge* notification_bridge); 31 NotificationPlatformBridge* notification_bridge);
37 ~NativeNotificationDisplayService() override; 32 ~NativeNotificationDisplayService() override;
38 33
39 // NotificationDisplayService implementation. 34 // NotificationDisplayService implementation.
40 void Display(NotificationCommon::Type notification_type, 35 void Display(NotificationCommon::Type notification_type,
41 const std::string& notification_id, 36 const std::string& notification_id,
42 const Notification& notification) override; 37 const Notification& notification) override;
43 void Close(NotificationCommon::Type notification_type, 38 void Close(NotificationCommon::Type notification_type,
44 const std::string& notification_id) override; 39 const std::string& notification_id) override;
45 void GetDisplayed(const DisplayedNotificationsCallback& callback) override; 40 void GetDisplayed(const DisplayedNotificationsCallback& callback) override;
46 41
47 // Used by the notification bridge to propagate back events (click, close...).
48 void ProcessNotificationOperation(NotificationCommon::Operation operation,
49 NotificationCommon::Type notification_type,
50 const std::string& origin,
51 const std::string& notification_id,
52 int action_index,
53 const base::NullableString16& reply);
54
55 // Registers an implementation object to handle notification operations
56 // for |notification_type|.
57 void AddNotificationHandler(NotificationCommon::Type notification_type,
58 std::unique_ptr<NotificationHandler> handler);
59
60 // Removes an implementation added via |AddNotificationHandler|.
61 void RemoveNotificationHandler(NotificationCommon::Type notification_type);
62
63 private: 42 private:
64 NotificationHandler* GetNotificationHandler(
65 NotificationCommon::Type notification_type);
66
67 // Called by |notification_bridge_| when it is finished 43 // Called by |notification_bridge_| when it is finished
68 // initializing. |success| indicates it is ready to be used. 44 // initializing. |success| indicates it is ready to be used.
69 void OnNotificationPlatformBridgeReady(bool success); 45 void OnNotificationPlatformBridgeReady(bool success);
70 46
71 Profile* profile_; 47 Profile* profile_;
72 48
73 NotificationPlatformBridge* notification_bridge_; 49 NotificationPlatformBridge* notification_bridge_;
74 // Indicates if |notification_bridge_| is ready to be used. 50 // Indicates if |notification_bridge_| is ready to be used.
75 bool notification_bridge_ready_; 51 bool notification_bridge_ready_;
76 52
77 // MessageCenterDisplayService to fallback on if initialization of 53 // MessageCenterDisplayService to fallback on if initialization of
78 // |notification_bridge_| failed. 54 // |notification_bridge_| failed.
79 std::unique_ptr<MessageCenterDisplayService> message_center_display_service_; 55 std::unique_ptr<MessageCenterDisplayService> message_center_display_service_;
80 56
81 // Tasks that need to be run once we have the initialization status 57 // Tasks that need to be run once we have the initialization status
82 // for |notification_bridge_|. 58 // for |notification_bridge_|.
83 std::queue<base::OnceClosure> actions_; 59 std::queue<base::OnceClosure> actions_;
84 60
85 std::map<NotificationCommon::Type, std::unique_ptr<NotificationHandler>>
86 notification_handlers_;
87
88 base::WeakPtrFactory<NativeNotificationDisplayService> weak_factory_; 61 base::WeakPtrFactory<NativeNotificationDisplayService> weak_factory_;
89 62
90 DISALLOW_COPY_AND_ASSIGN(NativeNotificationDisplayService); 63 DISALLOW_COPY_AND_ASSIGN(NativeNotificationDisplayService);
91 }; 64 };
92 65
93 #endif // CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ 66 #endif // CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698