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

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

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 #include "chrome/browser/notifications/message_center_notification_manager.h" 5 #include "chrome/browser/notifications/message_center_notification_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/extensions/extension_info_map.h" 10 #include "chrome/browser/extensions/extension_info_map.h"
11 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/notifications/desktop_notification_service.h" 12 #include "chrome/browser/notifications/desktop_notification_service.h"
13 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 13 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
14 #include "chrome/browser/notifications/message_center_settings_controller.h" 14 #include "chrome/browser/notifications/message_center_settings_controller.h"
15 #include "chrome/browser/notifications/notification.h" 15 #include "chrome/browser/notifications/notification.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser_finder.h" 17 #include "chrome/browser/ui/browser_finder.h"
18 #include "chrome/browser/ui/chrome_pages.h" 18 #include "chrome/browser/ui/chrome_pages.h"
19 #include "chrome/browser/ui/host_desktop.h" 19 #include "chrome/browser/ui/host_desktop.h"
20 #include "chrome/common/extensions/extension_set.h" 20 #include "chrome/common/extensions/extension_set.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/url_constants.h" 23 #include "content/public/common/url_constants.h"
24 #include "ui/message_center/message_center_style.h" 24 #include "ui/message_center/message_center_style.h"
25 #include "ui/message_center/message_center_tray.h" 25 #include "ui/message_center/message_center_tray.h"
26 #include "ui/message_center/notifier_settings.h" 26 #include "ui/message_center/notifier_settings.h"
27 27
28 namespace {
29 // The first-run balloon will be shown |kFirstRunIdleDelaySeconds| after all
30 // popups go away and the user has notifications in the message center.
31 const int kFirstRunIdleDelaySeconds = 1;
32 } // namespace
33
28 MessageCenterNotificationManager::MessageCenterNotificationManager( 34 MessageCenterNotificationManager::MessageCenterNotificationManager(
29 message_center::MessageCenter* message_center) 35 message_center::MessageCenter* message_center,
36 PrefService* local_state)
30 : message_center_(message_center), 37 : message_center_(message_center),
31 settings_controller_(new MessageCenterSettingsController) { 38 settings_controller_(new MessageCenterSettingsController),
39 first_run_idle_timeout_(
40 base::TimeDelta::FromSeconds(kFirstRunIdleDelaySeconds)),
41 weak_factory_(this) {
42 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state);
43
32 message_center_->SetDelegate(this); 44 message_center_->SetDelegate(this);
33 message_center_->AddObserver(this); 45 message_center_->AddObserver(this);
34 message_center_->SetNotifierSettingsProvider(settings_controller_.get()); 46 message_center_->SetNotifierSettingsProvider(settings_controller_.get());
35 47
36 #if defined(OS_WIN) || defined(OS_MACOSX) \ 48 #if defined(OS_WIN) || defined(OS_MACOSX) \
37 || (defined(USE_AURA) && !defined(USE_ASH)) 49 || (defined(USE_AURA) && !defined(USE_ASH))
38 // On Windows, Linux and Mac, the notification manager owns the tray icon and 50 // On Windows, Linux and Mac, the notification manager owns the tray icon and
39 // views.Other platforms have global ownership and Create will return NULL. 51 // views.Other platforms have global ownership and Create will return NULL.
40 tray_.reset(message_center::CreateMessageCenterTray()); 52 tray_.reset(message_center::CreateMessageCenterTray());
41 #endif 53 #endif
42 } 54 }
43 55
44 MessageCenterNotificationManager::~MessageCenterNotificationManager() { 56 MessageCenterNotificationManager::~MessageCenterNotificationManager() {
45 message_center_->RemoveObserver(this); 57 message_center_->RemoveObserver(this);
46 } 58 }
47 59
48
49 //////////////////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////////////////
50 // NotificationUIManager 61 // NotificationUIManager
51 62
52 bool MessageCenterNotificationManager::DoesIdExist(const std::string& id) { 63 bool MessageCenterNotificationManager::DoesIdExist(const std::string& id) {
53 if (NotificationUIManagerImpl::DoesIdExist(id)) 64 if (NotificationUIManagerImpl::DoesIdExist(id))
54 return true; 65 return true;
55 NotificationMap::iterator iter = profile_notifications_.find(id); 66 NotificationMap::iterator iter = profile_notifications_.find(id);
56 if (iter == profile_notifications_.end()) 67 if (iter == profile_notifications_.end())
57 return false; 68 return false;
58 return true; 69 return true;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void MessageCenterNotificationManager::OnNotificationRemoved( 274 void MessageCenterNotificationManager::OnNotificationRemoved(
264 const std::string& notification_id, 275 const std::string& notification_id,
265 bool by_user) { 276 bool by_user) {
266 // Do not call FindProfileNotification(). Some tests create notifications 277 // Do not call FindProfileNotification(). Some tests create notifications
267 // directly to MessageCenter, but this method will be called for the removals 278 // directly to MessageCenter, but this method will be called for the removals
268 // of such notifications. 279 // of such notifications.
269 NotificationMap::const_iterator iter = 280 NotificationMap::const_iterator iter =
270 profile_notifications_.find(notification_id); 281 profile_notifications_.find(notification_id);
271 if (iter != profile_notifications_.end()) 282 if (iter != profile_notifications_.end())
272 RemoveProfileNotification(iter->second, by_user); 283 RemoveProfileNotification(iter->second, by_user);
284
285 #if defined(OS_WIN)
286 CheckFirstRunTimer();
287 #endif
273 } 288 }
274 289
275 void MessageCenterNotificationManager::OnNotificationCenterClosed() { 290 void MessageCenterNotificationManager::OnNotificationCenterClosed() {
276 // When the center is open it halts all notifications, so we need to listen 291 // When the center is open it halts all notifications, so we need to listen
277 // for events indicating it's been closed. 292 // for events indicating it's been closed.
278 CheckAndShowNotifications(); 293 CheckAndShowNotifications();
294 #if defined(OS_WIN)
295 CheckFirstRunTimer();
296 #endif
297 }
298
299 void MessageCenterNotificationManager::OnNotificationUpdated(
300 const std::string& notification_id) {
301 #if defined(OS_WIN)
302 CheckFirstRunTimer();
303 #endif
304 }
305
306 void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest(
307 message_center::MessageCenterTrayDelegate* delegate) {
308 tray_.reset(delegate);
309 }
310
311 void MessageCenterNotificationManager::SetFirstRunTimeoutForTest(
312 base::TimeDelta timeout) {
313 first_run_idle_timeout_ = timeout;
279 } 314 }
280 315
281 //////////////////////////////////////////////////////////////////////////////// 316 ////////////////////////////////////////////////////////////////////////////////
282 // ImageDownloads 317 // ImageDownloads
283 318
284 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( 319 MessageCenterNotificationManager::ImageDownloads::ImageDownloads(
285 message_center::MessageCenter* message_center, 320 message_center::MessageCenter* message_center,
286 ImageDownloadsObserver* observer) 321 ImageDownloadsObserver* observer)
287 : message_center_(message_center), 322 : message_center_(message_center),
288 pending_downloads_(0), 323 pending_downloads_(0),
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 521
487 MessageCenterNotificationManager::ProfileNotification* 522 MessageCenterNotificationManager::ProfileNotification*
488 MessageCenterNotificationManager::FindProfileNotification( 523 MessageCenterNotificationManager::FindProfileNotification(
489 const std::string& id) const { 524 const std::string& id) const {
490 NotificationMap::const_iterator iter = profile_notifications_.find(id); 525 NotificationMap::const_iterator iter = profile_notifications_.find(id);
491 if (iter == profile_notifications_.end()) 526 if (iter == profile_notifications_.end())
492 return NULL; 527 return NULL;
493 528
494 return (*iter).second; 529 return (*iter).second;
495 } 530 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698