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 |
40 #if defined(OS_WIN) | |
41 // Called when the pref changes for the first run balloon. The first run | |
42 // balloon is only displayed on Windows, since the visibility of the tray | |
43 // icon is limited. | |
44 void DisplayFirstRunBalloon(); | |
45 #endif | |
46 | |
34 // NotificationUIManager | 47 // NotificationUIManager |
35 virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; | 48 virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; |
36 virtual bool CancelById(const std::string& notification_id) OVERRIDE; | 49 virtual bool CancelById(const std::string& notification_id) OVERRIDE; |
37 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( | 50 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( |
38 Profile* profile, | 51 Profile* profile, |
39 const GURL& source) OVERRIDE; | 52 const GURL& source) OVERRIDE; |
40 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; | 53 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; |
41 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; | 54 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; |
42 virtual void CancelAll() OVERRIDE; | 55 virtual void CancelAll() OVERRIDE; |
43 | 56 |
44 // NotificationUIManagerImpl | 57 // NotificationUIManagerImpl |
45 virtual bool ShowNotification(const Notification& notification, | 58 virtual bool ShowNotification(const Notification& notification, |
46 Profile* profile) OVERRIDE; | 59 Profile* profile) OVERRIDE; |
47 virtual bool UpdateNotification(const Notification& notification, | 60 virtual bool UpdateNotification(const Notification& notification, |
48 Profile* profile) OVERRIDE; | 61 Profile* profile) OVERRIDE; |
49 | 62 |
50 // MessageCenter::Delegate | 63 // MessageCenter::Delegate |
51 virtual void DisableExtension(const std::string& notification_id) OVERRIDE; | 64 virtual void DisableExtension(const std::string& notification_id) OVERRIDE; |
52 virtual void DisableNotificationsFromSource( | 65 virtual void DisableNotificationsFromSource( |
53 const std::string& notification_id) OVERRIDE; | 66 const std::string& notification_id) OVERRIDE; |
54 virtual void ShowSettings(const std::string& notification_id) OVERRIDE; | 67 virtual void ShowSettings(const std::string& notification_id) OVERRIDE; |
55 virtual message_center::NotifierSettingsDelegate* ShowSettingsDialog( | 68 virtual message_center::NotifierSettingsDelegate* ShowSettingsDialog( |
56 gfx::NativeView context) OVERRIDE; | 69 gfx::NativeView context) OVERRIDE; |
57 | 70 |
58 // MessageCenterObserver | 71 // MessageCenterObserver |
59 virtual void OnNotificationRemoved(const std::string& notification_id, | 72 virtual void OnNotificationRemoved(const std::string& notification_id, |
60 bool by_user) OVERRIDE; | 73 bool by_user) OVERRIDE; |
61 virtual void OnNotificationCenterClosed() OVERRIDE; | 74 virtual void OnNotificationCenterClosed() OVERRIDE; |
75 virtual void OnNotificationUpdated(const std::string& notification_id) | |
76 OVERRIDE; | |
77 | |
78 // Takes ownership of |delegate|. | |
79 void SetMessageCenterTrayDelegateForTest( | |
80 message_center::MessageCenterTrayDelegate* delegate); | |
81 void SetFirstRunTimeoutForTest(base::TimeDelta timeout); | |
62 | 82 |
63 private: | 83 private: |
64 class ImageDownloadsObserver { | 84 class ImageDownloadsObserver { |
65 public: | 85 public: |
66 virtual void OnDownloadsCompleted() = 0; | 86 virtual void OnDownloadsCompleted() = 0; |
67 }; | 87 }; |
68 | 88 |
69 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; | 89 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; |
70 class ImageDownloads | 90 class ImageDownloads |
71 : public base::SupportsWeakPtr<ImageDownloads> { | 91 : 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. | 184 // Helpers that add/remove the notification from local map and MessageCenter. |
165 // They take ownership of profile_notification object. | 185 // They take ownership of profile_notification object. |
166 void AddProfileNotification(ProfileNotification* profile_notification); | 186 void AddProfileNotification(ProfileNotification* profile_notification); |
167 void RemoveProfileNotification(ProfileNotification* profile_notification, | 187 void RemoveProfileNotification(ProfileNotification* profile_notification, |
168 bool by_user); | 188 bool by_user); |
169 | 189 |
170 // Returns the ProfileNotification for the |id|, or NULL if no such | 190 // Returns the ProfileNotification for the |id|, or NULL if no such |
171 // notification is found. | 191 // notification is found. |
172 ProfileNotification* FindProfileNotification(const std::string& id) const; | 192 ProfileNotification* FindProfileNotification(const std::string& id) const; |
173 | 193 |
194 #if defined(OS_WIN) | |
195 // This function is run on update to ensure that the notification balloon is | |
196 // shown only when there are no popups present. | |
197 void CheckFirstRunTimer(); | |
198 #endif | |
199 | |
200 // |first_run_pref_| is used to keep track of whether we've ever shown the | |
201 // first run balloon before, even across restarts. | |
202 BooleanPrefMember first_run_pref_; | |
203 | |
204 // The timer after which we will show the first run balloon. This timer is | |
205 // restarted every time the message center is closed and every time the last | |
206 // popup disappears from the screen. | |
207 base::OneShotTimer<MessageCenterNotificationManager> first_run_balloon_timer_; | |
Andrew T Wilson (Slow)
2013/06/20 21:08:59
So all this stuff is windows-only -- can we #if th
dewittj
2013/06/21 21:56:51
Done.
| |
208 | |
209 // The first-run balloon will be shown |first_run_idle_timeout_| after all | |
210 // popups go away and the user has notifications in the message center. | |
211 base::TimeDelta first_run_idle_timeout_; | |
212 | |
213 // Provides weak pointers for the purpose of the first run timer. | |
214 base::WeakPtrFactory<MessageCenterNotificationManager> weak_factory_; | |
215 | |
174 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); | 216 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); |
175 }; | 217 }; |
176 | 218 |
177 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ | 219 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ |
OLD | NEW |