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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/message_center_notification_manager.cc
diff --git a/chrome/browser/notifications/message_center_notification_manager.cc b/chrome/browser/notifications/message_center_notification_manager.cc
index be8bd2ef88fdbbe7e8d4b65da0070182eb80981d..945fefcb6c24c88835a550381524d1fef1d5aee4 100644
--- a/chrome/browser/notifications/message_center_notification_manager.cc
+++ b/chrome/browser/notifications/message_center_notification_manager.cc
@@ -25,10 +25,18 @@
#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/notifier_settings.h"
+namespace {
+
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.
+const int kIdleDelaySeconds = 1;
+}
+
MessageCenterNotificationManager::MessageCenterNotificationManager(
- message_center::MessageCenter* message_center)
+ message_center::MessageCenter* message_center,
+ PrefService* local_state)
: message_center_(message_center),
settings_controller_(new MessageCenterSettingsController) {
+ first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state);
+
message_center_->SetDelegate(this);
message_center_->AddObserver(this);
@@ -44,6 +52,20 @@ MessageCenterNotificationManager::~MessageCenterNotificationManager() {
message_center_->RemoveObserver(this);
}
+void MessageCenterNotificationManager::DisplayFirstRunBalloon() {
+#if !defined(OS_WIN)
+ // The first run balloon is only displayed on Windows, since the visibility of
+ // the tray icon is limited.
+ 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.
+#endif
+
+ if (!tray_)
+ return;
+
+ // Store for posterity the fact that we've shown the first-run balloon.
+ first_run_pref_.SetValue(true);
+ tray_->DisplayFirstRunBalloon();
+}
////////////////////////////////////////////////////////////////////////////////
// NotificationUIManager
@@ -274,12 +296,20 @@ void MessageCenterNotificationManager::OnNotificationRemoved(
profile_notifications_.find(notification_id);
if (iter != profile_notifications_.end())
RemoveProfileNotification(iter->second, by_user);
+
+ CheckFirstRunTimer();
}
void MessageCenterNotificationManager::OnNotificationCenterClosed() {
// When the center is open it halts all notifications, so we need to listen
// for events indicating it's been closed.
CheckAndShowNotifications();
+ CheckFirstRunTimer();
+}
+
+void MessageCenterNotificationManager::OnNotificationUpdated(
+ const std::string& notification_id) {
+ CheckFirstRunTimer();
}
////////////////////////////////////////////////////////////////////////////////
@@ -496,3 +526,37 @@ MessageCenterNotificationManager::ProfileNotification*
return (*iter).second;
}
+
+void MessageCenterNotificationManager::CheckFirstRunTimer() {
+#if !defined(OS_WIN)
+ // The first run balloon is only used on Windows, since it is the platform
+ // that has the most issues with tray icon visibility.
+ return;
+#endif
+
+ // If there is no tray_, we can't display a balloon here anyway.
+ // Also, we only want to display the first run balloon once, so the pref will
+ // store the flag on disk based on whether we ever showed the balloon.
+ 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
+ return;
+
+ // If there are popups, the message center is visible, or there are no more
+ // notifications, don't continue the timer since it will be annoying or
+ // useless.
+ if (message_center_->HasPopupNotifications() ||
+ message_center_->IsMessageCenterVisible() ||
+ 0 == message_center_->NotificationCount()) {
+ first_run_balloon_timer_.Stop();
+ return;
+ }
+
+ // No need to restart the timer if it's already going.
+ if (first_run_balloon_timer_.IsRunning())
+ return;
+
+ first_run_balloon_timer_.Start(
+ FROM_HERE,
+ base::TimeDelta::FromSeconds(kIdleDelaySeconds),
+ base::Bind(&MessageCenterNotificationManager::DisplayFirstRunBalloon,
+ AsWeakPtr()));
+}

Powered by Google App Engine
This is Rietveld 408576698