diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-25 20:54:06 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-25 20:54:06 +0000 |
commit | 3c64537927e5a31388c8fac8e04e575a12f6ff81 (patch) | |
tree | adc23145813263daad9d696f2ffb3648dafa8bd5 /chrome/browser/notifications | |
parent | 34ce848a57340642bb708d44bf1e6fa4ea3a07b5 (diff) | |
download | chromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.zip chromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.tar.gz chromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.tar.bz2 |
Do not show notifications when in fullscreen or screensaver mode.
I add full-screen/presentation mode detection for all 3 platforms. I also
add screensaver detection for MacOSX and Linux since it is missing in these
2 platforms.
BUG=25061
TEST=Manual test
Review URL: http://codereview.chromium.org/6359008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72539 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
-rw-r--r-- | chrome/browser/notifications/notification_ui_manager.cc | 40 | ||||
-rw-r--r-- | chrome/browser/notifications/notification_ui_manager.h | 8 |
2 files changed, 45 insertions, 3 deletions
diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc index 950bd6c..51a2c66 100644 --- a/chrome/browser/notifications/notification_ui_manager.cc +++ b/chrome/browser/notifications/notification_ui_manager.cc @@ -8,6 +8,8 @@ #include "base/scoped_ptr.h" #include "base/stl_util-inl.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/fullscreen.h" +#include "chrome/browser/idle.h" #include "chrome/browser/notifications/balloon_collection.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/prefs/pref_service.h" @@ -16,6 +18,10 @@ #include "chrome/common/notification_type.h" #include "chrome/common/pref_names.h" +namespace { +const int kUserStatePollingIntervalSeconds = 1; +} + // A class which represents a notification waiting to be shown. class QueuedNotification { public: @@ -42,14 +48,21 @@ class QueuedNotification { }; NotificationUIManager::NotificationUIManager(PrefService* local_state) - : balloon_collection_(NULL) { + : balloon_collection_(NULL), + is_user_active_(true) { registrar_.Add(this, NotificationType::APP_TERMINATING, NotificationService::AllSources()); position_pref_.Init(prefs::kDesktopNotificationPosition, local_state, this); +#if defined(OS_MACOSX) + InitFullScreenMonitor(); +#endif } NotificationUIManager::~NotificationUIManager() { STLDeleteElements(&show_queue_); +#if defined(OS_MACOSX) + StopFullScreenMonitor(); +#endif } // static @@ -126,8 +139,29 @@ void NotificationUIManager::CancelAll() { } void NotificationUIManager::CheckAndShowNotifications() { - // TODO(johnnyg): http://crbug.com/25061 - Check for user idle/presentation. - ShowNotifications(); + CheckUserState(); + if (is_user_active_) + ShowNotifications(); +} + +void NotificationUIManager::CheckUserState() { + bool is_user_active_previously = is_user_active_; + is_user_active_ = CalculateIdleState(0) != IDLE_STATE_LOCKED && + !IsFullScreenMode(); + if (is_user_active_ == is_user_active_previously) + return; + + if (is_user_active_) { + user_state_check_timer_.Stop(); + // We need to show any postponed nofications when the user becomes active + // again. + ShowNotifications(); + } else if (!user_state_check_timer_.IsRunning()) { + // Start a timer to detect the moment at which the user becomes active. + user_state_check_timer_.Start( + base::TimeDelta::FromSeconds(kUserStatePollingIntervalSeconds), this, + &NotificationUIManager::CheckUserState); + } } void NotificationUIManager::ShowNotifications() { diff --git a/chrome/browser/notifications/notification_ui_manager.h b/chrome/browser/notifications/notification_ui_manager.h index 1b9475d..7ac63a2 100644 --- a/chrome/browser/notifications/notification_ui_manager.h +++ b/chrome/browser/notifications/notification_ui_manager.h @@ -11,6 +11,7 @@ #include "base/id_map.h" #include "base/scoped_ptr.h" +#include "base/timer.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/balloon_collection.h" #include "chrome/browser/prefs/pref_member.h" @@ -93,6 +94,9 @@ class NotificationUIManager // returns true if the replacement happened. bool TryReplacement(const Notification& notification); + // Checks the user state to decide if we want to show the notification. + void CheckUserState(); + // An owned pointer to the collection of active balloons. scoped_ptr<BalloonCollection> balloon_collection_; @@ -106,6 +110,10 @@ class NotificationUIManager // Prefs listener for the position preference. IntegerPrefMember position_pref_; + // Used by screen-saver and full-screen handling support. + bool is_user_active_; + base::RepeatingTimer<NotificationUIManager> user_state_check_timer_; + DISALLOW_COPY_AND_ASSIGN(NotificationUIManager); }; |