Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/notifications/notification.h" | |
| 11 #include "chrome/browser/notifications/notification_ui_manager.h" | 13 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 12 #include "chrome/browser/notifications/notification_ui_manager_impl.h" | 14 #include "chrome/browser/notifications/notification_ui_manager_impl.h" |
| 15 #include "ui/message_center/message_center.h" | |
| 13 | 16 |
| 14 class Notification; | 17 class Notification; |
| 15 class Profile; | 18 class Profile; |
| 16 | 19 |
| 17 // This class extends NotificationUIManagerImpl and delegates actual display | 20 // This class extends NotificationUIManagerImpl and delegates actual display |
| 18 // of notifications to MessageCenter, doing necessary conversions. | 21 // of notifications to MessageCenter, doing necessary conversions. |
| 19 class MessageCenterNotificationManager : public NotificationUIManagerImpl { | 22 class MessageCenterNotificationManager |
| 23 : public NotificationUIManagerImpl, | |
| 24 public message_center::MessageCenter::Delegate { | |
| 20 public: | 25 public: |
| 21 MessageCenterNotificationManager(); | 26 MessageCenterNotificationManager(); |
| 22 virtual ~MessageCenterNotificationManager(); | 27 virtual ~MessageCenterNotificationManager(); |
| 23 | 28 |
| 24 // NotificationUIManager: | 29 // NotificationUIManager |
| 25 virtual bool CancelById(const std::string& notification_id) OVERRIDE; | 30 virtual bool CancelById(const std::string& notification_id) OVERRIDE; |
| 26 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; | 31 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; |
| 27 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; | 32 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; |
| 28 virtual void CancelAll() OVERRIDE; | 33 virtual void CancelAll() OVERRIDE; |
| 29 | 34 |
| 30 // NotificationUIManagerImpl: | 35 // NotificationUIManagerImpl |
| 31 virtual bool ShowNotification(const Notification& notification, | 36 virtual bool ShowNotification(const Notification& notification, |
| 32 Profile* profile) OVERRIDE; | 37 Profile* profile) OVERRIDE; |
| 33 virtual bool UpdateNotification(const Notification& notification) OVERRIDE; | 38 virtual bool UpdateNotification(const Notification& notification, |
| 39 Profile* profile) OVERRIDE; | |
| 40 | |
| 41 // MessageCenter::Delegate. | |
| 42 virtual void NotificationRemoved(const std::string& notification_id) OVERRIDE; | |
| 43 virtual void DisableExtension(const std::string& notification_id) OVERRIDE; | |
| 44 virtual void DisableNotificationsFromSource( | |
| 45 const std::string& notification_id) OVERRIDE; | |
| 46 virtual void ShowSettings(const std::string& notification_id) OVERRIDE; | |
| 47 virtual void OnClicked(const std::string& notification_id) OVERRIDE; | |
| 48 virtual void OnButtonClicked(const std::string& notification_id, | |
| 49 int button_index) OVERRIDE; | |
| 34 | 50 |
| 35 private: | 51 private: |
| 52 message_center::MessageCenter* message_center_; // Weak, global. | |
| 53 | |
| 54 // This class keeps a set of original Notificaiton objects and corresponding | |
| 55 // Profiles, so when MessageCenter calls back with a notificaiton_id, this | |
| 56 // class has necessary mapping to other source info - for example, it calls | |
| 57 // NotificationDelegate supplied by client when someone clicks on a Notificaiton | |
| 58 // in MessageCenter. Likewise, if a Profile or Extension is being removed, the | |
| 59 // map makes it possible to revoke the notifications from MessageCenter. | |
| 60 // To keep that set, we use the private ProfileNotification class that stores | |
| 61 // a superset of all information about a notification. | |
| 62 | |
| 63 // TODO(dimich): Consider merging all 4 types (Notification, QueuedNotification, | |
| 64 // ProfileNotification and NotificaitonList::Notification) into a single class. | |
|
dewittj
2013/01/18 00:45:44
nit: There are still 4 more misspellings of Notifi
| |
| 65 class ProfileNotification { | |
| 66 public: | |
| 67 ProfileNotification(Profile* profile, const Notification& notification); | |
| 68 | |
| 69 Profile* profile() const { return profile_; } | |
| 70 const Notification& notification() const { return notification_; } | |
| 71 | |
| 72 // Returns extension_id if the notification originates from an extension, | |
| 73 // empty string otherwise. | |
| 74 std::string GetExtensionId(); | |
| 75 private: | |
| 76 // Weak, guaranteed not to be used after profile removal by parent class. | |
| 77 Profile* profile_; | |
| 78 Notification notification_; | |
| 79 }; | |
| 80 | |
| 81 // Use a map by notification_id since this mapping is the most often used. | |
| 82 typedef std::map<std::string, ProfileNotification*> NotificationMap; | |
| 83 NotificationMap profile_notifications_; | |
| 84 | |
| 85 // Helpers that add/remove the notification from local map and MessageCenter. | |
| 86 // They take ownership of profile_notificaiton object. | |
|
dewittj
2013/01/18 00:45:44
nit: profile_notification
| |
| 87 void AddProfileNotification(ProfileNotification* profile_notification); | |
| 88 void RemoveProfileNotification(ProfileNotification* profile_notification); | |
| 89 | |
| 36 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); | 90 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); |
| 37 }; | 91 }; |
| 38 | 92 |
| 39 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 93 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
| 40 | 94 |
| 41 | 95 |
| OLD | NEW |