Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/notifications/message_center_notification_manager.h

Issue 17286015: Adds a first-run balloon to the Windows notification center. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar fixes. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 68
56 // MessageCenterObserver 69 // MessageCenterObserver
57 virtual void OnNotificationRemoved(const std::string& notification_id, 70 virtual void OnNotificationRemoved(const std::string& notification_id,
58 bool by_user) OVERRIDE; 71 bool by_user) OVERRIDE;
59 virtual void OnNotificationCenterClosed() OVERRIDE; 72 virtual void OnNotificationCenterClosed() OVERRIDE;
73 virtual void OnNotificationUpdated(const std::string& notification_id)
74 OVERRIDE;
75
76 // Takes ownership of |delegate|.
77 void SetMessageCenterTrayDelegateForTest(
78 message_center::MessageCenterTrayDelegate* delegate);
79 void SetFirstRunTimeoutForTest(base::TimeDelta timeout);
60 80
61 private: 81 private:
62 class ImageDownloadsObserver { 82 class ImageDownloadsObserver {
63 public: 83 public:
64 virtual void OnDownloadsCompleted() = 0; 84 virtual void OnDownloadsCompleted() = 0;
65 }; 85 };
66 86
67 typedef base::Callback<void(const gfx::Image&)> SetImageCallback; 87 typedef base::Callback<void(const gfx::Image&)> SetImageCallback;
68 class ImageDownloads 88 class ImageDownloads
69 : public base::SupportsWeakPtr<ImageDownloads> { 89 : public base::SupportsWeakPtr<ImageDownloads> {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 #endif
197
198 // |first_run_pref_| is used to keep track of whether we've ever shown the
199 // first run balloon before, even across restarts.
200 BooleanPrefMember first_run_pref_;
201
202 // The timer after which we will show the first run balloon. This timer is
203 // restarted every time the message center is closed and every time the last
204 // popup disappears from the screen.
205 base::OneShotTimer<MessageCenterNotificationManager> first_run_balloon_timer_;
206
207 // The first-run balloon will be shown |first_run_idle_timeout_| after all
208 // popups go away and the user has notifications in the message center.
209 base::TimeDelta first_run_idle_timeout_;
210
211 // Provides weak pointers for the purpose of the first run timer.
212 base::WeakPtrFactory<MessageCenterNotificationManager> weak_factory_;
213
172 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); 214 DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager);
173 }; 215 };
174 216
175 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_ 217 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_NOTIFICATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698