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/timer.h" | |
12 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
13 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" |
14 #include "chrome/browser/notifications/notification_ui_manager_impl.h" | 17 #include "chrome/browser/notifications/notification_ui_manager_impl.h" |
15 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
16 #include "ui/message_center/message_center_observer.h" | 19 #include "ui/message_center/message_center_observer.h" |
17 #include "ui/message_center/message_center_tray_delegate.h" | 20 #include "ui/message_center/message_center_tray_delegate.h" |
18 | 21 |
19 class MessageCenterSettingsController; | 22 class MessageCenterSettingsController; |
20 class Notification; | 23 class Notification; |
24 class PrefService; | |
21 class Profile; | 25 class Profile; |
22 | 26 |
23 // This class extends NotificationUIManagerImpl and delegates actual display | 27 // This class extends NotificationUIManagerImpl and delegates actual display |
24 // of notifications to MessageCenter, doing necessary conversions. | 28 // of notifications to MessageCenter, doing necessary conversions. Supports |
29 // weak pointers for reliable lifetime in timer callbacks. | |
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, |
34 public base::SupportsWeakPtr<MessageCenterNotificationManager> { | |
Andrew T Wilson (Slow)
2013/06/19 06:28:57
Unless external classes need to be able to create
dewittj
2013/06/20 02:20:54
Done.
| |
29 public: | 35 public: |
30 explicit MessageCenterNotificationManager( | 36 explicit MessageCenterNotificationManager( |
31 message_center::MessageCenter* message_center); | 37 message_center::MessageCenter* message_center, |
38 PrefService* local_state); | |
32 virtual ~MessageCenterNotificationManager(); | 39 virtual ~MessageCenterNotificationManager(); |
33 | 40 |
41 // Called when the pref changes for the first run balloon. | |
42 void DisplayFirstRunBalloon(); | |
43 | |
34 // NotificationUIManager | 44 // NotificationUIManager |
35 virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; | 45 virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; |
36 virtual bool CancelById(const std::string& notification_id) OVERRIDE; | 46 virtual bool CancelById(const std::string& notification_id) OVERRIDE; |
37 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( | 47 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( |
38 Profile* profile, | 48 Profile* profile, |
39 const GURL& source) OVERRIDE; | 49 const GURL& source) OVERRIDE; |
40 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; | 50 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; |
41 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; | 51 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; |
42 virtual void CancelAll() OVERRIDE; | 52 virtual void CancelAll() OVERRIDE; |
43 | 53 |
44 // NotificationUIManagerImpl | 54 // NotificationUIManagerImpl |
45 virtual bool ShowNotification(const Notification& notification, | 55 virtual bool ShowNotification(const Notification& notification, |
46 Profile* profile) OVERRIDE; | 56 Profile* profile) OVERRIDE; |
47 virtual bool UpdateNotification(const Notification& notification, | 57 virtual bool UpdateNotification(const Notification& notification, |
48 Profile* profile) OVERRIDE; | 58 Profile* profile) OVERRIDE; |
49 | 59 |
50 // MessageCenter::Delegate | 60 // MessageCenter::Delegate |
51 virtual void DisableExtension(const std::string& notification_id) OVERRIDE; | 61 virtual void DisableExtension(const std::string& notification_id) OVERRIDE; |
52 virtual void DisableNotificationsFromSource( | 62 virtual void DisableNotificationsFromSource( |
53 const std::string& notification_id) OVERRIDE; | 63 const std::string& notification_id) OVERRIDE; |
54 virtual void ShowSettings(const std::string& notification_id) OVERRIDE; | 64 virtual void ShowSettings(const std::string& notification_id) OVERRIDE; |
55 virtual message_center::NotifierSettingsDelegate* ShowSettingsDialog( | 65 virtual message_center::NotifierSettingsDelegate* ShowSettingsDialog( |
56 gfx::NativeView context) OVERRIDE; | 66 gfx::NativeView context) OVERRIDE; |
57 | 67 |
58 // MessageCenterObserver | 68 // MessageCenterObserver |
59 virtual void OnNotificationRemoved(const std::string& notification_id, | 69 virtual void OnNotificationRemoved(const std::string& notification_id, |
60 bool by_user) OVERRIDE; | 70 bool by_user) OVERRIDE; |
61 virtual void OnNotificationCenterClosed() OVERRIDE; | 71 virtual void OnNotificationCenterClosed() OVERRIDE; |
72 virtual void OnNotificationUpdated(const std::string& notification_id) | |
73 OVERRIDE; | |
62 | 74 |
63 private: | 75 private: |
64 class ImageDownloadsObserver { | 76 class ImageDownloadsObserver { |
65 public: | 77 public: |
66 virtual void OnDownloadsCompleted() = 0; | 78 virtual void OnDownloadsCompleted() = 0; |
67 }; | 79 }; |
68 | 80 |
69 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; | 81 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; |
70 class ImageDownloads | 82 class ImageDownloads |
71 : public base::SupportsWeakPtr<ImageDownloads> { | 83 : public base::SupportsWeakPtr<ImageDownloads> { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 // Helpers that add/remove the notification from local map and MessageCenter. | 176 // Helpers that add/remove the notification from local map and MessageCenter. |
165 // They take ownership of profile_notification object. | 177 // They take ownership of profile_notification object. |
166 void AddProfileNotification(ProfileNotification* profile_notification); | 178 void AddProfileNotification(ProfileNotification* profile_notification); |
167 void RemoveProfileNotification(ProfileNotification* profile_notification, | 179 void RemoveProfileNotification(ProfileNotification* profile_notification, |
168 bool by_user); | 180 bool by_user); |
169 | 181 |
170 // Returns the ProfileNotification for the |id|, or NULL if no such | 182 // Returns the ProfileNotification for the |id|, or NULL if no such |
171 // notification is found. | 183 // notification is found. |
172 ProfileNotification* FindProfileNotification(const std::string& id) const; | 184 ProfileNotification* FindProfileNotification(const std::string& id) const; |
173 | 185 |
186 // This function is run on update to ensure that the notification balloon is | |
187 // shown only when there are no popups present. | |
188 void CheckFirstRunTimer(); | |
189 | |
190 // |first_run_pref_| is used to keep track of whether we've ever shown the | |
191 // first run balloon before, even across restarts. | |
192 BooleanPrefMember first_run_pref_; | |
193 | |
194 // The timer after which we will show the first run balloon. This timer is | |
195 // restarted every time the message center is closed and every time the last | |
196 // popup disappears from the screen. | |
197 base::OneShotTimer<MessageCenterNotificationManager> first_run_balloon_timer_; | |
198 | |
174 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); | 199 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); |
175 }; | 200 }; |
176 | 201 |
177 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 202 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
OLD | NEW |