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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/notification_ui_manager.h" 5 #include "chrome/browser/notifications/notification_ui_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/fullscreen.h"
12 #include "chrome/browser/idle.h"
11 #include "chrome/browser/notifications/balloon_collection.h" 13 #include "chrome/browser/notifications/balloon_collection.h"
12 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/renderer_host/site_instance.h" 16 #include "chrome/browser/renderer_host/site_instance.h"
15 #include "chrome/common/notification_service.h" 17 #include "chrome/common/notification_service.h"
16 #include "chrome/common/notification_type.h" 18 #include "chrome/common/notification_type.h"
17 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
18 20
21 namespace {
22 const int kUserStatePollingIntervalSeconds = 1;
23 }
24
19 // A class which represents a notification waiting to be shown. 25 // A class which represents a notification waiting to be shown.
20 class QueuedNotification { 26 class QueuedNotification {
21 public: 27 public:
22 QueuedNotification(const Notification& notification, Profile* profile) 28 QueuedNotification(const Notification& notification, Profile* profile)
23 : notification_(notification), 29 : notification_(notification),
24 profile_(profile) { 30 profile_(profile) {
25 } 31 }
26 32
27 const Notification& notification() const { return notification_; } 33 const Notification& notification() const { return notification_; }
28 Profile* profile() const { return profile_; } 34 Profile* profile() const { return profile_; }
29 35
30 void Replace(const Notification& new_notification) { 36 void Replace(const Notification& new_notification) {
31 notification_ = new_notification; 37 notification_ = new_notification;
32 } 38 }
33 39
34 private: 40 private:
35 // The notification to be shown. 41 // The notification to be shown.
36 Notification notification_; 42 Notification notification_;
37 43
38 // Non owned pointer to the user's profile. 44 // Non owned pointer to the user's profile.
39 Profile* profile_; 45 Profile* profile_;
40 46
41 DISALLOW_COPY_AND_ASSIGN(QueuedNotification); 47 DISALLOW_COPY_AND_ASSIGN(QueuedNotification);
42 }; 48 };
43 49
44 NotificationUIManager::NotificationUIManager(PrefService* local_state) 50 NotificationUIManager::NotificationUIManager(PrefService* local_state)
45 : balloon_collection_(NULL) { 51 : balloon_collection_(NULL),
52 is_user_active_(true) {
46 registrar_.Add(this, NotificationType::APP_TERMINATING, 53 registrar_.Add(this, NotificationType::APP_TERMINATING,
47 NotificationService::AllSources()); 54 NotificationService::AllSources());
48 position_pref_.Init(prefs::kDesktopNotificationPosition, local_state, this); 55 position_pref_.Init(prefs::kDesktopNotificationPosition, local_state, this);
56 #if defined(OS_MACOSX)
57 InitMacFullScreenMonitor();
58 #endif
49 } 59 }
50 60
51 NotificationUIManager::~NotificationUIManager() { 61 NotificationUIManager::~NotificationUIManager() {
52 STLDeleteElements(&show_queue_); 62 STLDeleteElements(&show_queue_);
63 #if defined(OS_MACOSX)
64 StopMacFullScreenMonitor();
65 #endif
53 } 66 }
54 67
55 // static 68 // static
56 NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) { 69 NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) {
57 BalloonCollection* balloons = BalloonCollection::Create(); 70 BalloonCollection* balloons = BalloonCollection::Create();
58 NotificationUIManager* instance = new NotificationUIManager(local_state); 71 NotificationUIManager* instance = new NotificationUIManager(local_state);
59 instance->Initialize(balloons); 72 instance->Initialize(balloons);
60 balloons->set_space_change_listener(instance); 73 balloons->set_space_change_listener(instance);
61 return instance; 74 return instance;
62 } 75 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 132
120 return balloon_collection_->RemoveBySourceOrigin(source) || removed; 133 return balloon_collection_->RemoveBySourceOrigin(source) || removed;
121 } 134 }
122 135
123 void NotificationUIManager::CancelAll() { 136 void NotificationUIManager::CancelAll() {
124 STLDeleteElements(&show_queue_); 137 STLDeleteElements(&show_queue_);
125 balloon_collection_->RemoveAll(); 138 balloon_collection_->RemoveAll();
126 } 139 }
127 140
128 void NotificationUIManager::CheckAndShowNotifications() { 141 void NotificationUIManager::CheckAndShowNotifications() {
129 // TODO(johnnyg): http://crbug.com/25061 - Check for user idle/presentation. 142 CheckUserState();
130 ShowNotifications(); 143 if (is_user_active_)
144 ShowNotifications();
145 }
146
147 void NotificationUIManager::CheckUserState() {
148 bool is_user_active_previously = is_user_active_;
149 is_user_active_ = CalculateIdleState(0) != IDLE_STATE_LOCKED &&
150 !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
151 if (is_user_active_ == is_user_active_previously)
152 return;
153
154 if (is_user_active_) {
155 user_state_check_timer_.Stop();
156 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.
157 } else if (!user_state_check_timer_.IsRunning()) {
158 user_state_check_timer_.Start(
159 base::TimeDelta::FromSeconds(kUserStatePollingIntervalSeconds), this,
160 &NotificationUIManager::CheckUserState);
161 }
131 } 162 }
132 163
133 void NotificationUIManager::ShowNotifications() { 164 void NotificationUIManager::ShowNotifications() {
134 while (!show_queue_.empty() && balloon_collection_->HasSpace()) { 165 while (!show_queue_.empty() && balloon_collection_->HasSpace()) {
135 scoped_ptr<QueuedNotification> queued_notification(show_queue_.front()); 166 scoped_ptr<QueuedNotification> queued_notification(show_queue_.front());
136 show_queue_.pop_front(); 167 show_queue_.pop_front();
137 balloon_collection_->Add(queued_notification->notification(), 168 balloon_collection_->Add(queued_notification->notification(),
138 queued_notification->profile()); 169 queued_notification->profile());
139 } 170 }
140 } 171 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } else if (type == NotificationType::PREF_CHANGED) { 231 } else if (type == NotificationType::PREF_CHANGED) {
201 std::string* name = Details<std::string>(details).ptr(); 232 std::string* name = Details<std::string>(details).ptr();
202 if (*name == prefs::kDesktopNotificationPosition) 233 if (*name == prefs::kDesktopNotificationPosition)
203 balloon_collection_->SetPositionPreference( 234 balloon_collection_->SetPositionPreference(
204 static_cast<BalloonCollection::PositionPreference>( 235 static_cast<BalloonCollection::PositionPreference>(
205 position_pref_.GetValue())); 236 position_pref_.GetValue()));
206 } else { 237 } else {
207 NOTREACHED(); 238 NOTREACHED();
208 } 239 }
209 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698