Chromium Code Reviews| Index: chrome/browser/notifications/notification_ui_manager.cc |
| =================================================================== |
| --- chrome/browser/notifications/notification_ui_manager.cc (revision 72012) |
| +++ chrome/browser/notifications/notification_ui_manager.cc (working copy) |
| @@ -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 @@ |
| }; |
| 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) |
| + InitMacFullScreenMonitor(); |
| +#endif |
| } |
| NotificationUIManager::~NotificationUIManager() { |
| STLDeleteElements(&show_queue_); |
| +#if defined(OS_MACOSX) |
| + StopMacFullScreenMonitor(); |
| +#endif |
| } |
| // static |
| @@ -126,10 +139,28 @@ |
| } |
| 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(); |
|
evanm
2011/01/21 00:42:05
IsFullScreenMode, at least in the Linux implementa
jianli
2011/01/21 01:15:50
Yes, it is on UI thread. The Win32/MacOSX implemen
|
| + if (is_user_active_ == is_user_active_previously) |
| + return; |
| + |
| + if (is_user_active_) { |
| + user_state_check_timer_.Stop(); |
| + ShowNotifications(); |
|
John Gregg
2011/01/21 07:14:51
This doesn't look right at first glance because C
jianli
2011/01/21 20:21:00
Done.
|
| + } else if (!user_state_check_timer_.IsRunning()) { |
| + user_state_check_timer_.Start( |
| + base::TimeDelta::FromSeconds(kUserStatePollingIntervalSeconds), this, |
| + &NotificationUIManager::CheckUserState); |
| + } |
| +} |
| + |
| void NotificationUIManager::ShowNotifications() { |
| while (!show_queue_.empty() && balloon_collection_->HasSpace()) { |
| scoped_ptr<QueuedNotification> queued_notification(show_queue_.front()); |