| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_NOTIFICATION_UI_MANAGER_H_ | |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_BALLOON_NOTIFICATION_UI_MANAGER_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/linked_ptr.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/prefs/pref_member.h" | |
| 14 #include "chrome/browser/notifications/balloon.h" | |
| 15 #include "chrome/browser/notifications/balloon_collection.h" | |
| 16 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" | |
| 17 #include "chrome/browser/notifications/notification_prefs_manager.h" | |
| 18 #include "chrome/browser/notifications/notification_system_observer.h" | |
| 19 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 20 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" | |
| 21 | |
| 22 class Notification; | |
| 23 class PrefService; | |
| 24 class Profile; | |
| 25 class QueuedNotification; | |
| 26 | |
| 27 // The notification manager manages use of the desktop for notifications. | |
| 28 // It maintains a queue of pending notifications when space becomes constrained. | |
| 29 class BalloonNotificationUIManager | |
| 30 : public NotificationUIManager, | |
| 31 public NotificationPrefsManager, | |
| 32 public BalloonCollection::BalloonSpaceChangeListener, | |
| 33 public message_center::NotificationBlocker::Observer { | |
| 34 public: | |
| 35 explicit BalloonNotificationUIManager(PrefService* local_state); | |
| 36 virtual ~BalloonNotificationUIManager(); | |
| 37 | |
| 38 // Initializes the UI manager with a balloon collection; this object | |
| 39 // takes ownership of the balloon collection. | |
| 40 void SetBalloonCollection(BalloonCollection* balloon_collection); | |
| 41 | |
| 42 // NotificationUIManager overrides: | |
| 43 virtual void Add(const Notification& notification, | |
| 44 Profile* profile) OVERRIDE; | |
| 45 virtual bool Update(const Notification& notification, | |
| 46 Profile* profile) OVERRIDE; | |
| 47 virtual const Notification* FindById( | |
| 48 const std::string& notification_id) const OVERRIDE; | |
| 49 virtual bool CancelById(const std::string& notification_id) OVERRIDE; | |
| 50 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( | |
| 51 Profile* profile, | |
| 52 const GURL& source) OVERRIDE; | |
| 53 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; | |
| 54 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; | |
| 55 virtual void CancelAll() OVERRIDE; | |
| 56 | |
| 57 // NotificationPrefsManager overrides: | |
| 58 virtual BalloonCollection::PositionPreference | |
| 59 GetPositionPreference() const OVERRIDE; | |
| 60 virtual void SetPositionPreference( | |
| 61 BalloonCollection::PositionPreference preference) OVERRIDE; | |
| 62 | |
| 63 BalloonCollection* balloon_collection(); | |
| 64 NotificationPrefsManager* prefs_manager(); | |
| 65 | |
| 66 // Helper used to pull the static instance for testing. | |
| 67 // In tests, use this instead of g_browser_process->notification_ui_manager(). | |
| 68 static BalloonNotificationUIManager* GetInstanceForTesting(); | |
| 69 | |
| 70 void GetQueuedNotificationsForTesting( | |
| 71 std::vector<const Notification*>* notifications); | |
| 72 | |
| 73 private: | |
| 74 bool ShowNotification(const Notification& notification, Profile* profile); | |
| 75 bool UpdateNotification(const Notification& notification, Profile* profile); | |
| 76 | |
| 77 // Attempts to display notifications from the show_queue. Invoked if they | |
| 78 // previously returned 'false' from ShowNotifications, which may happen when | |
| 79 // there is no room to show another notification or notifications are blocked. | |
| 80 void CheckAndShowNotifications(); | |
| 81 | |
| 82 void ShowNotifications(); | |
| 83 | |
| 84 void OnDesktopNotificationPositionChanged(); | |
| 85 | |
| 86 // BalloonCollectionObserver overrides: | |
| 87 virtual void OnBalloonSpaceChanged() OVERRIDE; | |
| 88 | |
| 89 // NotificationBlocker::Observer overrides: | |
| 90 virtual void OnBlockingStateChanged( | |
| 91 message_center::NotificationBlocker* blocker) OVERRIDE; | |
| 92 | |
| 93 // A queue of notifications which are waiting to be shown. | |
| 94 typedef std::deque<linked_ptr<QueuedNotification> > NotificationDeque; | |
| 95 NotificationDeque show_queue_; | |
| 96 | |
| 97 // An owned pointer to the collection of active balloons. | |
| 98 scoped_ptr<BalloonCollection> balloon_collection_; | |
| 99 | |
| 100 ScreenLockNotificationBlocker screen_lock_blocker_; | |
| 101 FullscreenNotificationBlocker fullscreen_blocker_; | |
| 102 | |
| 103 // Prefs listener for the position preference. | |
| 104 IntegerPrefMember position_pref_; | |
| 105 | |
| 106 NotificationSystemObserver system_observer_; | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(BalloonNotificationUIManager); | |
| 109 }; | |
| 110 | |
| 111 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_NOTIFICATION_UI_MANAGER_H_ | |
| OLD | NEW |