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

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: Fix test failures 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 46
35 #if defined(OS_WIN) || defined(OS_MACOSX) \ 47 #if defined(OS_WIN) || defined(OS_MACOSX) \
36 || (defined(USE_AURA) && !defined(USE_ASH)) 48 || (defined(USE_AURA) && !defined(USE_ASH))
37 // On Windows, Linux and Mac, the notification manager owns the tray icon and 49 // On Windows, Linux and Mac, the notification manager owns the tray icon and
38 // views.Other platforms have global ownership and Create will return NULL. 50 // views.Other platforms have global ownership and Create will return NULL.
39 tray_.reset(message_center::CreateMessageCenterTray()); 51 tray_.reset(message_center::CreateMessageCenterTray());
40 #endif 52 #endif
41 } 53 }
42 54
43 MessageCenterNotificationManager::~MessageCenterNotificationManager() { 55 MessageCenterNotificationManager::~MessageCenterNotificationManager() {
44 message_center_->RemoveObserver(this); 56 message_center_->RemoveObserver(this);
45 } 57 }
46 58
47
48 //////////////////////////////////////////////////////////////////////////////// 59 ////////////////////////////////////////////////////////////////////////////////
49 // NotificationUIManager 60 // NotificationUIManager
50 61
51 bool MessageCenterNotificationManager::DoesIdExist(const std::string& id) { 62 bool MessageCenterNotificationManager::DoesIdExist(const std::string& id) {
52 if (NotificationUIManagerImpl::DoesIdExist(id)) 63 if (NotificationUIManagerImpl::DoesIdExist(id))
53 return true; 64 return true;
54 NotificationMap::iterator iter = profile_notifications_.find(id); 65 NotificationMap::iterator iter = profile_notifications_.find(id);
55 if (iter == profile_notifications_.end()) 66 if (iter == profile_notifications_.end())
56 return false; 67 return false;
57 return true; 68 return true;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 void MessageCenterNotificationManager::OnNotificationRemoved( 278 void MessageCenterNotificationManager::OnNotificationRemoved(
268 const std::string& notification_id, 279 const std::string& notification_id,
269 bool by_user) { 280 bool by_user) {
270 // Do not call FindProfileNotification(). Some tests create notifications 281 // Do not call FindProfileNotification(). Some tests create notifications
271 // directly to MessageCenter, but this method will be called for the removals 282 // directly to MessageCenter, but this method will be called for the removals
272 // of such notifications. 283 // of such notifications.
273 NotificationMap::const_iterator iter = 284 NotificationMap::const_iterator iter =
274 profile_notifications_.find(notification_id); 285 profile_notifications_.find(notification_id);
275 if (iter != profile_notifications_.end()) 286 if (iter != profile_notifications_.end())
276 RemoveProfileNotification(iter->second, by_user); 287 RemoveProfileNotification(iter->second, by_user);
288
289 #if defined(OS_WIN)
290 CheckFirstRunTimer();
291 #endif
277 } 292 }
278 293
279 void MessageCenterNotificationManager::OnNotificationCenterClosed() { 294 void MessageCenterNotificationManager::OnNotificationCenterClosed() {
280 // When the center is open it halts all notifications, so we need to listen 295 // When the center is open it halts all notifications, so we need to listen
281 // for events indicating it's been closed. 296 // for events indicating it's been closed.
282 CheckAndShowNotifications(); 297 CheckAndShowNotifications();
298 #if defined(OS_WIN)
299 CheckFirstRunTimer();
300 #endif
301 }
302
303 void MessageCenterNotificationManager::OnNotificationUpdated(
304 const std::string& notification_id) {
305 #if defined(OS_WIN)
306 CheckFirstRunTimer();
307 #endif
308 }
309
310 void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest(
311 message_center::MessageCenterTrayDelegate* delegate) {
312 tray_.reset(delegate);
313 }
314
315 void MessageCenterNotificationManager::SetFirstRunTimeoutForTest(
316 base::TimeDelta timeout) {
317 first_run_idle_timeout_ = timeout;
283 } 318 }
284 319
285 //////////////////////////////////////////////////////////////////////////////// 320 ////////////////////////////////////////////////////////////////////////////////
286 // ImageDownloads 321 // ImageDownloads
287 322
288 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( 323 MessageCenterNotificationManager::ImageDownloads::ImageDownloads(
289 message_center::MessageCenter* message_center, 324 message_center::MessageCenter* message_center,
290 ImageDownloadsObserver* observer) 325 ImageDownloadsObserver* observer)
291 : message_center_(message_center), 326 : message_center_(message_center),
292 pending_downloads_(0), 327 pending_downloads_(0),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 524
490 MessageCenterNotificationManager::ProfileNotification* 525 MessageCenterNotificationManager::ProfileNotification*
491 MessageCenterNotificationManager::FindProfileNotification( 526 MessageCenterNotificationManager::FindProfileNotification(
492 const std::string& id) const { 527 const std::string& id) const {
493 NotificationMap::const_iterator iter = profile_notifications_.find(id); 528 NotificationMap::const_iterator iter = profile_notifications_.find(id);
494 if (iter == profile_notifications_.end()) 529 if (iter == profile_notifications_.end())
495 return NULL; 530 return NULL;
496 531
497 return (*iter).second; 532 return (*iter).second;
498 } 533 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698