| 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 <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/prefs/pref_member.h" |
| 14 #include "base/time.h" |
| 15 #include "base/timer.h" |
| 12 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 13 #include "chrome/browser/notifications/notification_ui_manager.h" | 17 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager_impl.h" | 18 #include "chrome/browser/notifications/notification_ui_manager_impl.h" |
| 15 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
| 16 #include "ui/message_center/message_center_observer.h" | 20 #include "ui/message_center/message_center_observer.h" |
| 17 #include "ui/message_center/message_center_tray_delegate.h" | 21 #include "ui/message_center/message_center_tray_delegate.h" |
| 18 | 22 |
| 19 class MessageCenterSettingsController; | 23 class MessageCenterSettingsController; |
| 20 class Notification; | 24 class Notification; |
| 25 class PrefService; |
| 21 class Profile; | 26 class Profile; |
| 22 | 27 |
| 23 // This class extends NotificationUIManagerImpl and delegates actual display | 28 // This class extends NotificationUIManagerImpl and delegates actual display |
| 24 // of notifications to MessageCenter, doing necessary conversions. | 29 // of notifications to MessageCenter, doing necessary conversions. |
| 25 class MessageCenterNotificationManager | 30 class MessageCenterNotificationManager |
| 26 : public NotificationUIManagerImpl, | 31 : public NotificationUIManagerImpl, |
| 27 public message_center::MessageCenter::Delegate, | 32 public message_center::MessageCenter::Delegate, |
| 28 public message_center::MessageCenterObserver { | 33 public message_center::MessageCenterObserver { |
| 29 public: | 34 public: |
| 30 explicit MessageCenterNotificationManager( | 35 explicit MessageCenterNotificationManager( |
| 31 message_center::MessageCenter* message_center); | 36 message_center::MessageCenter* message_center, |
| 37 PrefService* local_state); |
| 32 virtual ~MessageCenterNotificationManager(); | 38 virtual ~MessageCenterNotificationManager(); |
| 33 | 39 |
| 34 // NotificationUIManager | 40 // NotificationUIManager |
| 35 virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; | 41 virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; |
| 36 virtual bool CancelById(const std::string& notification_id) OVERRIDE; | 42 virtual bool CancelById(const std::string& notification_id) OVERRIDE; |
| 37 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( | 43 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( |
| 38 Profile* profile, | 44 Profile* profile, |
| 39 const GURL& source) OVERRIDE; | 45 const GURL& source) OVERRIDE; |
| 40 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; | 46 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; |
| 41 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; | 47 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; |
| 42 virtual void CancelAll() OVERRIDE; | 48 virtual void CancelAll() OVERRIDE; |
| 43 | 49 |
| 44 // NotificationUIManagerImpl | 50 // NotificationUIManagerImpl |
| 45 virtual bool ShowNotification(const Notification& notification, | 51 virtual bool ShowNotification(const Notification& notification, |
| 46 Profile* profile) OVERRIDE; | 52 Profile* profile) OVERRIDE; |
| 47 virtual bool UpdateNotification(const Notification& notification, | 53 virtual bool UpdateNotification(const Notification& notification, |
| 48 Profile* profile) OVERRIDE; | 54 Profile* profile) OVERRIDE; |
| 49 | 55 |
| 50 // MessageCenter::Delegate | 56 // MessageCenter::Delegate |
| 51 virtual void DisableExtension(const std::string& notification_id) OVERRIDE; | 57 virtual void DisableExtension(const std::string& notification_id) OVERRIDE; |
| 52 virtual void DisableNotificationsFromSource( | 58 virtual void DisableNotificationsFromSource( |
| 53 const std::string& notification_id) OVERRIDE; | 59 const std::string& notification_id) OVERRIDE; |
| 54 virtual void ShowSettings(const std::string& notification_id) OVERRIDE; | 60 virtual void ShowSettings(const std::string& notification_id) OVERRIDE; |
| 55 | 61 |
| 56 // MessageCenterObserver | 62 // MessageCenterObserver |
| 57 virtual void OnNotificationRemoved(const std::string& notification_id, | 63 virtual void OnNotificationRemoved(const std::string& notification_id, |
| 58 bool by_user) OVERRIDE; | 64 bool by_user) OVERRIDE; |
| 59 virtual void OnNotificationCenterClosed() OVERRIDE; | 65 virtual void OnNotificationCenterClosed() OVERRIDE; |
| 66 virtual void OnNotificationUpdated(const std::string& notification_id) |
| 67 OVERRIDE; |
| 68 |
| 69 #if defined(OS_WIN) |
| 70 // Called when the pref changes for the first run balloon. The first run |
| 71 // balloon is only displayed on Windows, since the visibility of the tray |
| 72 // icon is limited. |
| 73 void DisplayFirstRunBalloon(); |
| 74 |
| 75 void SetFirstRunTimeoutForTest(base::TimeDelta timeout); |
| 76 bool FirstRunTimerIsActive() const; |
| 77 #endif |
| 78 |
| 79 // Takes ownership of |delegate|. |
| 80 void SetMessageCenterTrayDelegateForTest( |
| 81 message_center::MessageCenterTrayDelegate* delegate); |
| 60 | 82 |
| 61 private: | 83 private: |
| 62 class ImageDownloadsObserver { | 84 class ImageDownloadsObserver { |
| 63 public: | 85 public: |
| 64 virtual void OnDownloadsCompleted() = 0; | 86 virtual void OnDownloadsCompleted() = 0; |
| 65 }; | 87 }; |
| 66 | 88 |
| 67 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; | 89 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; |
| 68 class ImageDownloads | 90 class ImageDownloads |
| 69 : public base::SupportsWeakPtr<ImageDownloads> { | 91 : public base::SupportsWeakPtr<ImageDownloads> { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 scoped_ptr<ImageDownloads> downloads_; | 172 scoped_ptr<ImageDownloads> downloads_; |
| 151 }; | 173 }; |
| 152 | 174 |
| 153 scoped_ptr<message_center::MessageCenterTrayDelegate> tray_; | 175 scoped_ptr<message_center::MessageCenterTrayDelegate> tray_; |
| 154 message_center::MessageCenter* message_center_; // Weak, global. | 176 message_center::MessageCenter* message_center_; // Weak, global. |
| 155 | 177 |
| 156 // Use a map by notification_id since this mapping is the most often used. | 178 // Use a map by notification_id since this mapping is the most often used. |
| 157 typedef std::map<std::string, ProfileNotification*> NotificationMap; | 179 typedef std::map<std::string, ProfileNotification*> NotificationMap; |
| 158 NotificationMap profile_notifications_; | 180 NotificationMap profile_notifications_; |
| 159 | 181 |
| 160 scoped_ptr<MessageCenterSettingsController> settings_controller_; | |
| 161 | |
| 162 // Helpers that add/remove the notification from local map and MessageCenter. | 182 // Helpers that add/remove the notification from local map and MessageCenter. |
| 163 // They take ownership of profile_notification object. | 183 // They take ownership of profile_notification object. |
| 164 void AddProfileNotification(ProfileNotification* profile_notification); | 184 void AddProfileNotification(ProfileNotification* profile_notification); |
| 165 void RemoveProfileNotification(ProfileNotification* profile_notification, | 185 void RemoveProfileNotification(ProfileNotification* profile_notification, |
| 166 bool by_user); | 186 bool by_user); |
| 167 | 187 |
| 168 // Returns the ProfileNotification for the |id|, or NULL if no such | 188 // Returns the ProfileNotification for the |id|, or NULL if no such |
| 169 // notification is found. | 189 // notification is found. |
| 170 ProfileNotification* FindProfileNotification(const std::string& id) const; | 190 ProfileNotification* FindProfileNotification(const std::string& id) const; |
| 171 | 191 |
| 192 #if defined(OS_WIN) |
| 193 // This function is run on update to ensure that the notification balloon is |
| 194 // shown only when there are no popups present. |
| 195 void CheckFirstRunTimer(); |
| 196 |
| 197 // |first_run_pref_| is used to keep track of whether we've ever shown the |
| 198 // first run balloon before, even across restarts. |
| 199 BooleanPrefMember first_run_pref_; |
| 200 |
| 201 // The timer after which we will show the first run balloon. This timer is |
| 202 // restarted every time the message center is closed and every time the last |
| 203 // popup disappears from the screen. |
| 204 base::OneShotTimer<MessageCenterNotificationManager> first_run_balloon_timer_; |
| 205 |
| 206 // The first-run balloon will be shown |first_run_idle_timeout_| after all |
| 207 // popups go away and the user has notifications in the message center. |
| 208 base::TimeDelta first_run_idle_timeout_; |
| 209 |
| 210 // Provides weak pointers for the purpose of the first run timer. |
| 211 base::WeakPtrFactory<MessageCenterNotificationManager> weak_factory_; |
| 212 #endif |
| 213 |
| 214 scoped_ptr<MessageCenterSettingsController> settings_controller_; |
| 215 |
| 172 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); | 216 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); |
| 173 }; | 217 }; |
| 174 | 218 |
| 175 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 219 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |