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

Unified Diff: chrome/browser/notifications/notification_ui_manager.cc

Issue 6359008: Do not show notifications when in fullscreen or screensaver mode.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « chrome/browser/notifications/notification_ui_manager.h ('k') | chrome/browser/ui/gtk/gtk_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/notification_ui_manager.cc
===================================================================
--- chrome/browser/notifications/notification_ui_manager.cc (revision 72519)
+++ 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)
+ InitFullScreenMonitor();
+#endif
}
NotificationUIManager::~NotificationUIManager() {
STLDeleteElements(&show_queue_);
+#if defined(OS_MACOSX)
+ StopFullScreenMonitor();
+#endif
}
// static
@@ -126,10 +139,31 @@
}
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() {
while (!show_queue_.empty() && balloon_collection_->HasSpace()) {
scoped_ptr<QueuedNotification> queued_notification(show_queue_.front());
« no previous file with comments | « chrome/browser/notifications/notification_ui_manager.h ('k') | chrome/browser/ui/gtk/gtk_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698