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

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: 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
Andrew T Wilson (Slow) 2013/06/19 06:28:57 Remove blank line, and add a comment for what this
dewittj 2013/06/20 02:20:54 Done.
30 const int kIdleDelaySeconds = 1;
31 }
32
28 MessageCenterNotificationManager::MessageCenterNotificationManager( 33 MessageCenterNotificationManager::MessageCenterNotificationManager(
29 message_center::MessageCenter* message_center) 34 message_center::MessageCenter* message_center,
35 PrefService* local_state)
30 : message_center_(message_center), 36 : message_center_(message_center),
31 settings_controller_(new MessageCenterSettingsController) { 37 settings_controller_(new MessageCenterSettingsController) {
38 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state);
39
32 message_center_->SetDelegate(this); 40 message_center_->SetDelegate(this);
33 message_center_->AddObserver(this); 41 message_center_->AddObserver(this);
34 42
35 #if defined(OS_WIN) || defined(OS_MACOSX) \ 43 #if defined(OS_WIN) || defined(OS_MACOSX) \
36 || (defined(USE_AURA) && !defined(USE_ASH)) 44 || (defined(USE_AURA) && !defined(USE_ASH))
37 // On Windows, Linux and Mac, the notification manager owns the tray icon and 45 // 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. 46 // views.Other platforms have global ownership and Create will return NULL.
39 tray_.reset(message_center::CreateMessageCenterTray()); 47 tray_.reset(message_center::CreateMessageCenterTray());
40 #endif 48 #endif
41 } 49 }
42 50
43 MessageCenterNotificationManager::~MessageCenterNotificationManager() { 51 MessageCenterNotificationManager::~MessageCenterNotificationManager() {
44 message_center_->RemoveObserver(this); 52 message_center_->RemoveObserver(this);
45 } 53 }
46 54
55 void MessageCenterNotificationManager::DisplayFirstRunBalloon() {
56 #if !defined(OS_WIN)
57 // The first run balloon is only displayed on Windows, since the visibility of
58 // the tray icon is limited.
59 return;
Andrew T Wilson (Slow) 2013/06/19 06:28:57 I think it's better to make the entire method #if
dewittj 2013/06/20 02:20:54 Done.
60 #endif
61
62 if (!tray_)
63 return;
64
65 // Store for posterity the fact that we've shown the first-run balloon.
66 first_run_pref_.SetValue(true);
67 tray_->DisplayFirstRunBalloon();
68 }
47 69
48 //////////////////////////////////////////////////////////////////////////////// 70 ////////////////////////////////////////////////////////////////////////////////
49 // NotificationUIManager 71 // NotificationUIManager
50 72
51 bool MessageCenterNotificationManager::DoesIdExist(const std::string& id) { 73 bool MessageCenterNotificationManager::DoesIdExist(const std::string& id) {
52 if (NotificationUIManagerImpl::DoesIdExist(id)) 74 if (NotificationUIManagerImpl::DoesIdExist(id))
53 return true; 75 return true;
54 NotificationMap::iterator iter = profile_notifications_.find(id); 76 NotificationMap::iterator iter = profile_notifications_.find(id);
55 if (iter == profile_notifications_.end()) 77 if (iter == profile_notifications_.end())
56 return false; 78 return false;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 void MessageCenterNotificationManager::OnNotificationRemoved( 289 void MessageCenterNotificationManager::OnNotificationRemoved(
268 const std::string& notification_id, 290 const std::string& notification_id,
269 bool by_user) { 291 bool by_user) {
270 // Do not call FindProfileNotification(). Some tests create notifications 292 // Do not call FindProfileNotification(). Some tests create notifications
271 // directly to MessageCenter, but this method will be called for the removals 293 // directly to MessageCenter, but this method will be called for the removals
272 // of such notifications. 294 // of such notifications.
273 NotificationMap::const_iterator iter = 295 NotificationMap::const_iterator iter =
274 profile_notifications_.find(notification_id); 296 profile_notifications_.find(notification_id);
275 if (iter != profile_notifications_.end()) 297 if (iter != profile_notifications_.end())
276 RemoveProfileNotification(iter->second, by_user); 298 RemoveProfileNotification(iter->second, by_user);
299
300 CheckFirstRunTimer();
277 } 301 }
278 302
279 void MessageCenterNotificationManager::OnNotificationCenterClosed() { 303 void MessageCenterNotificationManager::OnNotificationCenterClosed() {
280 // When the center is open it halts all notifications, so we need to listen 304 // When the center is open it halts all notifications, so we need to listen
281 // for events indicating it's been closed. 305 // for events indicating it's been closed.
282 CheckAndShowNotifications(); 306 CheckAndShowNotifications();
307 CheckFirstRunTimer();
308 }
309
310 void MessageCenterNotificationManager::OnNotificationUpdated(
311 const std::string& notification_id) {
312 CheckFirstRunTimer();
283 } 313 }
284 314
285 //////////////////////////////////////////////////////////////////////////////// 315 ////////////////////////////////////////////////////////////////////////////////
286 // ImageDownloads 316 // ImageDownloads
287 317
288 MessageCenterNotificationManager::ImageDownloads::ImageDownloads( 318 MessageCenterNotificationManager::ImageDownloads::ImageDownloads(
289 message_center::MessageCenter* message_center, 319 message_center::MessageCenter* message_center,
290 ImageDownloadsObserver* observer) 320 ImageDownloadsObserver* observer)
291 : message_center_(message_center), 321 : message_center_(message_center),
292 pending_downloads_(0), 322 pending_downloads_(0),
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 519
490 MessageCenterNotificationManager::ProfileNotification* 520 MessageCenterNotificationManager::ProfileNotification*
491 MessageCenterNotificationManager::FindProfileNotification( 521 MessageCenterNotificationManager::FindProfileNotification(
492 const std::string& id) const { 522 const std::string& id) const {
493 NotificationMap::const_iterator iter = profile_notifications_.find(id); 523 NotificationMap::const_iterator iter = profile_notifications_.find(id);
494 if (iter == profile_notifications_.end()) 524 if (iter == profile_notifications_.end())
495 return NULL; 525 return NULL;
496 526
497 return (*iter).second; 527 return (*iter).second;
498 } 528 }
529
530 void MessageCenterNotificationManager::CheckFirstRunTimer() {
531 #if !defined(OS_WIN)
532 // The first run balloon is only used on Windows, since it is the platform
533 // that has the most issues with tray icon visibility.
534 return;
535 #endif
536
537 // If there is no tray_, we can't display a balloon here anyway.
538 // Also, we only want to display the first run balloon once, so the pref will
539 // store the flag on disk based on whether we ever showed the balloon.
540 if (!tray_.get() || first_run_pref_.GetValue())
Andrew T Wilson (Slow) 2013/06/19 06:28:57 What's the case where tray_ is null? Can we ever *
dewittj 2013/06/20 02:20:54 There is no case where tray_ is null. I was just
541 return;
542
543 // If there are popups, the message center is visible, or there are no more
544 // notifications, don't continue the timer since it will be annoying or
545 // useless.
546 if (message_center_->HasPopupNotifications() ||
547 message_center_->IsMessageCenterVisible() ||
548 0 == message_center_->NotificationCount()) {
549 first_run_balloon_timer_.Stop();
550 return;
551 }
552
553 // No need to restart the timer if it's already going.
554 if (first_run_balloon_timer_.IsRunning())
555 return;
556
557 first_run_balloon_timer_.Start(
558 FROM_HERE,
559 base::TimeDelta::FromSeconds(kIdleDelaySeconds),
560 base::Bind(&MessageCenterNotificationManager::DisplayFirstRunBalloon,
561 AsWeakPtr()));
562 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698